botsi commited on
Commit
36cb3bb
·
verified ·
1 Parent(s): 0a20152

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -18
app.py CHANGED
@@ -1,4 +1,4 @@
1
- # Changed now everyting from session_index to PROLIFIC_PID
2
 
3
  # Original code from https://huggingface.co/spaces/huggingface-projects/llama-2-7b-chat
4
  # Modified for trust game purposes
@@ -87,7 +87,7 @@ if torch.cuda.is_available():
87
  tokenizer.use_default_system_prompt = False
88
 
89
 
90
- def fetch_personalized_data(PROLIFIC_PID):
91
  try:
92
  # Connect to the database
93
  with mysql.connector.connect(
@@ -98,14 +98,14 @@ def fetch_personalized_data(PROLIFIC_PID):
98
  ) as conn:
99
  # Create a cursor object
100
  with conn.cursor() as cursor:
101
- # Query to fetch relevant data from both tables based on PROLIFIC_PID
102
  query = """
103
  SELECT e5390g37623_core.playerNr,
104
  e5390g37623_core.groupNrStart,
105
  e5390g37623_core.subjectNr,
106
  e5390g37623_core.onPage,
107
  e5390g37623_core.role,
108
- e5390g37623_session.PROLIFIC_PID,
109
  e5390g37623_decisions.transfer1,
110
  e5390g37623_decisions.tripledAmount1,
111
  e5390g37623_decisions.keptForSelf1,
@@ -126,14 +126,14 @@ def fetch_personalized_data(PROLIFIC_PID):
126
  e5390g37623_core.playerNr = e5390g37623_session.playerNr
127
  JOIN e5390g37623_decisions ON
128
  e5390g37623_core.playerNr = e5390g37623_decisions.playerNr
129
- WHERE e5390g37623_session.PROLIFIC_PID = %s
130
  UNION ALL
131
  SELECT e5390g37623_core.playerNr,
132
  e5390g37623_core.groupNrStart,
133
  e5390g37623_core.subjectNr,
134
  e5390g37623_core.onPage,
135
  e5390g37623_core.role,
136
- e5390g37623_session.PROLIFIC_PID,
137
  e5390g37623_decisions.transfer1,
138
  e5390g37623_decisions.tripledAmount1,
139
  e5390g37623_decisions.keptForSelf1,
@@ -159,10 +159,10 @@ def fetch_personalized_data(PROLIFIC_PID):
159
  FROM e5390g37623_core
160
  JOIN e5390g37623_session
161
  ON e5390g37623_core.playerNr = e5390g37623_session.playerNr
162
- WHERE e5390g37623_session.PROLIFIC_PID = %s
163
- ) AND e5390g37623_session.PROLIFIC_PID != %s
164
  """
165
- cursor.execute(query,(PROLIFIC_PID, PROLIFIC_PID, PROLIFIC_PID))
166
  # Fetch data row by row
