Skip to content

Commit

Permalink
chore: PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
zhudotexe committed Nov 8, 2023
1 parent 6a27a3a commit 6afe648
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions docs/function_calling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------------
Expand Down Expand Up @@ -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.

Expand Down
3 changes: 1 addition & 2 deletions examples/2_function_calling_fewshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions kani/kani.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions kani/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`."
)
Expand Down
3 changes: 1 addition & 2 deletions tests/test_chatmessage.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down

0 comments on commit 6afe648

Please sign in to comment.