Commit b8510001 authored by baberabb's avatar baberabb
Browse files

fixed error handling

parent 3a3655d6
...@@ -41,12 +41,6 @@ def anthropic_completion( ...@@ -41,12 +41,6 @@ def anthropic_completion(
) )
time.sleep(backoff_time) time.sleep(backoff_time)
backoff_time *= 1.5 backoff_time *= 1.5
except anthropic.APIConnectionError as e:
eval_logger.critical(f"Server unreachable: {e.__cause__}")
break
except anthropic.APIStatusError as e:
eval_logger.critical(f"API error {e.status_code}: {e.message}")
break
@register_model("anthropic") @register_model("anthropic")
...@@ -122,21 +116,28 @@ class AnthropicLM(LM): ...@@ -122,21 +116,28 @@ class AnthropicLM(LM):
res = [] res = []
for request in tqdm(requests): for request in tqdm(requests):
inp = request[0] try:
request_args = request[1] inp = request[0]
until = request_args["until"] request_args = request[1]
response = anthropic_completion( until = request_args["until"]
client=self.client, response = anthropic_completion(
model=self.model, client=self.client,
prompt=inp, model=self.model,
max_tokens_to_sample=self.max_tokens_to_sample, prompt=inp,
temperature=self.temperature, # TODO: implement non-greedy sampling for Anthropic max_tokens_to_sample=self.max_tokens_to_sample,
stop=until, temperature=self.temperature, # TODO: implement non-greedy sampling for Anthropic
**self.kwargs, stop=until,
) **self.kwargs,
res.append(response) )
res.append(response)
self.cache_hook.add_partial("greedy_until", request, response)
self.cache_hook.add_partial("greedy_until", request, response)
except anthropic.APIConnectionError as e:
eval_logger.critical(f"Server unreachable: {e.__cause__}")
break
except anthropic.APIStatusError as e:
eval_logger.critical(f"API error {e.status_code}: {e.message}")
break
return res return res
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment