gerasdf commited on
Commit
0594bb7
·
1 Parent(s): 551b27a

sessions only saved for real users, names of sesssions are better, etc

Browse files
Files changed (1) hide show
  1. query.py +5 -2
query.py CHANGED
@@ -104,6 +104,9 @@ def new_state():
104
  "history" : None,
105
  })
106
 
 
 
 
107
  store = None
108
  def auth(token, state, request: gr.Request):
109
  global store
@@ -122,7 +125,7 @@ def auth(token, state, request: gr.Request):
122
  token=os.environ.get("ASTRA_DB_APPLICATION_TOKEN"),
123
  api_endpoint=os.environ.get("ASTRA_DB_API_ENDPOINT"),
124
  )
125
- user_session = f'{state["user"]}_{request.session_hash}'
126
  session_data = {
127
  'user' : state["user"],
128
  'session' : request.session_hash,
@@ -149,7 +152,7 @@ def not_authenticated(state):
149
 
150
  def add_history(state, request, type, message):
151
  if not state["history"]:
152
- session = request.session_hash
153
  state["history"] = AstraDBChatMessageHistory(
154
  session_id=session,
155
  collection_name=f'{os.environ.get("ASTRA_DB_COLLECTION")}_chat_history',
 
104
  "history" : None,
105
  })
106
 
107
+ def session_id(state: dict, request: gr.Request) -> str:
108
+ return f'{state["user"]}_{request.session_hash}'
109
+
110
  store = None
111
  def auth(token, state, request: gr.Request):
112
  global store
 
125
  token=os.environ.get("ASTRA_DB_APPLICATION_TOKEN"),
126
  api_endpoint=os.environ.get("ASTRA_DB_API_ENDPOINT"),
127
  )
128
+ user_session = session_id(state, request)
129
  session_data = {
130
  'user' : state["user"],
131
  'session' : request.session_hash,
 
152
 
153
  def add_history(state, request, type, message):
154
  if not state["history"]:
155
+ session = session_id(state, request)
156
  state["history"] = AstraDBChatMessageHistory(
157
  session_id=session,
158
  collection_name=f'{os.environ.get("ASTRA_DB_COLLECTION")}_chat_history',