Skip to content

Commit

Permalink
make it more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
agahkarakuzu committed Apr 4, 2024
1 parent 35c463d commit 0442fe0
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions api/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,18 @@ def get_book_target_tail(book_url,commit_hash):

def get_gpt_response(prompt):
client = OpenAI(api_key=os.getenv('OAI_TOKEN'))
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful editorial bot for a scientific journal. Your task is to help publish reproducible articles."},
{"role": "user", "content": prompt}
])
answer = response.choices[0].message.content
if answer:
try:
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful editorial bot for a scientific journal. Your task is to help publish reproducible articles."},
{"role": "user", "content": prompt}
])
answer = response.choices[0].message.content
except:
answer = None

if answer != None:
return answer
else:
return "GPT is AFK, keep hanging out with roboneuro."

0 comments on commit 0442fe0

Please sign in to comment.