File size: 1,930 Bytes
6e1aac6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# import os            
# import openai            
# openai.api_type = "azure"            
# openai.api_base = "https://fevaworksopenai.openai.azure.com/"            
# openai.api_version = "2023-03-15-preview"            
# openai.api_key = os.getenv("OPENAI_API_KEY")            
#              
# response = openai.ChatCompletion.create(            
#   engine="gpt-35-turbo",            
#   messages = [{"role":"system","content":"You are an AI assistant that helps people find information."},{"role":"user","content":"<input>"            
#   max_tokens=800,            
#   top_p=0.95,            
#   frequency_penalty=0,            
#   presence_penalty=0,            
#   stop=None)            
# &nbsp;            
# 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

import os  
import openai  
import streamlit as st  
  
# Set up OpenAI API  
openai.api_type = "azure"  
openai.api_base = "https://fevaworksopenai.openai.azure.com/"  
openai.api_version = "2023-03-15-preview"  
openai.api_key = os.getenv("OPENAI_API_KEY")  
  
# Streamlit app  
st.title("AI Chatbot")  
st.write("Ask your question and get a response from the AI.")  
  
user_input = st.text_input("Your question:")  
if st.button("Send"):  
    if user_input:  
        response = openai.ChatCompletion.create(  
            engine="gpt-35-turbo",  
            messages=[{"role": "system", "content": "You are an AI assistant that helps people find information."},  
                      {"role": "user", "content": user_input}],  
            max_tokens=800,  
            top_p=0.95,  
            frequency_penalty=0,  
            presence_penalty=0,  
            stop=None)  
  
        st.write("AI response:", response.choices[0].message["content"])  
    else:  
        st.write("Please enter a question.")