zjrwtx commited on
Commit
a63736e
·
1 Parent(s): 6652184

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -2
app.py CHANGED
@@ -1,4 +1,28 @@
 
1
  import streamlit as st
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
  import streamlit as st
3
 
4
+ openai.api_key ="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" # Replace this with your API key: https://beta.openai.com/docs/quickstart/add-your-api-key
5
+
6
+ def openai_chat(prompt):
7
+ completions = openai.Completion.create(
8
+ engine="text-davinci-003",
9
+ prompt="请给出这道题的答案与解释:"+prompt,
10
+ max_tokens=1024,
11
+ n=1,
12
+ temperature=0.5,
13
+ )
14
+
15
+ message = completions.choices[0].text
16
+ return message.strip()
17
+
18
+ def chatbot():
19
+ history = []
20
+ input_text = st.text_input("Enter your question:")
21
+ if st.button('Submit'):
22
+ output = openai_chat(input_text)
23
+ history.append((input_text, output))
24
+ st.write("Robot: ",output)
25
+ st.write("History:",history)
26
+
27
+ if __name__ == "__main__":
28
+ chatbot()