zhudotexe / kani

kani (カニ) is a highly hackable microframework for chat-based language models with tool use/function calling. (NLP-OSS @ EMNLP 2023)
https://kani.readthedocs.io
MIT License
557 stars 30 forks source link

Allow multiple tool calls per ChatMessage #28

Closed arturoleon closed 11 months ago

arturoleon commented 11 months ago

This PR addresses a bug where a ChatMessage containing multiple ToolCall objects would result in a validation error due to Pydantic's tuple length constraint[0]. The tool_calls field's type annotation was updated to allow a variable-length tuple.

Before:

➜ python3 start.py
USER: get me the SEA weather in F and C
Traceback (most recent call last):
 [truncated]
pydantic_core._pydantic_core.ValidationError: 1 validation error for ChatMessage
tool_calls
  Tuple should have at most 1 item after validation, not 2 [type=too_long, input_value=[ToolCall(id='call_iQLAkv...unit": "fahrenheit"}'))], input_type=list]
    For further information visit https://errors.pydantic.dev/2.5/v/too_long

After:

➜ python3 start.py
USER: get me the SEA weather in F and C
AI: Thinking (get_weather)...
AI: The current weather in Seattle, WA is sunny. It is 72 degrees Fahrenheit and 22 degrees Celsius.

[0] Tuple should have at most 1 item after validation, not 2 [type=too_long, input_value=[ToolCall(id='call_iQLAkv...unit": "fahrenheit"}'))], input_type=list]