Skip to content

Commit 2157a82

Browse files
authored
Merge pull request #56 from devchat-ai/fix_openai_key_error
Add environment variables for OpenAI API key and base URL
2 parents dae577b + 294c2d1 commit 2157a82

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

unit_tests/openai_util.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from typing import Optional
23

34
from openai import OpenAI, Stream
@@ -13,7 +14,10 @@ def create_chat_completion_chunks(
1314
"""
1415
Create streaming responses.
1516
"""
16-
_client = client or OpenAI()
17+
_client = client or OpenAI(
18+
api_key=os.environ.get("OPENAI_API_KEY", None),
19+
base_url=os.environ.get("OPENAI_API_BASE", None),
20+
)
1721

1822
# Force to use streaming
1923
kwargs["stream"] = True
@@ -36,7 +40,10 @@ def create_chat_completion_content(client: Optional[OpenAI] = None, **kwargs) ->
3640
3741
This is a replacement of creating non-streaming chat completion.
3842
"""
39-
_client = client or OpenAI()
43+
_client = client or OpenAI(
44+
api_key=os.environ.get("OPENAI_API_KEY", None),
45+
base_url=os.environ.get("OPENAI_API_BASE", None),
46+
)
4047

4148
# Force to use streaming
4249
kwargs["stream"] = True

0 commit comments

Comments
 (0)