arthurcarvalho commited on
Commit
8dd3847
·
verified ·
1 Parent(s): 8b26583

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -13,16 +13,14 @@ image = Image.open('logo.png')
13
  st.image(image)
14
 
15
  if "openai_model" not in st.session_state:
16
- st.session_state["openai_model"] = "gpt-4o"
17
 
18
  if "messages" not in st.session_state:
19
  st.session_state.messages = []
20
- st.session_state.messages.append({"role": "system", "content": grounding})
21
 
22
  for message in st.session_state.messages:
23
- if message["role"] != "system":
24
- with st.chat_message(message["role"]):
25
- st.markdown(message["content"])
26
 
27
  if prompt := st.chat_input("How can I help you today?"):
28
  st.session_state.messages.append({"role": "user", "content": prompt})
@@ -32,15 +30,16 @@ if prompt := st.chat_input("How can I help you today?"):
32
  with st.chat_message("assistant"):
33
  message_placeholder = st.empty()
34
  full_response = ""
35
- for response in openai.ChatCompletion.create(
36
  model=st.session_state["openai_model"],
37
- messages=[
 
38
  {"role": m["role"], "content": m["content"]}
39
  for m in st.session_state.messages
40
  ],
41
  stream=True,
42
  ):
43
- full_response += response.choices[0].delta.get("content", "").replace('\\$','$').replace('$','\\$')
44
  message_placeholder.markdown(full_response + "▌")
45
  message_placeholder.markdown(full_response)
46
  print(full_response)
 
13
  st.image(image)
14
 
15
  if "openai_model" not in st.session_state:
16
+ st.session_state["openai_model"] = "gpt-4o-mini"
17
 
18
  if "messages" not in st.session_state:
19
  st.session_state.messages = []
 
20
 
21
  for message in st.session_state.messages:
22
+ with st.chat_message(message["role"]):
23
+ st.markdown(message["content"])
 
24
 
25
  if prompt := st.chat_input("How can I help you today?"):
26
  st.session_state.messages.append({"role": "user", "content": prompt})
 
30
  with st.chat_message("assistant"):
31
  message_placeholder = st.empty()
32
  full_response = ""
33
+ for response in openai.responses.create(
34
  model=st.session_state["openai_model"],
35
+ instructions = grounding,
36
+ input=[
37
  {"role": m["role"], "content": m["content"]}
38
  for m in st.session_state.messages
39
  ],
40
  stream=True,
41
  ):
42
+ full_response += response.output_text.replace('\\$','$').replace('$','\\$')
43
  message_placeholder.markdown(full_response + "▌")
44
  message_placeholder.markdown(full_response)
45
  print(full_response)