Skip to content

Commit

Permalink
Merge pull request #2 from M507/app-in-docker
Browse files Browse the repository at this point in the history
Fix OpenAI message error + rename client vars
  • Loading branch information
M507 authored Dec 22, 2023
2 parents 405392a + 3e38957 commit 5727968
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

# Initialize the MongoDB client
mongo_uri = os.getenv('MONGODB_URI')
client = MongoClient(mongo_uri) # Replace with your MongoDB connection string
db = client["mydb"]
mongo_client = MongoClient(mongo_uri) # Replace with your MongoDB connection string
db = mongo_client["mydb"]
collection = db["user_requests"]
prompts_collection = db["good_prompts"]

Expand Down Expand Up @@ -75,13 +75,13 @@ def check_prompt(prompt):
ip_request_timestamps = {}

def get_response_from_gpt(context, prompt):
client = OpenAI(api_key=openai_api_key)
openai_client = OpenAI(api_key=openai_api_key)

completion = client.chat.completions.create(model='gpt-3.5-turbo', messages=[
completion = openai_client.chat.completions.create(model='gpt-3.5-turbo', messages=[
{"role": "system", "content": context},
{"role": "user", "content": prompt}
])
response_from_gpt = completion.choices[0].message['content']
response_from_gpt = completion.choices[0].message.content
logger.debug(f'Info message - response_from_gpt: {response_from_gpt}')
return response_from_gpt

Expand Down

0 comments on commit 5727968

Please sign in to comment.