in lmms_eval/tasks/ferret/utils.py [0:0]
def get_eval(content: str, max_tokens: int, retries: int = 3):
global headers
messages = [
{
"role": "system",
"content": "You are a helpful and precise assistant for checking the quality of the answer.",
},
{"role": "user", "content": content},
]
payload = {
"model": GPT_EVAL_MODEL_NAME,
"messages": messages,
"temperature": 0.2,
"max_tokens": max_tokens,
}
for attempt in range(retries):
try:
response = requests.post(API_URL, headers=headers, json=payload)
response.raise_for_status()
response_data = response.json()
content = response_data["choices"][0]["message"]["content"].strip()
if content != "":
return content, response_data["model"]
break # If successful, break out of the loop
except Exception as e:
eval_logger.info(f"Attempt {attempt + 1} failed with error: {e}")
if attempt < retries - 1: # If we have retries left, sleep and then continue to next attempt
time.sleep(NUM_SECONDS_TO_SLEEP)
else: # If this was the last attempt, log and return empty
eval_logger.error(f"All {retries} attempts failed. Last error message: {e}")
return "", ""
return "", ""