Skip to content

Commit

Permalink
Wrap LLM judge in retry logic
Browse files Browse the repository at this point in the history
Reviewed By: SimonWan

Differential Revision: D66671973

fbshipit-source-id: c98d50e0fe02d9e45dec477688deccb0bb8a2814
  • Loading branch information
onionymous authored and facebook-github-bot committed Dec 2, 2024
1 parent 1551cbf commit 0884335
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ async def run(self, num_test_cases: int = 0, run_llm_in_parallel: int = 16) -> N
judge_response_result = query_llm_to_generate_responses(
{"judge_llm": self.judge_llm},
self.response_path,
run_llm_in_parallel,
4,
to_process_prompt=self._process_prompt_for_judge,
enumerate_prompt_and_pass_id=False,
num_test_cases=num_test_cases,
Expand Down Expand Up @@ -248,11 +248,14 @@ def _process_prompt_for_judge(
if not judge_llm:
raise ValueError("Judge LLM must be specified.")

judge_response = judge_llm.query_with_retries(
prompt=JUDGE_PROMPT.format(
llm_response=response, question=judge_question
),
)
while True:
judge_response = judge_llm.query_with_retries(
prompt=JUDGE_PROMPT.format(
llm_response=response, question=judge_question
),
)
if judge_response.lower().strip(".") in {"yes", "no"}:
break

judge_result = {
"prompt_id": prompt_id,
Expand Down

0 comments on commit 0884335

Please sign in to comment.