Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made litellm judge backend more robust. #485

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/lighteval/metrics/llm_as_judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from tqdm import tqdm

from lighteval.models.model_output import ModelResponse
from lighteval.utils.imports import is_litellm_available, is_openai_available, is_vllm_available


Expand Down Expand Up @@ -195,20 +196,28 @@ def __call_litellm(self, prompts):
def __call_api(prompt):
for _ in range(self.API_MAX_RETRY):
try:
response = litellm.completion(
model=self.model,
messages=prompt,
response_format={"type": "text"},
max_tokens=512,
n=1,
caching=True,
)
kwargs = {
"model": self.model,
"messages": prompt,
"response_format": {"type": "text"},
"max_tokens": 512,
"n": 1,
"caching": True,
}
response = litellm.completion(**kwargs)
text = response.choices[0].message.content
if text is None:
kwargs["caching"] = False
response = litellm.completion(**kwargs)
text = response.choices[0].message.content
if text is None:
# Just return an error response if the second attempt fails too
return ModelResponse(text="Failed to get response from the API.", model=self.model)
clefourrier marked this conversation as resolved.
Show resolved Hide resolved
return text
except Exception as e:
logger.warning(f"{type(e), e}")
time.sleep(self.API_RETRY_SLEEP)
raise Exception("Failed to get response from the API")
return ModelResponse(text="Failed to get response from the API.", model=self.model)

results = []
with ThreadPoolExecutor(100) as executor:
Expand Down