doc:修复第七章 tiny-agent

This commit is contained in:
KMnO4-zx
2025-05-14 21:26:54 +08:00
parent ba29bde6b1
commit c9d22772a1
3 changed files with 22 additions and 24 deletions

View File

@@ -51,14 +51,15 @@ class Agent:
stream=False,
)
if response.choices[0].message.tool_calls:
self.messages.append({"role": "assistant", "content": response.choices[0].message.content})
# 处理工具调用
tool_list = []
for tool_call in response.choices[0].message.tool_calls:
# 处理工具调用并将结果添加到消息列表中
self.messages.append(self.handle_tool_call(tool_call))
tool_list.append(tool_call.function.name)
tool_list.append([tool_call.function.name, tool_call.function.arguments])
if self.verbose:
print("调用工具:", tool_list)
print("调用工具:", response.choices[0].message.content, tool_list)
# 再次获取模型的完成响应,这次包含工具调用的结果
response = self.client.chat.completions.create(
model=self.model,