Skip to content

Commit

Permalink
fix: bug in openai async call. update requirements. #139 #134 #128
Browse files Browse the repository at this point in the history
  • Loading branch information
chenweize1998 committed Sep 9, 2024
1 parent 4dd772d commit f90c4bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions agentverse/llms/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@
AZURE_API_BASE = os.environ.get("AZURE_OPENAI_API_BASE")
VLLM_BASE_URL = os.environ.get("VLLM_BASE_URL")
VLLM_API_KEY = os.environ.get("VLLM_API_KEY", "EMPTY")

if not OPENAI_API_KEY and not AZURE_API_KEY:
logger.warn(
"OpenAI API key is not set. Please set an environment variable OPENAI_API_KEY or "
"AZURE_OPENAI_API_KEY."
)
elif OPENAI_API_KEY:
DEFAULT_CLIENT = OpenAI(api_key=OPENAI_API_KEY, base_url=OPENAI_BASE_URL)
DEFAULT_CLIENT_ASYNC = AsyncOpenAI(api_key=OPENAI_API_KEY, base_url=OPENAI_BASE_URL)
DEFAULT_CLIENT_ASYNC = AsyncOpenAI(
api_key=OPENAI_API_KEY, base_url=OPENAI_BASE_URL
)
api_key = OPENAI_API_KEY
base_url = OPENAI_BASE_URL
elif AZURE_API_KEY:
Expand Down Expand Up @@ -232,12 +234,11 @@ def generate_response(
try:
# Execute function call
if functions != []:
async with async_openai_client:
response = openai_client.chat.completions.create(
messages=messages,
functions=functions,
**self.args.dict(),
)
response = openai_client.chat.completions.create(
messages=messages,
functions=functions,
**self.args.dict(),
)

logger.log_prompt(
[
Expand Down Expand Up @@ -276,11 +277,10 @@ def generate_response(
)

else:
async with async_openai_client:
response = openai_client.chat.completions.create(
messages=messages,
**self.args.dict(),
)
response = openai_client.chat.completions.create(
messages=messages,
**self.args.dict(),
)
logger.log_prompt(
[
{
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fastapi==0.95.1
uvicorn
py3langid
setuptools-scm
openai==1.5.0
openai==1.1.0
opencv-python==4.8.0.76
gradio
httpx[socks]==0.25.0
Expand Down

0 comments on commit f90c4bd

Please sign in to comment.