Skip to content

Commit

Permalink
Upgrade the request body field Function, use the Tool field for funct…
Browse files Browse the repository at this point in the history
…ion calls.
  • Loading branch information
yym68686 committed Aug 24, 2024
1 parent 0140d23 commit 809165c
Showing 1 changed file with 21 additions and 32 deletions.
53 changes: 21 additions & 32 deletions request.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ async def get_claude_payload(request, engine, provider):
messages = []
system_prompt = None
for msg in request.messages:
name = None
tool_calls = None
tool_call_id = None
if isinstance(msg.content, list):
content = []
for item in msg.content:
Expand All @@ -289,37 +290,25 @@ async def get_claude_payload(request, engine, provider):
content.append(image_message)
else:
content = msg.content
name = msg.name
arguments = msg.arguments
if arguments:
arguments = json.loads(arguments)
if name:
# messages.append({"role": "assistant", "name": name, "content": content})
messages.append(
{
"role": "assistant",
"content": [
{
"type": "tool_use",
"id": "toolu_01RofFmKHUKsEaZvqESG5Hwz",
"name": name,
"input": arguments,
}
]
}
)
messages.append(
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "toolu_01RofFmKHUKsEaZvqESG5Hwz",
"content": content
}
]
}
)
tool_calls = msg.tool_calls
tool_call_id = msg.tool_call_id

if tool_calls:
tool_calls_list = []
for tool_call in tool_calls:
tool_calls_list.append({
"type": "tool_use",
"id": tool_call.id,
"name": tool_call.function.name,
"input": json.loads(tool_call.function.arguments),
})
messages.append({"role": msg.role, "content": tool_calls_list})
elif tool_call_id:
messages.append({"role": "user", "content": [{
"type": "tool_result",
"tool_use_id": tool_call.id,
"content": content
}]})
elif msg.role != "system":
messages.append({"role": msg.role, "content": content})
elif msg.role == "system":
Expand Down

0 comments on commit 809165c

Please sign in to comment.