GTP response error check

This commit is contained in:
SevaSk 2023-05-13 16:04:35 -04:00
parent 9bac8bf41b
commit 02d1f12c76

View File

@ -6,11 +6,15 @@ import time
openai.api_key = OPENAI_API_KEY openai.api_key = OPENAI_API_KEY
def generate_response_from_transcript(transcript): def generate_response_from_transcript(transcript):
try:
response = openai.ChatCompletion.create( response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-0301", model="gpt-3.5-turbo-0301",
messages=[{"role": "system", "content": create_prompt(transcript)}], messages=[{"role": "system", "content": create_prompt(transcript)}],
temperature = 0.0 temperature = 0.0
) )
except openai.OpenAIError:
print("An error occurred while calling OpenAI ChatCompletion.")
return ''
full_response = response.choices[0].message.content full_response = response.choices[0].message.content
try: try:
return full_response.split('[')[1].split(']')[0] return full_response.split('[')[1].split(']')[0]