Skip to content

Commit

Permalink
Fix bug #17352 by catching errors for malformed LLM responses
Browse files Browse the repository at this point in the history
  • Loading branch information
okirmis authored Dec 22, 2024
1 parent 4b50ce8 commit bf5af4f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions llama-index-core/llama_index/core/indices/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,18 @@ def default_parse_choice_select_answer_fn(
continue
answer_nums.append(answer_num)
# extract just the first digits after the colon.
_answer_relevance = re.findall(r"\d+", line_tokens[1].split(":")[1].strip())[0]
answer_relevances.append(float(_answer_relevance))
try:
_answer_relevance = re.findall(r"\d+", line_tokens[1].split(":")[1].strip())[0]
answer_relevances.append(float(_answer_relevance))
except (IndexError, ValueError) as e:
if not raise_error:
continue
else:
raise ValueError(
f"Invalid answer line: {answer_line}. "
"Answer line must be of the form: "
"answer_num: <int>, answer_relevance: <float>"
)
return answer_nums, answer_relevances


Expand Down

0 comments on commit bf5af4f

Please sign in to comment.