fix:找不到function卡住bug (#408)

Co-authored-by: hrz <1710360675@qq.com>
This commit is contained in:
欣南科技
2025-03-18 14:26:27 +08:00
committed by GitHub
co-authored by hrz
parent 878809ecb4
commit bd556c33a0
2 changed files with 35 additions and 26 deletions
+14 -5
View File
@@ -422,7 +422,8 @@ class ConnectionHandler:
else: else:
function_arguments = json.loads(function_arguments) function_arguments = json.loads(function_arguments)
if not bHasError: if not bHasError:
self.logger.bind(tag=TAG).info(f"function_name={function_name}, function_id={function_id}, function_arguments={function_arguments}") self.logger.bind(tag=TAG).info(
f"function_name={function_name}, function_id={function_id}, function_arguments={function_arguments}")
function_call_data = { function_call_data = {
"name": function_name, "name": function_name,
"id": function_id, "id": function_id,
@@ -467,17 +468,25 @@ class ConnectionHandler:
function_arguments = function_call_data["arguments"] function_arguments = function_call_data["arguments"]
self.dialogue.put(Message(role='assistant', self.dialogue.put(Message(role='assistant',
tool_calls=[{"id": function_id, tool_calls=[{"id": function_id,
"function": {"arguments": function_arguments,"name": function_name}, "function": {"arguments": function_arguments,
"name": function_name},
"type": 'function', "type": 'function',
"index": 0}])) "index": 0}]))
self.dialogue.put(Message(role="tool", tool_call_id=function_id, content=text)) self.dialogue.put(Message(role="tool", tool_call_id=function_id, content=text))
self.chat_with_function_calling(text, tool_call=True) self.chat_with_function_calling(text, tool_call=True)
elif result.action == Action.NOTFOUND: elif result.action == Action.NOTFOUND:
text = result.response text = result.result
self.recode_first_last_text(text, text_index)
future = self.executor.submit(self.speak_and_play, text, text_index)
self.tts_queue.put(future)
self.dialogue.put(Message(role="assistant", content=text))
else: else:
text = result.response text = result.result
self.recode_first_last_text(text, text_index)
future = self.executor.submit(self.speak_and_play, text, text_index)
self.tts_queue.put(future)
self.dialogue.put(Message(role="assistant", content=text))
def _tts_priority_thread(self): def _tts_priority_thread(self):
while not self.stop_event.is_set(): while not self.stop_event.is_set():
+4 -4
View File
@@ -197,12 +197,12 @@ def register_device_type(descriptor):
# 为每个属性创建查询函数 # 为每个属性创建查询函数
for prop_name, prop_info in descriptor["properties"].items(): for prop_name, prop_info in descriptor["properties"].items():
func_name = f"get_{{device_name.lower()}}_{{prop_name.lower()}}" func_name = f"get_{device_name.lower()}_{prop_name.lower()}"
func_desc = { func_desc = {
"type": "function", "type": "function",
"function": { "function": {
"name": func_name, "name": func_name,
"description": f"查询{{descriptor['description']}}{{prop_info['description']}}", "description": f"查询{descriptor['description']}{prop_info['description']}",
"parameters": { "parameters": {
"type": "object", "type": "object",
"properties": { "properties": {
@@ -212,7 +212,7 @@ def register_device_type(descriptor):
}, },
"response_failure": { "response_failure": {
"type": "string", "type": "string",
"description": f"查询失败时的友好回复,例如:'无法获取{{device_name}}{{prop_info['description']}}'" "description": f"查询失败时的友好回复,例如:'无法获取{device_name}{prop_info['description']}'"
} }
}, },
"required": ["response_success", "response_failure"] "required": ["response_success", "response_failure"]
@@ -256,7 +256,7 @@ def register_device_type(descriptor):
"type": "function", "type": "function",
"function": { "function": {
"name": func_name, "name": func_name,
"description": f"{{descriptor['description']}} - {{method_info['description']}}", "description": f"{descriptor['description']} - {method_info['description']}",
"parameters": { "parameters": {
"type": "object", "type": "object",
"properties": parameters, "properties": parameters,