Skip to content

Commit

Permalink
Fix openai API usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricklamers committed Jul 25, 2023
1 parent da98893 commit 99a6ba8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
OPENAI_API_KEY=sk-XXXX
OPENAI_API_TYPE=openai
OPENAI_BASE_URL=https://api.openai.com
OPENAI_API_TYPE=open_ai
OPENAI_BASE_URL=https://api.openai.com/v1
OPENAI_API_VERSION=2023-03-15-preview
# OPENAI_EXTRA_HEADERS={"key": "value"}
OPENAI_MODELS=[{"displayName": "GPT-3.5", "name": "gpt-3.5-turbo"}, {"displayName": "GPT-4", "name": "gpt-4"}]
Expand Down
9 changes: 3 additions & 6 deletions gpt_code_ui/webapp/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@

load_dotenv('.env')

openai.api_base = os.environ.get("OPENAI_BASE_URL", "https://api.openai.com")
openai.api_type = os.environ.get("OPENAI_API_TYPE", "openai")
openai.api_version = os.environ.get("OPENAI_API_VERSION")
openai.api_key = os.environ.get("OPENAI_API_KEY", "")
openai.log = os.getenv("OPENAI_API_LOGLEVEL", "")
openai.log = os.getenv("OPENAI_API_LOGLEVEL")
OPENAI_EXTRA_HEADERS = json.loads(os.environ.get("OPENAI_EXTRA_HEADERS", "{}"))

if openai.api_type == "openai":
if openai.api_type == "open_ai":
AVAILABLE_MODELS = json.loads(os.environ.get("OPENAI_MODELS", '''[{"displayName": "GPT-3.5", "name": "gpt-3.5-turbo"}, {"displayName": "GPT-4", "name": "gpt-4"}]'''))
elif openai.api_type == "azure":
try:
Expand Down Expand Up @@ -138,7 +135,7 @@ async def get_code(user_prompt, user_openai_key=None, model="gpt-3.5-turbo"):
]
)

if openai.api_type == 'openai':
if openai.api_type == 'open_ai':
arguments["model"] = model
elif openai.api_type == 'azure':
arguments["deployment_id"] = model
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='gpt_code_ui',
version='0.42.38',
version='0.42.39',
description="An Open Source version of ChatGPT Code Interpreter",
long_description=long_description,
long_description_content_type='text/markdown', # This field specifies the format of the `long_description`.
Expand Down

4 comments on commit 99a6ba8

@dasmy
Copy link
Contributor

@dasmy dasmy commented on 99a6ba8 Jul 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this. - Due to this fix I just recognized that my local tests using the openai API were disabled a while ago as Azure was my default. Sorry for breaking things that worked before.

@ricklamers
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good! I guess a basic unit test suite should be added next 😄

@StephenHnilica
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On this note, I've gotten this error:

Error from API: Unsupported OpenAI-Version header provided: 2023-03-15-preview. (HINT: you can provide any of the following supported versions: 2020-10-01, 2020-11-07. Alternatively, you can simply omit this header to use the default version associated with your account.)

Changing to https://api.openai.com/v1/chat/completions as the URL didn't fix things. I'll make an issue report on this later.

@ricklamers
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixed as per da98893

Please sign in to comment.