Spaces:
Sleeping
Sleeping
Create workflow_conditions.py
Browse files- workflow_conditions.py +31 -0
workflow_conditions.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict
|
| 2 |
+
from config import config
|
| 3 |
+
|
| 4 |
+
def should_continue_groundedness(state: Dict) -> str:
|
| 5 |
+
"""Decides if groundedness is sufficient or needs improvement."""
|
| 6 |
+
print("---------should_continue_groundedness---------")
|
| 7 |
+
print("groundedness loop count: ", state['groundedness_loop_count'])
|
| 8 |
+
|
| 9 |
+
if state['groundedness_score'] >= config.GROUNDEDNESS_THRESHOLD:
|
| 10 |
+
print("Moving to precision")
|
| 11 |
+
return "check_precision"
|
| 12 |
+
else:
|
| 13 |
+
if state["groundedness_loop_count"] > state['loop_max_iter']:
|
| 14 |
+
return "max_iterations_reached"
|
| 15 |
+
else:
|
| 16 |
+
print(f"---------Groundedness Score Threshold Not met. Refining Response-----------")
|
| 17 |
+
return "refine_response"
|
| 18 |
+
|
| 19 |
+
def should_continue_precision(state: Dict) -> str:
|
| 20 |
+
"""Decides if precision is sufficient or needs improvement."""
|
| 21 |
+
print("---------should_continue_precision---------")
|
| 22 |
+
print("precision loop count: ", state['precision_loop_count'])
|
| 23 |
+
|
| 24 |
+
if state['precision_score'] >= config.PRECISION_THRESHOLD:
|
| 25 |
+
return "pass"
|
| 26 |
+
else:
|
| 27 |
+
if state['precision_loop_count'] > state['loop_max_iter']:
|
| 28 |
+
return "max_iterations_reached"
|
| 29 |
+
else:
|
| 30 |
+
print(f"---------Precision Score Threshold Not met. Refining Query-----------")
|
| 31 |
+
return "refine_query"
|