bizvideoschool commited on
Commit
8cbb2af
·
1 Parent(s): 959fd59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import openai
2
  import gradio
3
  import os
 
4
 
5
  openai.api_key = os.environ["OPENAI_API_KEY"]
6
 
@@ -18,12 +19,16 @@ of the viewer and summarize what they can expect to hear in the rest of the scri
18
  4. Choose the best hook and replace the beginning of the script draft with that hook.
19
  5. Return just the words the agent should read into the camera."""}]
20
 
 
 
 
 
 
 
 
21
  def CustomChatGPT(user_input, messages):
22
  messages.append({"role": "user", "content": user_input})
23
- response = openai.ChatCompletion.create(
24
- model = "gpt-3.5-turbo",
25
- messages = messages
26
- )
27
  ChatGPT_reply = response["choices"][0]["message"]["content"]
28
  messages.append({"role": "assistant", "content": ChatGPT_reply})
29
  return ChatGPT_reply, messages
 
1
  import openai
2
  import gradio
3
  import os
4
+ from tenacity import retry, wait_fixed, stop_after_attempt
5
 
6
  openai.api_key = os.environ["OPENAI_API_KEY"]
7
 
 
19
  4. Choose the best hook and replace the beginning of the script draft with that hook.
20
  5. Return just the words the agent should read into the camera."""}]
21
 
22
+ @retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
23
+ def call_openai_api(messages):
24
+ return openai.ChatCompletion.create(
25
+ model="gpt-3.5-turbo",
26
+ messages=messages
27
+ )
28
+
29
  def CustomChatGPT(user_input, messages):
30
  messages.append({"role": "user", "content": user_input})
31
+ response = call_openai_api(messages)
 
 
 
32
  ChatGPT_reply = response["choices"][0]["message"]["content"]
33
  messages.append({"role": "assistant", "content": ChatGPT_reply})
34
  return ChatGPT_reply, messages