Spaces:
Sleeping
Sleeping
buzzCraft
commited on
Commit
·
681cecd
1
Parent(s):
5aaced9
Added few_shot to .env
Browse files- .env_demo +1 -0
- 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,
|
224 |
while True:
|
225 |
-
|
|
|
226 |
if new_value.lower() == 'quit':
|
227 |
break # Exit the loop and do not update the property
|
228 |
|
229 |
-
|
|
|
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("[
|
236 |
-
print("[
|
237 |
|
238 |
-
selection =
|
239 |
-
if selection in [
|
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 == '
|
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 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
|
|
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 |
-
|
|
|
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-
|
313 |
-
if choice in
|
|
|
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 == '
|
318 |
# Allow re-entry of value for this specific item
|
319 |
-
recheck_property_value(properties, property_name, value,
|
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.")
|