Skip to content

Commit

Permalink
Fix IndexError in LLM Reranking when handling malformed LLM responses (
Browse files Browse the repository at this point in the history
…#17353)

* Fix bug #17352 by catching errors for malformed LLM responses

* Fix formatting
  • Loading branch information
okirmis authored Dec 26, 2024
1 parent 1262e6b commit 2c85e1c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 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,20 @@ 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 2c85e1c

Please # to comment.