Skip to content

Commit f2246ba

Browse files
Vamshi AdimallaVamshi Adimalla
authored andcommitted
Restricted response to tuple or NumberSchema. If response incompatible, add confinement instruction
1 parent c0b09fa commit f2246ba

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

deepeval/benchmarks/gsm8k/gsm8k.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Optional, Dict
1+
from typing import List, Optional, Dict, Union, Tuple, Any
22
from tqdm import tqdm
33

44
from deepeval.dataset import Golden
@@ -95,11 +95,19 @@ def predict(self, model: DeepEvalBaseLLM, golden: Golden) -> Dict:
9595

9696
# Enforced model generation
9797
try:
98-
res: NumberSchema = model.generate(
98+
res: Union[NumberSchema, Tuple[Any]] = model.generate(
9999
prompt=prompt, schema=NumberSchema
100100
)
101-
prediction = str(res.answer)
102-
except TypeError:
101+
if isinstance(res, tuple):
102+
if len(res) == 1:
103+
res = res[0]
104+
else:
105+
raise TypeError
106+
elif isinstance(res, NumberSchema):
107+
prediction = str(res.answer)
108+
else:
109+
raise TypeError # Much eaiser to just add confinement instructions
110+
except (TypeError, AttributeError):
103111
prompt += f"\n\n{self.confinement_instructions}"
104112
prediction = model.generate(prompt)
105113

0 commit comments

Comments
 (0)