From 6afe6483f513d2349b4730854cb633b93b00e8a3 Mon Sep 17 00:00:00 2001 From: Andrew Zhu Date: Wed, 8 Nov 2023 12:48:12 -0500 Subject: [PATCH] chore: PR comments --- docs/function_calling.rst | 4 ++-- examples/2_function_calling_fewshot.py | 3 +-- kani/kani.py | 4 ++-- kani/models.py | 4 ++-- tests/test_chatmessage.py | 3 +-- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/docs/function_calling.rst b/docs/function_calling.rst index 6cc1239..94404f3 100644 --- a/docs/function_calling.rst +++ b/docs/function_calling.rst @@ -139,7 +139,7 @@ control should be given to the human (i.e. return from the chat round), set ``af .. note:: If the model calls multiple tools in parallel, the model will be allowed to generate a response if *any* function - allows it. + has ``after=ChatRole.ASSISTANT`` (the default) once all function calls are complete. Complete Example ---------------- @@ -299,7 +299,7 @@ call. .. note:: If the model calls multiple tools in parallel, the model will be allowed a retry if *any* exception handler - allows it. + allows it. This will only count as 1 retry attempt regardless of the number of functions that raised an exception. In the next section, we'll discuss how to customize this behaviour, along with other parts of the kani interface. diff --git a/examples/2_function_calling_fewshot.py b/examples/2_function_calling_fewshot.py index 672464a..981b00f 100644 --- a/examples/2_function_calling_fewshot.py +++ b/examples/2_function_calling_fewshot.py @@ -2,9 +2,8 @@ import os from typing import Annotated -from kani import AIParam, ChatMessage, Kani, ai_function, chat_in_terminal +from kani import AIParam, ChatMessage, Kani, ToolCall, ai_function, chat_in_terminal from kani.engines.openai import OpenAIEngine -from kani.models import ToolCall api_key = os.getenv("OPENAI_API_KEY") engine = OpenAIEngine(api_key, model="gpt-3.5-turbo") diff --git a/kani/kani.py b/kani/kani.py index 4899194..b6fe03a 100644 --- a/kani/kani.py +++ b/kani/kani.py @@ -80,7 +80,7 @@ def __init__( Use ``chat_history=mykani.chat_history.copy()`` to pass a copy. :param functions: A list of :class:`.AIFunction` to expose to the model (for dynamic function calling). Use :func:`.ai_function` to define static functions (see :doc:`function_calling`). - :param retry_attempts: How many attempts the LM may take if a function call raises an exception. + :param retry_attempts: How many attempts the LM may take per full round if any tool call raises an exception. """ self.engine = engine self.system_prompt = system_prompt.strip() if system_prompt else None @@ -211,7 +211,7 @@ async def _do_tool_call(tc: ToolCall): retry += 1 if not should_retry_call: # disable function calling on the next go - kwargs = {**kwargs, "include_functions": False} + kwargs["include_functions"] = False else: retry = 0 diff --git a/kani/models.py b/kani/models.py index 170c6d9..75e6b99 100644 --- a/kani/models.py +++ b/kani/models.py @@ -9,7 +9,7 @@ from pydantic import BaseModel as PydanticBase, ConfigDict, model_serializer, model_validator -from .exceptions import MissingMessagePartType, ToolCallError +from .exceptions import MissingMessagePartType # ==== constants ==== MESSAGEPART_TYPE_KEY = "__kani_messagepart_type__" # used for serdes of MessageParts @@ -247,7 +247,7 @@ def function_call(self) -> FunctionCall | None: if not self.tool_calls: return None if len(self.tool_calls) > 1: - raise ToolCallError( + warnings.warn( "This message contains multiple tool calls; iterate over `.tool_calls` instead of using" " `.function_call`." ) diff --git a/tests/test_chatmessage.py b/tests/test_chatmessage.py index 0f79223..01650db 100644 --- a/tests/test_chatmessage.py +++ b/tests/test_chatmessage.py @@ -1,8 +1,7 @@ import pydantic import pytest -from kani import ChatMessage, ChatRole, MessagePart -from kani.models import ToolCall +from kani import ChatMessage, ChatRole, MessagePart, ToolCall class TestMessagePart(MessagePart):