fix: fix client code
This commit is contained in:
parent
8873262d7a
commit
8acb5f97a2
1 changed files with 29 additions and 22 deletions
|
|
@ -165,9 +165,11 @@ async def process_query(self, query: str) -> str:
|
||||||
tool_results = []
|
tool_results = []
|
||||||
final_text = []
|
final_text = []
|
||||||
|
|
||||||
|
assistant_message_content = []
|
||||||
for content in response.content:
|
for content in response.content:
|
||||||
if content.type == 'text':
|
if content.type == 'text':
|
||||||
final_text.append(content.text)
|
final_text.append(content.text)
|
||||||
|
assistant_message_content.append(content)
|
||||||
elif content.type == 'tool_use':
|
elif content.type == 'tool_use':
|
||||||
tool_name = content.name
|
tool_name = content.name
|
||||||
tool_args = content.input
|
tool_args = content.input
|
||||||
|
|
@ -177,15 +179,20 @@ async def process_query(self, query: str) -> str:
|
||||||
tool_results.append({"call": tool_name, "result": result})
|
tool_results.append({"call": tool_name, "result": result})
|
||||||
final_text.append(f"[Calling tool {tool_name} with args {tool_args}]")
|
final_text.append(f"[Calling tool {tool_name} with args {tool_args}]")
|
||||||
|
|
||||||
# Continue conversation with tool results
|
assistant_message_content.append(content)
|
||||||
if hasattr(content, 'text') and content.text:
|
messages.append({
|
||||||
messages.append({
|
"role": "assistant",
|
||||||
"role": "assistant",
|
"content": assistant_message_content
|
||||||
"content": content.text
|
})
|
||||||
})
|
|
||||||
messages.append({
|
messages.append({
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"content": result.content
|
"content": [
|
||||||
|
{
|
||||||
|
"type": "tool_result",
|
||||||
|
"tool_use_id": content.id,
|
||||||
|
"content": result.content
|
||||||
|
}
|
||||||
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
# Get next response from Claude
|
# Get next response from Claude
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue