Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,7 @@ if "history" not in st.session_state:
|
|
10 |
|
11 |
st.sidebar.markdown("## Configuration")
|
12 |
API_KEY = st.sidebar.text_input("Enter your OpenAI API key")
|
13 |
-
models = ['text-davinci-003', 'text-curie-001', '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)
|
@@ -18,10 +18,8 @@ max_tokens = st.sidebar.slider("Max Tokens", 0, 4000, 2024)
|
|
18 |
|
19 |
if st.sidebar.button("Delete Conversation"):
|
20 |
st.session_state.history = []
|
21 |
-
|
22 |
st.sidebar.markdown("## GPT-3")
|
23 |
st.sidebar.markdown("OpenAI's GPT-3 models can understand and generate natural language. They offer four main models with different levels of power suitable for different tasks. Davinci is the most capable model, and Ada is the fastest.")
|
24 |
-
|
25 |
st.sidebar.markdown("text-davinci-003 | 4,000 max tokens")
|
26 |
st.sidebar.markdown("text-curie-001 | 2,048 max tokens")
|
27 |
st.sidebar.markdown("text-babbage-001 | 2,048 max tokens")
|
@@ -45,9 +43,12 @@ def generate_answer(prompt):
|
|
45 |
}
|
46 |
response = requests.post(API_URL, headers=headers, data=json.dumps(data))
|
47 |
result = response.json()
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
51 |
|
52 |
|
53 |
|
|
|
10 |
|
11 |
st.sidebar.markdown("## Configuration")
|
12 |
API_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)
|
|
|
18 |
|
19 |
if st.sidebar.button("Delete Conversation"):
|
20 |
st.session_state.history = []
|
|
|
21 |
st.sidebar.markdown("## GPT-3")
|
22 |
st.sidebar.markdown("OpenAI's GPT-3 models can understand and generate natural language. They offer four main models with different levels of power suitable for different tasks. Davinci is the most capable model, and Ada is the fastest.")
|
|
|
23 |
st.sidebar.markdown("text-davinci-003 | 4,000 max tokens")
|
24 |
st.sidebar.markdown("text-curie-001 | 2,048 max tokens")
|
25 |
st.sidebar.markdown("text-babbage-001 | 2,048 max tokens")
|
|
|
43 |
}
|
44 |
response = requests.post(API_URL, headers=headers, data=json.dumps(data))
|
45 |
result = response.json()
|
46 |
+
if 'choices' in result:
|
47 |
+
message_bot = result['choices'][0]['text'].strip()
|
48 |
+
st.session_state.history.append({"message": prompt, "is_user": True})
|
49 |
+
st.session_state.history.append({"message": message_bot, "is_user": False})
|
50 |
+
else:
|
51 |
+
st.error("An error occurred while processing the API response.")
|
52 |
|
53 |
|
54 |
|