This commit is contained in:
Awni Hannun 2025-03-04 13:38:48 -08:00
parent 925f5621b0
commit 86c665f7b4

View File

@ -47,11 +47,12 @@ response = generate(
)
# Parse the tool call:
tool_open = "<tool_call>\n"
tool_close = "\n</tool_call>"
# (Note, the tool call format is model specific)
tool_open = "<tool_call>"
tool_close = "</tool_call>"
start_tool = response.find(tool_open) + len(tool_open)
end_tool = response.find(tool_close)
tool_call = json.loads(response[start_tool:end_tool])
tool_call = json.loads(response[start_tool:end_tool].strip())
tool_result = tools[tool_call["name"]](**tool_call["arguments"])
# Put the tool result in the prompt