Skip to content

Commit

Permalink
Update anthropic tools stream format
Browse files Browse the repository at this point in the history
  • Loading branch information
kxtran committed May 21, 2024
1 parent 1d85176 commit 3c93afc
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions log10/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,17 @@ def __next__(self):
self.model = chunk.message.model
self.message_id = chunk.message.id
self.input_tokens = chunk.message.usage.input_tokens
if chunk.type == "content_block_start" and hasattr(chunk.content_block, "text"):
self.final_result += chunk.content_block.text
elif chunk.type == "message_delta":
self.finish_reason = chunk.delta.stop_reason
self.output_tokens = chunk.usage.output_tokens
elif chunk.type == "content_block_delta":
self.final_result += chunk.delta.text
elif chunk.type == "message_stop":
if hasattr(chunk.delta, "text"):
self.final_result += chunk.delta.text
if hasattr(chunk.delta, "partial_json"):
self.final_result += chunk.delta.partial_json
elif chunk.type == "message_stop" or chunk.type == "content_block_stop":
response = {
"id": self.message_id,
"object": "chat",
Expand Down Expand Up @@ -513,6 +518,16 @@ def _init_log_row(func, *args, **kwargs):
else:
new_content.append(c)
m["content"] = new_content
if "tools" in kwargs_copy:
for t in kwargs_copy["tools"]:
new_function = {
"name": t["name"],
"description": t["description"],
"parameters": {
"properties": t["input_schema"]["properties"],
},
}
t["function"] = new_function
elif "vertexai" in func.__module__:
if func.__name__ == "_send_message":
# get model name save in ChatSession instance
Expand Down

0 comments on commit 3c93afc

Please sign in to comment.