Skip to content

Commit 5343d0d

Browse files
authored
fix: openai async (#585) bump:patch
1 parent 95191f5 commit 5343d0d

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

libs/kotaemon/kotaemon/llms/chats/openai.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ def openai_response(self, client, **kwargs):
196196
"""Get the openai response"""
197197
raise NotImplementedError
198198

199+
async def aopenai_response(self, client, **kwargs):
200+
"""Get the openai response"""
201+
raise NotImplementedError
202+
199203
def invoke(
200204
self, messages: str | BaseMessage | list[BaseMessage], *args, **kwargs
201205
) -> LLMInterface:
@@ -211,8 +215,10 @@ async def ainvoke(
211215
) -> LLMInterface:
212216
client = self.prepare_client(async_version=True)
213217
input_messages = self.prepare_message(messages)
214-
resp = await self.openai_response(
215-
client, messages=input_messages, stream=False, **kwargs
218+
resp = (
219+
await self.aopenai_response(
220+
client, messages=input_messages, stream=False, **kwargs
221+
)
216222
).dict()
217223

218224
return self.prepare_output(resp)
@@ -290,8 +296,7 @@ def prepare_client(self, async_version: bool = False):
290296

291297
return OpenAI(**params)
292298

293-
def openai_response(self, client, **kwargs):
294-
"""Get the openai response"""
299+
def prepare_params(self, **kwargs):
295300
if "tools_pydantic" in kwargs:
296301
kwargs.pop("tools_pydantic")
297302

@@ -313,8 +318,17 @@ def openai_response(self, client, **kwargs):
313318
params = {k: v for k, v in params_.items() if v is not None}
314319
params.update(kwargs)
315320

321+
return params
322+
323+
def openai_response(self, client, **kwargs):
324+
"""Get the openai response"""
325+
params = self.prepare_params(**kwargs)
316326
return client.chat.completions.create(**params)
317327

328+
async def aopenai_response(self, client, **kwargs):
329+
params = self.prepare_params(**kwargs)
330+
return await client.chat.completions.create(**params)
331+
318332

319333
class AzureChatOpenAI(BaseChatOpenAI):
320334
"""OpenAI chat model provided by Microsoft Azure"""
@@ -361,8 +375,7 @@ def prepare_client(self, async_version: bool = False):
361375

362376
return AzureOpenAI(**params)
363377

364-
def openai_response(self, client, **kwargs):
365-
"""Get the openai response"""
378+
def prepare_params(self, **kwargs):
366379
if "tools_pydantic" in kwargs:
367380
kwargs.pop("tools_pydantic")
368381

@@ -384,4 +397,13 @@ def openai_response(self, client, **kwargs):
384397
params = {k: v for k, v in params_.items() if v is not None}
385398
params.update(kwargs)
386399

400+
return params
401+
402+
def openai_response(self, client, **kwargs):
403+
"""Get the openai response"""
404+
params = self.prepare_params(**kwargs)
387405
return client.chat.completions.create(**params)
406+
407+
async def aopenai_response(self, client, **kwargs):
408+
params = self.prepare_params(**kwargs)
409+
return await client.chat.completions.create(**params)

libs/ktem/ktem/pages/chat/chat_panel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def on_building_ui(self):
2626
scale=20,
2727
file_count="multiple",
2828
placeholder=(
29-
"Type a message, or search the @web, " "tag a file with @filename"
29+
"Type a message, search the @web, or tag a file with @filename"
3030
),
3131
container=False,
3232
show_label=False,

0 commit comments

Comments
 (0)