Skip to content

Commit

Permalink
Support obtaining the API key passed in from the front-end.
Browse files Browse the repository at this point in the history
  • Loading branch information
WongSaang committed Mar 24, 2023
1 parent 06c6a93 commit ad93bfa
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions chat/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def conversation(request):
frequency_penalty = request.data.get('frequency_penalty', 0)
presence_penalty = request.data.get('presence_penalty', 0)
web_search_params = request.data.get('web_search')
openai_api_key = request.data.get('openaiApiKey')

if conversation_id:
# get the conversation
Expand Down Expand Up @@ -188,7 +189,7 @@ def stream_content():
'userMessageId': message_obj.id,
})

myOpenai = get_openai()
myOpenai = get_openai(openai_api_key)

openai_response = myOpenai.ChatCompletion.create(
model=model['name'],
Expand Down Expand Up @@ -304,8 +305,10 @@ def num_tokens_from_messages(messages, model="gpt-3.5-turbo"):
tokens.""")


def get_openai():
openai.api_key = get_openai_api_key()
def get_openai(openai_api_key = None):
if openai_api_key is None:
openai_api_key = get_openai_api_key()
openai.api_key = openai_api_key
proxy = os.getenv('OPENAI_API_PROXY')
if proxy:
openai.api_base = proxy
Expand Down

0 comments on commit ad93bfa

Please sign in to comment.