in lmms_eval/tasks/mathvista/mathvista_evals.py [0:0]
def get_chat_response(self, prompt, temperature=0, max_tokens=256, n=1, patience=10000000, sleep_time=0):
messages = [
{"role": "user", "content": prompt},
]
payload = {"model": self.gpt_model, "messages": messages, "temperature": temperature, "max_tokens": max_tokens, "n": n}
while patience > 0:
patience -= 1
try:
response = self._post_request(payload)
if n == 1:
prediction = response["choices"][0]["message"]["content"].strip()
if prediction and prediction != "":
return prediction
else:
prediction = [choice["message"]["content"].strip() for choice in response["choices"]]
if prediction and prediction[0] != "":
return prediction
except Exception as e:
if "Rate limit" not in str(e):
eval_logger.error(e)
if "Please reduce the length of the messages" in str(e):
eval_logger.error("!!Reduce prompt size")
# reduce input prompt and keep the tail
new_size = int(len(prompt) * 0.9)
new_start = len(prompt) - new_size
prompt = prompt[new_start:]
payload["messages"] = [
{"role": "user", "content": prompt},
]
if sleep_time > 0:
time.sleep(sleep_time)
return ""