Skip to content

Commit b75f228

Browse files
simplified the logic
1 parent 826c412 commit b75f228

1 file changed

Lines changed: 0 additions & 44 deletions

File tree

deepeval/benchmarks/gsm8k/gsm8k.py

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,6 @@ def _extract_prediction_from_response(self, res) -> str:
132132
elif isinstance(res, tuple):
133133
return self._extract_from_tuple(res)
134134

135-
# Case 3: Response is a string
136-
elif isinstance(res, str):
137-
return res
138-
139-
# Case 4: Response has .text or .content attribute
140-
elif hasattr(res, 'text'):
141-
return str(res.text)
142-
elif hasattr(res, 'content'):
143-
return str(res.content)
144-
145-
# Case 5: Response is a dict
146-
elif isinstance(res, dict):
147-
return self._extract_from_dict(res)
148-
149-
# Case 6: Fallback - convert to string
150135
else:
151136
return str(res)
152137

@@ -155,37 +140,8 @@ def _extract_from_tuple(self, res: tuple) -> str:
155140
if len(res) == 0:
156141
return ""
157142
first_elem = res[0]
158-
159143
if hasattr(first_elem, 'answer'):
160144
return str(first_elem.answer)
161-
elif hasattr(first_elem, 'text'):
162-
return str(first_elem.text)
163-
elif hasattr(first_elem, 'content'):
164-
return str(first_elem.content)
165-
elif len(res) > 1 and res[1] is not None:
166-
second_elem = res[1]
167-
if hasattr(second_elem, 'answer'):
168-
return str(second_elem.answer)
169-
else:
170-
return str(second_elem)
171-
172-
else:
173-
return str(first_elem)
174-
175-
def _extract_from_dict(self, res: dict) -> str:
176-
"""Extract prediction from dictionary response."""
177-
# Common keys that might contain the answer
178-
possible_keys = ['answer', 'text', 'content', 'response', 'output', 'result']
179-
180-
for key in possible_keys:
181-
if key in res:
182-
return str(res[key])
183-
184-
for value in res.values():
185-
if value is not None and str(value).strip():
186-
return str(value)
187-
188-
return str(res)
189145

190146
def load_benchmark_dataset(self) -> List[Golden]:
191147
from datasets import load_dataset

0 commit comments

Comments
 (0)