From d6d6f5185a8fdde05ac6fb9dee639c14f2433a8d Mon Sep 17 00:00:00 2001 From: Charlie Vaske Date: Tue, 27 Feb 2024 16:51:17 -0800 Subject: [PATCH] Pass no tool argument when none provided 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 --- chatlab/chat.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/chatlab/chat.py b/chatlab/chat.py index 19d12a3..1c91f66 100644 --- a/chatlab/chat.py +++ b/chatlab/chat.py @@ -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) @@ -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,