mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-26 09:03:54 +08:00
fix:local variable 'response' referenced before assignment
This commit is contained in:
@@ -37,17 +37,19 @@ class VisionHandler:
|
|||||||
|
|
||||||
async def handle_post(self, request):
|
async def handle_post(self, request):
|
||||||
"""处理 MCP Vision POST 请求"""
|
"""处理 MCP Vision POST 请求"""
|
||||||
|
response = None # 初始化response变量
|
||||||
try:
|
try:
|
||||||
# 验证token
|
# 验证token
|
||||||
is_valid, token_device_id = self._verify_auth_token(request)
|
is_valid, token_device_id = self._verify_auth_token(request)
|
||||||
if not is_valid:
|
if not is_valid:
|
||||||
return web.Response(
|
response = web.Response(
|
||||||
text=json.dumps(
|
text=json.dumps(
|
||||||
self._create_error_response("无效的认证token或token已过期")
|
self._create_error_response("无效的认证token或token已过期")
|
||||||
),
|
),
|
||||||
content_type="application/json",
|
content_type="application/json",
|
||||||
status=401,
|
status=401,
|
||||||
)
|
)
|
||||||
|
return response
|
||||||
|
|
||||||
# 获取请求头信息
|
# 获取请求头信息
|
||||||
device_id = request.headers.get("Device-Id", "")
|
device_id = request.headers.get("Device-Id", "")
|
||||||
@@ -120,11 +122,11 @@ class VisionHandler:
|
|||||||
vllm_type, current_config["VLLM"][select_vllm_module]
|
vllm_type, current_config["VLLM"][select_vllm_module]
|
||||||
)
|
)
|
||||||
|
|
||||||
response = vllm.response(question, image_base64)
|
result = vllm.response(question, image_base64)
|
||||||
|
|
||||||
return_json = {
|
return_json = {
|
||||||
"success": True,
|
"success": True,
|
||||||
"result": response,
|
"result": result,
|
||||||
}
|
}
|
||||||
|
|
||||||
response = web.Response(
|
response = web.Response(
|
||||||
@@ -146,7 +148,8 @@ class VisionHandler:
|
|||||||
content_type="application/json",
|
content_type="application/json",
|
||||||
)
|
)
|
||||||
finally:
|
finally:
|
||||||
self._add_cors_headers(response)
|
if response:
|
||||||
|
self._add_cors_headers(response)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
async def handle_get(self, request):
|
async def handle_get(self, request):
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ async def checkWakeupWords(conn, text):
|
|||||||
text_hello = WAKEUP_CONFIG["text"]
|
text_hello = WAKEUP_CONFIG["text"]
|
||||||
if not text_hello:
|
if not text_hello:
|
||||||
text_hello = text
|
text_hello = text
|
||||||
|
if conn.tts is None:
|
||||||
|
return False
|
||||||
conn.tts.tts_one_sentence(
|
conn.tts.tts_one_sentence(
|
||||||
conn, ContentType.FILE, content_file=file, content_detail=text_hello
|
conn, ContentType.FILE, content_file=file, content_detail=text_hello
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user