Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# import os
|
| 2 |
+
# import openai
|
| 3 |
+
# openai.api_type = "azure"
|
| 4 |
+
# openai.api_base = "https://fevaworksopenai.openai.azure.com/"
|
| 5 |
+
# openai.api_version = "2023-03-15-preview"
|
| 6 |
+
# openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 7 |
+
#
|
| 8 |
+
# response = openai.ChatCompletion.create(
|
| 9 |
+
# engine="gpt-35-turbo",
|
| 10 |
+
# messages = [{"role":"system","content":"You are an AI assistant that helps people find information."},{"role":"user","content":"<input>"
|
| 11 |
+
# max_tokens=800,
|
| 12 |
+
# top_p=0.95,
|
| 13 |
+
# frequency_penalty=0,
|
| 14 |
+
# presence_penalty=0,
|
| 15 |
+
# stop=None)
|
| 16 |
+
#
|
| 17 |
+
# above is an openai chat API call, create a streamlit app with a chat interface that takes user input that enter button to send request and reply with openai API response
|
| 18 |
+
|
| 19 |
+
import os
|
| 20 |
+
import openai
|
| 21 |
+
import streamlit as st
|
| 22 |
+
|
| 23 |
+
# Set up OpenAI API
|
| 24 |
+
openai.api_type = "azure"
|
| 25 |
+
openai.api_base = "https://fevaworksopenai.openai.azure.com/"
|
| 26 |
+
openai.api_version = "2023-03-15-preview"
|
| 27 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 28 |
+
|
| 29 |
+
# Streamlit app
|
| 30 |
+
st.title("AI Chatbot")
|
| 31 |
+
st.write("Ask your question and get a response from the AI.")
|
| 32 |
+
|
| 33 |
+
user_input = st.text_input("Your question:")
|
| 34 |
+
if st.button("Send"):
|
| 35 |
+
if user_input:
|
| 36 |
+
response = openai.ChatCompletion.create(
|
| 37 |
+
engine="gpt-35-turbo",
|
| 38 |
+
messages=[{"role": "system", "content": "You are an AI assistant that helps people find information."},
|
| 39 |
+
{"role": "user", "content": user_input}],
|
| 40 |
+
max_tokens=800,
|
| 41 |
+
top_p=0.95,
|
| 42 |
+
frequency_penalty=0,
|
| 43 |
+
presence_penalty=0,
|
| 44 |
+
stop=None)
|
| 45 |
+
|
| 46 |
+
st.write("AI response:", response.choices[0].message["content"])
|
| 47 |
+
else:
|
| 48 |
+
st.write("Please enter a question.")
|