Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
fix: openai error exception without api key
Browse files Browse the repository at this point in the history
  • Loading branch information
loyal812 committed Mar 28, 2024
1 parent 6da82fe commit 87df1fa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches:
- main
- dev
- fix/docker

jobs:
test:
Expand Down
5 changes: 2 additions & 3 deletions src/utils/chatgpt_communicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from dotenv import load_dotenv

load_dotenv()
client = OpenAI()


class ChatGPTCommunicator:
"""
Expand All @@ -23,6 +21,7 @@ def __init__(self, api_key=None, language_model="gpt-4"):
self.api_key = api_key or os.getenv("OPENAI_API_KEY")
self.language_model = language_model
self.messages = [{"role": "system", "content": "You are a helpful assistant."}]
self.client = OpenAI(api_key=self.api_key)


def create_chat(self, initial_message):
Expand Down Expand Up @@ -62,7 +61,7 @@ def get_response(self):
raise ValueError("Chat not initialized. Call create_chat() first.")

try:
response = client.chat.completions.create(model=self.language_model,
response = self.client.chat.completions.create(model=self.language_model,
messages=self.messages)
# Directly accessing the content of the message from the response
if response.choices and hasattr(response.choices[0].message, 'content'):
Expand Down

0 comments on commit 87df1fa

Please sign in to comment.