Kaludi commited on
Commit
4b8fbf1
·
1 Parent(s): 5bc9297

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -3,14 +3,14 @@ import requests
3
  import json
4
 
5
  st.title("OpenAI Chatbot")
6
- st.write("Interact with OpenAI's GPT-3 models in real-time using your OpenAI API. Choose from a selection of their best models, set the temperature and max tokens, and start a conversation. Delete the conversation at any time to start fresh.")
7
 
8
  if "history" not in st.session_state:
9
  st.session_state.history = []
10
 
11
  st.sidebar.markdown("## Configuration")
12
  KEY = st.sidebar.text_input("Enter your OpenAI API key")
13
- models = ['text-davinci-003', 'text-curie-001', 'text-babbage-001', 'text-ada-001']
14
  model = st.sidebar.selectbox("Select a model", models, index=0)
15
 
16
  temperature = st.sidebar.slider("Temperature", 0.0, 1.0, 0.7)
@@ -41,6 +41,9 @@ def generate_answer(prompt):
41
  "temperature": temperature,
42
  "max_tokens": max_tokens
43
  }
 
 
 
44
  response = requests.post(API_URL, headers=headers, data=json.dumps(data))
45
  result = response.json()
46
  if 'choices' in result:
@@ -50,8 +53,6 @@ def generate_answer(prompt):
50
  else:
51
  st.error("An error occurred while processing the API response.")
52
 
53
-
54
-
55
  prompt = st.text_input("Prompt")
56
  if st.button("Submit"):
57
  generate_answer(prompt)
 
3
  import json
4
 
5
  st.title("OpenAI Chatbot")
6
+ st.write("Interact with OpenAI's models in real-time using your OpenAI API. Choose from a selection of their best models, set the temperature and max tokens, and start a conversation. Delete the conversation at any time and start fresh.")
7
 
8
  if "history" not in st.session_state:
9
  st.session_state.history = []
10
 
11
  st.sidebar.markdown("## Configuration")
12
  KEY = st.sidebar.text_input("Enter your OpenAI API key")
13
+ models = ['text-davinci-003', 'text-curie-001 (WIP)', 'text-babbage-001 (WIP)', 'text-ada-001 (WIP)']
14
  model = st.sidebar.selectbox("Select a model", models, index=0)
15
 
16
  temperature = st.sidebar.slider("Temperature", 0.0, 1.0, 0.7)
 
41
  "temperature": temperature,
42
  "max_tokens": max_tokens
43
  }
44
+ if not API_KEY:
45
+ st.warning("Please input your API key")
46
+ return
47
  response = requests.post(API_URL, headers=headers, data=json.dumps(data))
48
  result = response.json()
49
  if 'choices' in result:
 
53
  else:
54
  st.error("An error occurred while processing the API response.")
55
 
 
 
56
  prompt = st.text_input("Prompt")
57
  if st.button("Submit"):
58
  generate_answer(prompt)