Spaces:
Runtime error
Runtime error
Update RAG_utils.py
Browse files- RAG_utils.py +9 -4
RAG_utils.py
CHANGED
@@ -166,7 +166,7 @@ class base_utils:
|
|
166 |
@staticmethod
|
167 |
def extract_score_reasoning(text: str) -> Dict[str, Optional[str]]:
|
168 |
"""
|
169 |
-
Extracts score and reasoning from a given text using regular expressions.
|
170 |
|
171 |
Args:
|
172 |
text (str): The text from which to extract the score and reasoning.
|
@@ -178,14 +178,19 @@ class base_utils:
|
|
178 |
score_pattern = r"Score: (\d+)"
|
179 |
reasoning_pattern = r"Reasoning: (\S.+)"
|
180 |
|
181 |
-
# Extract
|
182 |
score_match = re.search(score_pattern, text)
|
183 |
-
reasoning_match = re.search(reasoning_pattern, text, re.DOTALL) # re.DOTALL allows '.' to match newlines
|
184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
# Extract and return the results
|
186 |
extracted_data = {
|
187 |
"score": score_match.group(1) if score_match else None,
|
188 |
-
"reasoning":
|
189 |
}
|
190 |
|
191 |
return extracted_data
|
|
|
166 |
@staticmethod
|
167 |
def extract_score_reasoning(text: str) -> Dict[str, Optional[str]]:
|
168 |
"""
|
169 |
+
Extracts score and the longest reasoning from a given text using regular expressions.
|
170 |
|
171 |
Args:
|
172 |
text (str): The text from which to extract the score and reasoning.
|
|
|
178 |
score_pattern = r"Score: (\d+)"
|
179 |
reasoning_pattern = r"Reasoning: (\S.+)"
|
180 |
|
181 |
+
# Extract score using regular expressions
|
182 |
score_match = re.search(score_pattern, text)
|
|
|
183 |
|
184 |
+
# Extract all reasoning matches
|
185 |
+
reasoning_matches = re.findall(reasoning_pattern, text, re.DOTALL)
|
186 |
+
|
187 |
+
# Find the longest reasoning match
|
188 |
+
longest_reasoning = max(reasoning_matches, key=len) if reasoning_matches else None
|
189 |
+
|
190 |
# Extract and return the results
|
191 |
extracted_data = {
|
192 |
"score": score_match.group(1) if score_match else None,
|
193 |
+
"reasoning": longest_reasoning.strip() if longest_reasoning else None
|
194 |
}
|
195 |
|
196 |
return extracted_data
|