mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 13:18:18 +00:00
Show thoughts and text response in thoughts on anthropic tool use
Previously if anthropic models were using tools, the models text response accompanying the tool use wouldn't be shown as they were overwritten in aggregated response with the tool call json. This changes appends the text response to the thoughts portion on tool use to still show model's thinking. Thinking and text response are delineated by italics vs normal text for such cases.
This commit is contained in:
@@ -35,7 +35,7 @@ def anthropic_send_message_to_model(
|
||||
"""
|
||||
Send message to model
|
||||
"""
|
||||
# Get Response from GPT. Don't use response_type because Anthropic doesn't support it.
|
||||
# Get response from model. Don't use response_type because Anthropic doesn't support it.
|
||||
return anthropic_completion_with_backoff(
|
||||
messages=messages,
|
||||
system_prompt="",
|
||||
|
||||
@@ -129,6 +129,14 @@ def anthropic_completion_with_backoff(
|
||||
if item.type == "tool_use"
|
||||
]
|
||||
if tool_calls:
|
||||
# If there are tool calls, aggregate thoughts and responses into thoughts
|
||||
if thoughts and aggregated_response:
|
||||
# wrap each line of thought in italics
|
||||
thoughts = "\n".join([f"*{line.strip()}*" for line in thoughts.splitlines() if line.strip()])
|
||||
thoughts = f"{thoughts}\n\n{aggregated_response}"
|
||||
else:
|
||||
thoughts = thoughts or aggregated_response
|
||||
# Json dump tool calls into aggregated response
|
||||
aggregated_response = json.dumps(tool_calls)
|
||||
# If response schema is used, return the first tool call's input
|
||||
elif response_schema:
|
||||
|
||||
Reference in New Issue
Block a user