File size: 1,081 Bytes
eef1095
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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.text_area("AI response:", value=response.choices[0].text)    
    else:    
        st.write("Please enter a question.")