Promotingai commited on
Commit
f0acf20
·
verified ·
1 Parent(s): 749f4b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -5,19 +5,26 @@ import os # Import the os module
5
  # Fetch the API key from an environment variable
6
  openai_api_key = os.getenv("OPENAI_API_KEY")
7
 
8
- st.title("💬 Chatbot")
9
- st.caption("")
 
 
 
 
 
 
 
 
10
 
11
  # Initialize session state for storing messages if it doesn't already exist
12
  if "messages" not in st.session_state:
13
- st.session_state["messages"] = [{"role": "assistant", "content": "How can I help you?"}]
 
14
 
15
  # Display all previous messages
16
  for msg in st.session_state.messages:
17
  st.chat_message(msg["role"]).write(msg["content"])
18
 
19
- # Select model using a dropdown
20
- model_choice = st.selectbox('Choose a model:', ['gpt-3.5-turbo', 'gpt-4', 'davinci', 'curie'])
21
 
22
  # Input for new prompts
23
  prompt = st.chat_input("Enter your question:")
@@ -31,11 +38,11 @@ if prompt:
31
  st.chat_message("user").write(prompt)
32
 
33
  # Use a spinner to indicate that the model is generating a response
34
- with st.spinner('Thinking...'):
35
  client = OpenAI(api_key=openai_api_key)
36
  response = client.chat.completions.create(model=model_choice, messages=st.session_state.messages)
37
  msg = response.choices[0].message.content
38
 
39
  # Append and display the assistant's response
40
  st.session_state.messages.append({"role": "assistant", "content": msg})
41
- st.chat_message("assistant").write(msg)
 
5
  # Fetch the API key from an environment variable
6
  openai_api_key = os.getenv("OPENAI_API_KEY")
7
 
8
+ # Select model using a dropdown
9
+ model_choice = st.selectbox('Choose a model:', ['gpt-4-turbo','gpt-3.5-turbo', 'gpt-3.5-turbo-0125','gpt-3.5-turbo-1106','gpt-3.5-turbo-0613','gpt-3.5-turbo-16k-0613','gpt-3.5-turbo-16k','gpt-4-turbo-2024-04-09','gpt-4-turbo-preview', 'gpt-4-0125-preview','gpt-4-1106-preview','gpt-4-0613'])
10
+
11
+ # Lecture du message système à partir d'un fichier texte
12
+ try:
13
+ with open("system_message.txt", "r") as file:
14
+ system_message = file.read().strip()
15
+ except FileNotFoundError:
16
+ st.error("The system message file was not found. Please make sure 'system_message.txt' exists.")
17
+ st.stop()
18
 
19
  # Initialize session state for storing messages if it doesn't already exist
20
  if "messages" not in st.session_state:
21
+ st.session_state["messages"] = [{"role": "system", "content": system_message},
22
+ {"role": "assistant", "content": "How can I help you?"}]
23
 
24
  # Display all previous messages
25
  for msg in st.session_state.messages:
26
  st.chat_message(msg["role"]).write(msg["content"])
27
 
 
 
28
 
29
  # Input for new prompts
30
  prompt = st.chat_input("Enter your question:")
 
38
  st.chat_message("user").write(prompt)
39
 
40
  # Use a spinner to indicate that the model is generating a response
41
+ with st.spinner('PromptingAI is Thinking...'):
42
  client = OpenAI(api_key=openai_api_key)
43
  response = client.chat.completions.create(model=model_choice, messages=st.session_state.messages)
44
  msg = response.choices[0].message.content
45
 
46
  # Append and display the assistant's response
47
  st.session_state.messages.append({"role": "assistant", "content": msg})
48
+ st.chat_message("assistant").write(msg)