initial commit
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
| 6 |
+
if not openai.api_key:
|
| 7 |
+
openai.api_key = st.text_input("Your openai api key", placeholder="Input your OpenAI API key here")
|
| 8 |
+
|
| 9 |
+
if openai.api_key:
|
| 10 |
+
user_prompt = st.text_input("Prompt", placeholder="Ask me anything")
|
| 11 |
+
|
| 12 |
+
if user_prompt:
|
| 13 |
+
response = openai.ChatCompletion.create(
|
| 14 |
+
model="gpt-3.5-turbo",
|
| 15 |
+
messages=[
|
| 16 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
| 17 |
+
{"role": "user", "content": user_prompt},
|
| 18 |
+
],
|
| 19 |
+
max_tokens=1000,
|
| 20 |
+
temperature=0.7,
|
| 21 |
+
)
|
| 22 |
+
#print(response)
|
| 23 |
+
json_object = json.loads(str(response))
|
| 24 |
+
st.write(json_object['choices'][0]['message']['content'])
|
| 25 |
+
st.write(json_object['usage'])
|