-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat_app.py
More file actions
46 lines (35 loc) · 1.21 KB
/
chat_app.py
File metadata and controls
46 lines (35 loc) · 1.21 KB
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
import streamlit as st
import openai
from decouple import config
# Read API key and API base from .env file
api_key = config('API_KEY')
api_base = config('API_BASE')
# Set OpenAI configuration
openai.api_type = "azure"
openai.api_base = api_base
openai.api_version = "2022-12-01"
openai.api_key = api_key
st.title("OpenAI Chatbot App (Streamlit)")
# Create and configure a chat display area
#chat_display = st.text_area("Chat Display", value="", height=400, max_chars=None, key="chat_display", disabled=True)
# Create an input field for user messages
user_message = st.text_input("your prompt")
# Create a button to send the message
if st.button("Send"):
# Display the user's message
st.markdown("You: " + user_message)
# Generate a response from the chatbot
response = openai.Completion.create(
engine="gpt35turbo",
prompt=user_message,
temperature=0.2,
max_tokens=500,
top_p=1,
frequency_penalty=0,
presence_penalty=0.5,
stop=None
)
bot_message = response.choices[0].text
# Display the chatbot's response
st.markdown("Bot: " + bot_message)
# Note: In Streamlit, there's no need to start a main loop; it's handled automatically.