167
  data = [{
168
  'playerNr': row[0],
@@ -170,7 +170,7 @@ def fetch_personalized_data(PROLIFIC_PID):
170
  'subjectNr': row[2],
171
  'onPage': row[3],
172
  'role': row[4], # Include the role here
173
- 'PROLIFIC_PID': row[5],
174
  'transfer1': row[6],
175
  'tripledAmount1': row[7],
176
  'keptForSelf1': row[8],
@@ -281,18 +281,18 @@ def generate(
281
  #print(params)
282
 
283
  # Assuming params = request.query_params is the dictionary containing the query parameters
284
- # Extract the value of the 'PROLIFIC_PID' parameter
285
- PROLIFIC_PID = params.get('PROLIFIC_PID')
286
 
287
- # Check if PROLIFIC_PID_value is None or contains a value
288
  if PROLIFIC_PID is not None:
289
- print("Session index:", PROLIFIC_PID)
290
  else:
291
  PROLIFIC_PID = 'no_PROLIFIC_PID'
292
- print("Session index not found or has no value.")
293
 
294
  # Fetch personalized data
295
- personalized_data = fetch_personalized_data(PROLIFIC_PID)
296
 
297
  # Construct the input prompt using the functions from the system_prompt_config module
298
  input_prompt = construct_input_prompt(chat_history, message, personalized_data)
@@ -359,8 +359,8 @@ def generate(
359
  # Iterate over each dictionary in the list
360
  if personalized_data:
361
  for entry in personalized_data:
362
- # Check if the PROLIFIC_PID matches the value in PROLIFIC_PID variable
363
- if entry['PROLIFIC_PID'] == PROLIFIC_PID:
364
  onPage = entry.get('onPage', "no_onPage") # Retrieve onPage value
365
  playerNr = entry.get('playerNr', "no_playerNr") # Retrieve playerNr value
366
  groupNrStart = entry.get('groupNrStart', "groupNrStart") # Retrieve groupNrStart value
 
1
+ # Changed now everyting from session_index to externalID
2
 
3
  # Original code from https://huggingface.co/spaces/huggingface-projects/llama-2-7b-chat
4
  # Modified for trust game purposes
 
87
  tokenizer.use_default_system_prompt = False
88
 
89
 
90
+ def fetch_personalized_data(externalID):
91
  try:
92
  # Connect to the database
93
  with mysql.connector.connect(
 
98
  ) as conn:
99
  # Create a cursor object
100
  with conn.cursor() as cursor:
101
+ # Query to fetch relevant data from both tables based on externalID = PROLIFIC_PID
102
  query = """
103
  SELECT e5390g37623_core.playerNr,
104
  e5390g37623_core.groupNrStart,
105
  e5390g37623_core.subjectNr,
106
  e5390g37623_core.onPage,
107
  e5390g37623_core.role,
108
+ e5390g37623_session.externalID,
109
  e5390g37623_decisions.transfer1,
110
  e5390g37623_decisions.tripledAmount1,
111
  e5390g37623_decisions.keptForSelf1,
 
126
  e5390g37623_core.playerNr = e5390g37623_session.playerNr
127
  JOIN e5390g37623_decisions ON
128
  e5390g37623_core.playerNr = e5390g37623_decisions.playerNr
129
+ WHERE e5390g37623_session.externalID = %s
130
  UNION ALL
131
  SELECT e5390g37623_core.playerNr,
132
  e5390g37623_core.groupNrStart,
133
  e5390g37623_core.subjectNr,
134
  e5390g37623_core.onPage,
135
  e5390g37623_core.role,
136
+ e5390g37623_session.externalID,
137
  e5390g37623_decisions.transfer1,
138
  e5390g37623_decisions.tripledAmount1,
139
  e5390g37623_decisions.keptForSelf1,
 
159
  FROM e5390g37623_core
160
  JOIN e5390g37623_session
161
  ON e5390g37623_core.playerNr = e5390g37623_session.playerNr
162
+ WHERE e5390g37623_session.externalID = %s
163
+ ) AND e5390g37623_session.externalID != %s
164
  """
165
+ cursor.execute(query,(externalID, externalID, externalID))
166
  # Fetch data row by row
167
  data = [{
168
  'playerNr': row[0],
 
170
  'subjectNr': row[2],
171
  'onPage': row[3],
172
  'role': row[4], # Include the role here
173
+ 'externalID': row[5],
174
  'transfer1': row[6],
175
  'tripledAmount1': row[7],
176
  'keptForSelf1': row[8],
 
281
  #print(params)
282
 
283
  # Assuming params = request.query_params is the dictionary containing the query parameters
284
+ # Extract the value of the 'externalID' parameter = PROLIFIC_PID
285
+ PROLIFIC_PID = params.get('externalID')
286
 
287
+ # Check if PROLIFIC_PID value is None or contains a value
288
  if PROLIFIC_PID is not None:
289
+ print("PROLIFIC_PID:", PROLIFIC_PID)
290
  else:
291
  PROLIFIC_PID = 'no_PROLIFIC_PID'
292
+ print("PROLIFIC_PID not found or has no value.")
293
 
294
  # Fetch personalized data
295
+ personalized_data = fetch_personalized_data(externalID)
296
 
297
  # Construct the input prompt using the functions from the system_prompt_config module
298
  input_prompt = construct_input_prompt(chat_history, message, personalized_data)
 
359
  # Iterate over each dictionary in the list
360
  if personalized_data:
361
  for entry in personalized_data:
362
+ # Check if the externalID matches the value in externalID variable
363
+ if entry['externalID'] == PROLIFIC_PID:
364
  onPage = entry.get('onPage', "no_onPage") # Retrieve onPage value
365
  playerNr = entry.get('playerNr', "no_playerNr") # Retrieve playerNr value
366
  groupNrStart = entry.get('groupNrStart', "groupNrStart") # Retrieve groupNrStart value