fix: openai async (#585) bump:patch
This commit is contained in:
parent
95191f53d9
commit
5343d0d3ee
|
@ -196,6 +196,10 @@ class BaseChatOpenAI(ChatLLM):
|
|||
"""Get the openai response"""
|
||||
raise NotImplementedError
|
||||
|
||||
async def aopenai_response(self, client, **kwargs):
|
||||
"""Get the openai response"""
|
||||
raise NotImplementedError
|
||||
|
||||
def invoke(
|
||||
self, messages: str | BaseMessage | list[BaseMessage], *args, **kwargs
|
||||
) -> LLMInterface:
|
||||
|
@ -211,8 +215,10 @@ class BaseChatOpenAI(ChatLLM):
|
|||
) -> LLMInterface:
|
||||
client = self.prepare_client(async_version=True)
|
||||
input_messages = self.prepare_message(messages)
|
||||
resp = await self.openai_response(
|
||||
resp = (
|
||||
await self.aopenai_response(
|
||||
client, messages=input_messages, stream=False, **kwargs
|
||||
)
|
||||
).dict()
|
||||
|
||||
return self.prepare_output(resp)
|
||||
|
@ -290,8 +296,7 @@ class ChatOpenAI(BaseChatOpenAI):
|
|||
|
||||
return OpenAI(**params)
|
||||
|
||||
def openai_response(self, client, **kwargs):
|
||||
"""Get the openai response"""
|
||||
def prepare_params(self, **kwargs):
|
||||
if "tools_pydantic" in kwargs:
|
||||
kwargs.pop("tools_pydantic")
|
||||
|
||||
|
@ -313,8 +318,17 @@ class ChatOpenAI(BaseChatOpenAI):
|
|||
params = {k: v for k, v in params_.items() if v is not None}
|
||||
params.update(kwargs)
|
||||
|
||||
return params
|
||||
|
||||
def openai_response(self, client, **kwargs):
|
||||
"""Get the openai response"""
|
||||
params = self.prepare_params(**kwargs)
|
||||
return client.chat.completions.create(**params)
|
||||
|
||||
async def aopenai_response(self, client, **kwargs):
|
||||
params = self.prepare_params(**kwargs)
|
||||
return await client.chat.completions.create(**params)
|
||||
|
||||
|
||||
class AzureChatOpenAI(BaseChatOpenAI):
|
||||
"""OpenAI chat model provided by Microsoft Azure"""
|
||||
|
@ -361,8 +375,7 @@ class AzureChatOpenAI(BaseChatOpenAI):
|
|||
|
||||
return AzureOpenAI(**params)
|
||||
|
||||
def openai_response(self, client, **kwargs):
|
||||
"""Get the openai response"""
|
||||
def prepare_params(self, **kwargs):
|
||||
if "tools_pydantic" in kwargs:
|
||||
kwargs.pop("tools_pydantic")
|
||||
|
||||
|
@ -384,4 +397,13 @@ class AzureChatOpenAI(BaseChatOpenAI):
|
|||
params = {k: v for k, v in params_.items() if v is not None}
|
||||
params.update(kwargs)
|
||||
|
||||
return params
|
||||
|
||||
def openai_response(self, client, **kwargs):
|
||||
"""Get the openai response"""
|
||||
params = self.prepare_params(**kwargs)
|
||||
return client.chat.completions.create(**params)
|
||||
|
||||
async def aopenai_response(self, client, **kwargs):
|
||||
params = self.prepare_params(**kwargs)
|
||||
return await client.chat.completions.create(**params)
|
||||
|
|
|
@ -26,7 +26,7 @@ class ChatPanel(BasePage):
|
|||
scale=20,
|
||||
file_count="multiple",
|
||||
placeholder=(
|
||||
"Type a message, or search the @web, " "tag a file with @filename"
|
||||
"Type a message, search the @web, or tag a file with @filename"
|
||||
),
|
||||
container=False,
|
||||
show_label=False,
|
||||
|
|
Loading…
Reference in New Issue
Block a user