buzzCraft commited on
Commit
681cecd
·
1 Parent(s): 5aaced9

Added few_shot to .env

Browse files
Files changed (2) hide show
  1. .env_demo +1 -0
  2. src/extractor.py +24 -17
.env_demo CHANGED
@@ -4,3 +4,4 @@ DATABASE_PATH = data/gamess.db
4
  LANGSMITH = False
5
  LANGSMITH_API_KEY=
6
  LANGSMITH_PROJECT=SoccerRag
 
 
4
  LANGSMITH = False
5
  LANGSMITH_API_KEY=
6
  LANGSMITH_PROJECT=SoccerRag
7
+ FEW_SHOT = 3
src/extractor.py CHANGED
@@ -36,6 +36,8 @@ if os.getenv('LANGSMITH'):
36
  db_uri = os.getenv('DATABASE_PATH')
37
  db_uri = f"sqlite:///{db_uri}"
38
  db = SQLDatabase.from_uri(db_uri)
 
 
39
 
40
 
41
  # from langchain_anthropic import ChatAnthropic
@@ -220,28 +222,30 @@ def extract_properties(prompt, schema_config, custom_extractor_prompt=None):
220
  return None
221
 
222
 
223
- def recheck_property_value(properties, property_name, retrievers, input_func):
224
  while True:
225
- new_value = input_func(f"Enter new value for {property_name} or type 'quit' to stop: ")
 
226
  if new_value.lower() == 'quit':
227
  break # Exit the loop and do not update the property
228
 
229
- new_top_matches = retrievers[property_name].find_close_matches(new_value, n=3)
 
230
  if new_top_matches:
231
  # Display new top matches and ask for confirmation or re-entry
232
  print("\nNew close matches found:")
233
  for i, match in enumerate(new_top_matches, start=1):
234
  print(f"[{i}] {match}")
235
- print("[4] Re-enter value")
236
- print("[5] Quit without updating")
237
 
238
- selection = input_func("Select the best match (1-3), choose 4 to re-enter value, or 5 to quit: ")
239
- if selection in ['1', '2', '3']:
240
  selected_match = new_top_matches[int(selection) - 1]
241
  properties[property_name] = selected_match # Update the dictionary directly
242
  print(f"Updated {property_name} to {selected_match}")
243
  break # Successfully updated, exit the loop
244
- elif selection == '5':
245
  break # Quit without updating
246
  # Loop will continue if user selects 4 or inputs invalid selection
247
  else:
@@ -280,10 +284,11 @@ def check_and_update_properties(properties_list, retrievers, method="fuzzy", inp
280
  updated_property_values.append(augmented_value)
281
  continue
282
  # Since property_value is now expected to be a list, we handle each value individually
283
- if input_func == "chainlit":
284
- n = 5
285
- else:
286
- n = 3
 
287
  top_matches = retriever.find_close_matches(value, method=method, n=n)
288
 
289
  # Check if the closest match is the same as the current value
@@ -305,18 +310,20 @@ def check_and_update_properties(properties_list, retrievers, method="fuzzy", inp
305
  print(f"\nCurrent {property_name}: {value}")
306
  for i, match in enumerate(top_matches, start=1):
307
  print(f"[{i}] {match}")
308
- print("[4] Enter new value")
 
309
 
310
  # hmm = input(f"Fix for Pycharm, press enter to continue")
311
 
312
- choice = input(f"Select the best match for {property_name} (1-4): ")
313
- if choice in ['1', '2', '3']:
 
314
  selected_match = top_matches[int(choice) - 1]
315
  updated_property_values.append(selected_match) # Update with the selected match
316
  print(f"Updated {property_name} to {selected_match}")
317
- elif choice == '4':
318
  # Allow re-entry of value for this specific item
319
- recheck_property_value(properties, property_name, value, retrievers, input_func)
320
  # Note: Implement recheck_property_value to handle individual value updates within the list
321
  else:
322
  print("Invalid selection. Property not updated.")
 
36
  db_uri = os.getenv('DATABASE_PATH')
37
  db_uri = f"sqlite:///{db_uri}"
38
  db = SQLDatabase.from_uri(db_uri)
39
+ few_shot_n = os.getenv('FEW_SHOT')
40
+ few_shot_n = int(few_shot_n)
41
 
42
 
43
  # from langchain_anthropic import ChatAnthropic
 
222
  return None
223
 
224
 
225
+ def recheck_property_value(properties, property_name, value, retrievers):
226
  while True:
227
+ print(property_name)
228
+ new_value = input(f"Enter new value for {property_name} - {value} or type 'quit' to stop: ")
229
  if new_value.lower() == 'quit':
230
  break # Exit the loop and do not update the property
231
 
232
+
233
+ new_top_matches = retrievers.find_close_matches(new_value, n=few_shot_n)
234
  if new_top_matches:
235
  # Display new top matches and ask for confirmation or re-entry
236
  print("\nNew close matches found:")
237
  for i, match in enumerate(new_top_matches, start=1):
238
  print(f"[{i}] {match}")
239
+ print(f"[{i+1}] Re-enter value")
240
+ print(f"[{i+2}] Quit without updating")
241
 
242
+ selection = input(f"Select the best match (1-{i}), choose {i+1} to re-enter value, or {i+2} to quit: ")
243
+ if selection in [str(i) for i in range(1, i + 1)]:
244
  selected_match = new_top_matches[int(selection) - 1]
245
  properties[property_name] = selected_match # Update the dictionary directly
246
  print(f"Updated {property_name} to {selected_match}")
247
  break # Successfully updated, exit the loop
248
+ elif selection == f'{i+2}':
249
  break # Quit without updating
250
  # Loop will continue if user selects 4 or inputs invalid selection
251
  else:
 
284
  updated_property_values.append(augmented_value)
285
  continue
286
  # Since property_value is now expected to be a list, we handle each value individually
287
+ n = few_shot_n
288
+ # if input_func == "chainlit":
289
+ # n = 5
290
+ # else:
291
+ # n = 3
292
  top_matches = retriever.find_close_matches(value, method=method, n=n)
293
 
294
  # Check if the closest match is the same as the current value
 
310
  print(f"\nCurrent {property_name}: {value}")
311
  for i, match in enumerate(top_matches, start=1):
312
  print(f"[{i}] {match}")
313
+
314
+ print(f"[{i+1}] Enter new value")
315
 
316
  # hmm = input(f"Fix for Pycharm, press enter to continue")
317
 
318
+ choice = input(f"Select the best match for {property_name} (1-{i+1}): ")
319
+ # if choice == in range(1, i)
320
+ if choice in [str(i) for i in range(1, i+1)]:
321
  selected_match = top_matches[int(choice) - 1]
322
  updated_property_values.append(selected_match) # Update with the selected match
323
  print(f"Updated {property_name} to {selected_match}")
324
+ elif choice == f'{i+1}':
325
  # Allow re-entry of value for this specific item
326
+ recheck_property_value(properties, property_name, value, retriever)
327
  # Note: Implement recheck_property_value to handle individual value updates within the list
328
  else:
329
  print("Invalid selection. Property not updated.")