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