vsouza commited on
Commit
7dcb88a
·
1 Parent(s): 771f2d0

remove cookies test

Browse files
Files changed (1) hide show
  1. app.py +28 -32
app.py CHANGED
@@ -26,42 +26,40 @@ if "messages" not in st.session_state:
26
 
27
  st.title(":speech_balloon: Assistant API Chat")
28
 
29
- def get_all_cookies():
30
- '''
31
- WARNING: This uses unsupported feature of Streamlit
32
- Returns the cookies as a dictionary of kv pairs
33
- '''
34
- from streamlit.web.server.websocket_headers import _get_websocket_headers
35
- from urllib.parse import unquote
36
-
37
- headers = _get_websocket_headers()
38
- if headers is None:
39
- return {}
40
-
41
- if 'Cookie' not in headers:
42
- return {}
43
-
44
- cookie_string = headers['Cookie']
45
- # A sample cookie string: "K1=V1; K2=V2; K3=V3"
46
- cookie_kv_pairs = cookie_string.split(';')
47
-
48
- cookie_dict = {}
49
- for kv in cookie_kv_pairs:
50
- k_and_v = kv.split('=')
51
- k = k_and_v[0].strip()
52
- v = k_and_v[1].strip()
53
- cookie_dict[k] = unquote(v) #e.g. Convert name%40company.com to name@company.com
54
- return cookie_dict
55
-
56
 
57
  with st.sidebar:
58
  st.caption(f"**Session ID**: \n {st.session_state.session_id}")
59
  st.header("Configuration")
60
  thread_id = st.sidebar.text_input("Enter your Thread ID:", placeholder="Leave empty to start a new thread")
61
  c1, c2 = st.columns(2)
62
- st.write(get_all_cookies())
63
  if c1.button("Start Chat", use_container_width=True):
64
-
65
  st.session_state.start_chat = True
66
  if thread_id:
67
  st.session_state.thread_id = thread_id
@@ -79,7 +77,7 @@ with st.sidebar:
79
  st.session_state.thread_id = None
80
  cookie_manager.delete('thread_id')
81
 
82
- #def process_message(message):
83
  # message_content = message.content[0].text
84
  # annotations = message_content.annotations if hasattr(message_content, 'annotations') else []
85
  # citations = []
@@ -87,7 +85,6 @@ with st.sidebar:
87
  # return full_response
88
 
89
  if st.session_state.thread_id:
90
-
91
  st.session_state.messages = client.beta.threads.messages.list(
92
  thread_id=st.session_state.thread_id
93
  )
@@ -97,7 +94,6 @@ if st.session_state.thread_id:
97
  st.markdown(message.content[0].text.value)
98
 
99
  if prompt := st.chat_input():
100
-
101
  with st.chat_message("user"):
102
  st.markdown(prompt)
103
 
 
26
 
27
  st.title(":speech_balloon: Assistant API Chat")
28
 
29
+ #def get_all_cookies():
30
+ # '''
31
+ # WARNING: This uses unsupported feature of Streamlit
32
+ # Returns the cookies as a dictionary of kv pairs
33
+ # '''
34
+ # from streamlit.web.server.websocket_headers import _get_websocket_headers
35
+ # from urllib.parse import unquote
36
+ #
37
+ # headers = _get_websocket_headers()
38
+ # if headers is None:
39
+ # return {}
40
+ #
41
+ # if 'Cookie' not in headers:
42
+ # return {}
43
+ #
44
+ # cookie_string = headers['Cookie']
45
+ # # A sample cookie string: "K1=V1; K2=V2; K3=V3"
46
+ # cookie_kv_pairs = cookie_string.split(';')
47
+ #
48
+ # cookie_dict = {}
49
+ # for kv in cookie_kv_pairs:
50
+ # k_and_v = kv.split('=')
51
+ # k = k_and_v[0].strip()
52
+ # v = k_and_v[1].strip()
53
+ # cookie_dict[k] = unquote(v) #e.g. Convert name%40company.com to name@company.com
54
+ # return cookie_dict
 
55
 
56
  with st.sidebar:
57
  st.caption(f"**Session ID**: \n {st.session_state.session_id}")
58
  st.header("Configuration")
59
  thread_id = st.sidebar.text_input("Enter your Thread ID:", placeholder="Leave empty to start a new thread")
60
  c1, c2 = st.columns(2)
61
+
62
  if c1.button("Start Chat", use_container_width=True):
 
63
  st.session_state.start_chat = True
64
  if thread_id:
65
  st.session_state.thread_id = thread_id
 
77
  st.session_state.thread_id = None
78
  cookie_manager.delete('thread_id')
79
 
80
+ #def process_citations(message):
81
  # message_content = message.content[0].text
82
  # annotations = message_content.annotations if hasattr(message_content, 'annotations') else []
83
  # citations = []
 
85
  # return full_response
86
 
87
  if st.session_state.thread_id:
 
88
  st.session_state.messages = client.beta.threads.messages.list(
89
  thread_id=st.session_state.thread_id
90
  )
 
94
  st.markdown(message.content[0].text.value)
95
 
96
  if prompt := st.chat_input():
 
97
  with st.chat_message("user"):
98
  st.markdown(prompt)
99