Skip to content

Commit

Permalink
Pass no tool argument when none provided
Browse files Browse the repository at this point in the history
OpenAI's API requires that the tool list has at least one element
when it is present.

Also, pass the tools even when not streaming
  • Loading branch information
cvaske committed Feb 28, 2024
1 parent f063fd7 commit d6d6f51
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions chatlab/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ async def submit(self, *messages: Union[ChatCompletionMessageParam, str], stream
stream: Whether to stream chat into markdown or not. If False, the entire chat will be sent once.
"""

full_messages: List[ChatCompletionMessageParam] = []
full_messages.extend(self.messages)

Expand All @@ -285,14 +286,14 @@ async def submit(self, *messages: Union[ChatCompletionMessageParam, str], stream
"temperature": kwargs.get("temperature", 0),
}

if self.legacy_function_calling:
chat_create_kwargs.update(self.function_registry.api_manifest())
else:
chat_create_kwargs["tools"] = self.function_registry.tools or None

# Due to the strict response typing based on `Literal` typing on `stream`, we have to process these
# two cases separately
if stream:
if self.legacy_function_calling:
chat_create_kwargs.update(self.function_registry.api_manifest())
else:
chat_create_kwargs["tools"] = self.function_registry.tools

streaming_response = await client.chat.completions.create(
**chat_create_kwargs,
stream=True,
Expand Down

0 comments on commit d6d6f51

Please sign in to comment.