Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GPT] fix no key config #1418

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions Services/Services_bases/gpt_service/gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# License along with this library.
import asyncio
import os
import uuid

import openai
import logging
import datetime
Expand Down Expand Up @@ -350,10 +352,18 @@ def get_logo(self):
return "https://upload.wikimedia.org/wikipedia/commons/0/04/ChatGPT_logo.svg"

def _get_api_key(self):
return self._env_secret_key or \
self.config[services_constants.CONFIG_CATEGORY_SERVICES][services_constants.CONFIG_GPT][
services_constants.CONIG_OPENAI_SECRET_KEY
]
key = (
self._env_secret_key or
self.config[services_constants.CONFIG_CATEGORY_SERVICES][services_constants.CONFIG_GPT].get(
services_constants.CONIG_OPENAI_SECRET_KEY, None
)
)
if key and not fields_utils.has_invalid_default_config_value(key):
return key
if self._get_base_url():
# no key and custom base url: use random key
return uuid.uuid4().hex
Copy link
Member Author

Choose a reason for hiding this comment

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

a key is required by the openai lib

return key

def _get_base_url(self):
value = self.config[services_constants.CONFIG_CATEGORY_SERVICES][services_constants.CONFIG_GPT].get(
Expand Down
Loading