mirror of
https://github.com/TheSmallHanCat/sora2api.git
synced 2026-02-24 02:04:41 +08:00
Merge pull request #52 from sxhxliang/main
修复UnboundLocalError: cannot access local variable 'json' where it is …
This commit is contained in:
@@ -151,7 +151,6 @@ async def create_chat_completion(
|
|||||||
result = chunk
|
result = chunk
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
import json
|
|
||||||
return JSONResponse(content=json.loads(result))
|
return JSONResponse(content=json.loads(result))
|
||||||
else:
|
else:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
@@ -169,7 +168,6 @@ async def create_chat_completion(
|
|||||||
# Handle streaming
|
# Handle streaming
|
||||||
if request.stream:
|
if request.stream:
|
||||||
async def generate():
|
async def generate():
|
||||||
import json as json_module # Import inside function to avoid scope issues
|
|
||||||
try:
|
try:
|
||||||
async for chunk in generation_handler.handle_generation(
|
async for chunk in generation_handler.handle_generation(
|
||||||
model=request.model,
|
model=request.model,
|
||||||
@@ -184,7 +182,7 @@ async def create_chat_completion(
|
|||||||
# Try to parse structured error (JSON format)
|
# Try to parse structured error (JSON format)
|
||||||
error_data = None
|
error_data = None
|
||||||
try:
|
try:
|
||||||
error_data = json_module.loads(str(e))
|
error_data = json.loads(str(e))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -202,7 +200,7 @@ async def create_chat_completion(
|
|||||||
"code": None
|
"code": None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
error_chunk = f'data: {json_module.dumps(error_response)}\n\n'
|
error_chunk = f'data: {json.dumps(error_response)}\n\n'
|
||||||
yield error_chunk
|
yield error_chunk
|
||||||
yield 'data: [DONE]\n\n'
|
yield 'data: [DONE]\n\n'
|
||||||
|
|
||||||
@@ -229,7 +227,6 @@ async def create_chat_completion(
|
|||||||
result = chunk
|
result = chunk
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
import json
|
|
||||||
return JSONResponse(content=json.loads(result))
|
return JSONResponse(content=json.loads(result))
|
||||||
else:
|
else:
|
||||||
# Return OpenAI-compatible error format
|
# Return OpenAI-compatible error format
|
||||||
|
|||||||
@@ -600,7 +600,6 @@ class GenerationHandler:
|
|||||||
# Parse error message to check if it's a structured error (JSON)
|
# Parse error message to check if it's a structured error (JSON)
|
||||||
error_response = None
|
error_response = None
|
||||||
try:
|
try:
|
||||||
import json
|
|
||||||
error_response = json.loads(str(e))
|
error_response = json.loads(str(e))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user