Skip to content

Commit 4dd772d

Browse files
fix: openai async client bug #130
Update openai.py
2 parents 6e6dff6 + c755193 commit 4dd772d

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

Diff for: agentverse/llms/openai.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,12 @@ def generate_response(
232232
try:
233233
# Execute function call
234234
if functions != []:
235-
response = openai_client.chat.completions.create(
236-
messages=messages,
237-
functions=functions,
238-
**self.args.dict(),
239-
)
235+
async with async_openai_client:
236+
response = openai_client.chat.completions.create(
237+
messages=messages,
238+
functions=functions,
239+
**self.args.dict(),
240+
)
240241

241242
logger.log_prompt(
242243
[
@@ -275,10 +276,11 @@ def generate_response(
275276
)
276277

277278
else:
278-
response = openai_client.chat.completions.create(
279-
messages=messages,
280-
**self.args.dict(),
281-
)
279+
async with async_openai_client:
280+
response = openai_client.chat.completions.create(
281+
messages=messages,
282+
**self.args.dict(),
283+
)
282284
logger.log_prompt(
283285
[
284286
{

0 commit comments

Comments
 (0)