This commit is contained in:
Lucca Zenobio 2024-03-20 15:22:23 -03:00
parent cace0bd6fb
commit 872ff6176d
2 changed files with 7 additions and 4 deletions

View file

@ -604,13 +604,13 @@ def convert_to_anthropic_tool_result(message: dict) -> str:
def convert_to_anthropic_tool_invoke(tool_calls: list) -> str:
invokes = ""
for tool in tool_calls:
if tool["type"] != "function":
if tool.type != "function":
continue
tool_name = tool["function"]["name"]
tool_name = tool.function.name
parameters = "".join(
f"<{param}>{val}</{param}>\n"
for param, val in json.loads(tool["function"]["arguments"]).items()
for param, val in json.loads(tool.function.arguments).items()
)
invokes += (
"<invoke>\n"

View file

@ -271,7 +271,10 @@ class Message(OpenAIObject):
if tool_calls is not None:
self.tool_calls = []
for tool_call in tool_calls:
self.tool_calls.append(ChatCompletionMessageToolCall(**tool_call))
if isinstance(tool_call, dict):
self.tool_calls.append(ChatCompletionMessageToolCall(**tool_call))
else:
self.tool_calls.append(tool_call)
if logprobs is not None:
self._logprobs = logprobs