Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: differentiate prompts fields based on function_calling_type #5880

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: differentiate prompts fields based on function_calling_type
  • Loading branch information
qiqizjl committed Jul 2, 2024
commit 92cb61209fa5e4f8432807068468116084956913
Original file line number Diff line number Diff line change
Expand Up @@ -616,30 +616,34 @@ def _convert_prompt_message_to_dict(self, message: PromptMessage, credentials: O
message = cast(AssistantPromptMessage, message)
message_dict = {"role": "assistant", "content": message.content}
if message.tool_calls:
# message_dict["tool_calls"] = [helper.dump_model(PromptMessageFunction(function=tool_call)) for tool_call
# in
# message.tool_calls]

function_call = message.tool_calls[0]
message_dict["function_call"] = {
"name": function_call.function.name,
"arguments": function_call.function.arguments,
}
function_calling_type = credentials.get('function_calling_type', 'no_call')
if function_calling_type == 'tool_call':
message_dict["tool_calls"] = [tool_call.dict() for tool_call in
message.tool_calls]
elif function_calling_type == 'function_call':
function_call = message.tool_calls[0]
message_dict["function_call"] = {
"name": function_call.function.name,
"arguments": function_call.function.arguments,
}
elif isinstance(message, SystemPromptMessage):
message = cast(SystemPromptMessage, message)
message_dict = {"role": "system", "content": message.content}
elif isinstance(message, ToolPromptMessage):
message = cast(ToolPromptMessage, message)
# message_dict = {
# "role": "tool",
# "content": message.content,
# "tool_call_id": message.tool_call_id
# }
message_dict = {
"role": "tool" if credentials and credentials.get('function_calling_type', 'no_call') == 'tool_call' else "function",
"content": message.content,
"name": message.tool_call_id
}
function_calling_type = credentials.get('function_calling_type', 'no_call')
if function_calling_type == 'tool_call':
message_dict = {
"role": "tool",
"content": message.content,
"tool_call_id": message.tool_call_id
}
elif function_calling_type == 'function_call':
message_dict = {
"role": "function",
"content": message.content,
"name": message.tool_call_id
}
else:
raise ValueError(f"Got unknown type {message}")

Expand Down