liyaoshi commited on
Commit
8a55776
1 Parent(s): 884590f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -3
app.py CHANGED
@@ -54,9 +54,9 @@ def get_supabase_client():
54
  supabase = create_client(url, key)
55
  return supabase
56
 
57
- def supabase_insert_message(user_message,response_content,messages,response_data,user_name,user_oauth_token,ip,sign):
58
  supabase = get_supabase_client()
59
- data, count = supabase.table('messages').insert({"user_message": user_message, "response_content": response_content,"messages":messages,"response":response_data,"user_name":user_name,"user_oauth_token":user_oauth_token,"ip":ip,"sign":sign}).execute()
60
 
61
  def supabase_insert_user(name,user_name,profile,picture,oauth_token):
62
  supabase = get_supabase_client()
@@ -107,6 +107,21 @@ def get_completion(message,history,profile: gr.OAuthProfile | None,oauth_token:
107
  ip = request.client.host
108
  print("Query parameters:", dict(request.query_params))
109
  sign = dict(request.query_params).get('__sign')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
  # check login
112
  if profile is None:
@@ -204,7 +219,7 @@ def get_completion(message,history,profile: gr.OAuthProfile | None,oauth_token:
204
  response_content = response_data['choices'][0]['message']['content']
205
  usage = response_data['usage']
206
 
207
- supabase_insert_message(user_message,response_content,messages,response_data,user_name,user_oauth_token,ip,sign)
208
 
209
  return response_content
210
 
 
54
  supabase = create_client(url, key)
55
  return supabase
56
 
57
+ def supabase_insert_message(user_message,response_content,messages,response_data,user_name,user_oauth_token,ip,sign,cookie_value):
58
  supabase = get_supabase_client()
59
+ data, count = supabase.table('messages').insert({"user_message": user_message, "response_content": response_content,"messages":messages,"response":response_data,"user_name":user_name,"user_oauth_token":user_oauth_token,"ip":ip,"sign":sign,"cookie":cookie_value}).execute()
60
 
61
  def supabase_insert_user(name,user_name,profile,picture,oauth_token):
62
  supabase = get_supabase_client()
 
107
  ip = request.client.host
108
  print("Query parameters:", dict(request.query_params))
109
  sign = dict(request.query_params).get('__sign')
110
+
111
+ # get cookie
112
+ headers = request.headers.raw
113
+
114
+ # find 'cookie'
115
+ cookie_header = next((header for header in headers if header[0] == b'cookie'), None)
116
+
117
+ if cookie_header:
118
+ # extract cookie
119
+ cookie_value = cookie_header[1].decode()
120
+ print(f"Cookie: {cookie_value}")
121
+ else:
122
+ cookie_value = ''
123
+ print("No cookie found in request headers")
124
+
125
 
126
  # check login
127
  if profile is None:
 
219
  response_content = response_data['choices'][0]['message']['content']
220
  usage = response_data['usage']
221
 
222
+ supabase_insert_message(user_message,response_content,messages,response_data,user_name,user_oauth_token,ip,sign,cookie_value)
223
 
224
  return response_content
225