Skip to content

Commit

Permalink
[GPT] fix no key config
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeDSM committed Jan 13, 2025
1 parent 30e45ec commit b28b0fc
Showing 1 changed file with 14 additions and 4 deletions.
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
return key

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

0 comments on commit b28b0fc

Please sign in to comment.