Skip to content

Commit f45371a

Browse files
committed
Fix async usage
1 parent 030053c commit f45371a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/gptcmd/message.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ def __init__(
151151
continue
152152
self.stream: bool = False
153153
self._openai = openai.OpenAI()
154+
self._async_openai: Optional[openai.AsyncOpenAI] = (
155+
None # Lazily create as not used in the CLI
156+
)
154157
if model is None:
155158
models = self._openai.models.list().data
156159
if self._is_valid_model("gpt-4", models=models):
@@ -347,8 +350,10 @@ async def asend(self) -> Union[Message, AioMessageStream]:
347350
append the result to this thread. Note that this method must
348351
be awaited.
349352
"""
353+
if self._async_openai is None:
354+
self._async_openai = openai.AsyncOpenAI()
350355
self._pre_send()
351-
resp = await self._openai.chat.completions.acreate(
356+
resp = await self._openai.chat.completions.create(
352357
**self._get_openai_kwargs()
353358
)
354359
return self._post_send(resp, AioMessageStream)

0 commit comments

Comments
 (0)