Skip to content

Commit a3a9563

Browse files
committed
fix process_qwen_messages spell error and unused f_args
1 parent 5e93085 commit a3a9563

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

api/generation/qwen.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def process_qwen_messages(
206206
messages = []
207207
for m_idx, m in enumerate(_messages):
208208
role, content = m["role"], m["content"]
209-
func_call, tools_call = m.get("function_call", None), m.get("tools_call", None)
209+
func_call, tool_calls = m.get("function_call", None), m.get("tool_calls", None)
210210
if content:
211211
content = content.lstrip("\n").rstrip()
212212
if role in [Role.FUNCTION, Role.TOOL]:
@@ -227,20 +227,22 @@ def process_qwen_messages(
227227
last_msg = messages[-1]["content"]
228228
last_msg_has_zh = len(re.findall(r"[\u4e00-\u9fff]+", last_msg)) > 0
229229

230-
if func_call is None and tools_call is None:
231-
if functions or tools_call:
230+
if func_call is None and tool_calls is None:
231+
if functions or tool_calls:
232232
content = dummy_thought["zh" if last_msg_has_zh else "en"] + content
233233
else:
234234
if func_call:
235235
f_name, f_args = func_call.get("name"), func_call.get("arguments")
236236
else:
237-
f_name, f_args = tools_call[0]["function"]["name"], tools_call[0]["function"]["arguments"]
237+
f_name, f_args = tool_calls[0]["function"]["name"], tool_calls[0]["function"]["arguments"]
238238
if not content:
239239
if last_msg_has_zh:
240240
content = f"Thought: 我可以使用 {f_name} API。"
241241
else:
242242
content = f"Thought: I can use {f_name}."
243-
243+
244+
if func_call:
245+
content = f"\n{content}\nAction: {f_name}\nAction Input: {f_args}"
244246
if messages[-1]["role"] == Role.USER:
245247
messages.append(
246248
ChatCompletionAssistantMessageParam(role="assistant", content=content.lstrip("\n").rstrip())

0 commit comments

Comments
 (0)