Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
lm-evaluation-harness
Commits
e49972b0
Commit
e49972b0
authored
Aug 04, 2023
by
haileyschoelkopf
Browse files
make AnthropicLM class still registered when missing anthropic extra
parent
fa2d592a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
9 deletions
+21
-9
lm_eval/models/__init__.py
lm_eval/models/__init__.py
+1
-5
lm_eval/models/anthropic_llms.py
lm_eval/models/anthropic_llms.py
+20
-4
No files found.
lm_eval/models/__init__.py
View file @
e49972b0
...
...
@@ -2,11 +2,7 @@ from . import huggingface
from
.
import
openai_completions
from
.
import
textsynth
from
.
import
dummy
from
.
import
anthropic_llms
try
:
import
anthropic
from
.
import
anthropic_llms
except
Exception
:
raise
"anthropic library is not yet installed"
# TODO: implement __all__
lm_eval/models/anthropic_llms.py
View file @
e49972b0
...
...
@@ -3,13 +3,12 @@ from lm_eval.api.model import LM
from
lm_eval.api.registry
import
register_model
from
tqdm
import
tqdm
import
time
import
anthropic
from
lm_eval.logger
import
eval_logger
from
typing
import
List
,
Literal
,
Any
def
anthropic_completion
(
client
:
anthropic
.
Anthropic
,
client
,
#
: anthropic.Anthropic,
model
:
str
,
prompt
:
str
,
max_tokens_to_sample
:
int
,
...
...
@@ -21,6 +20,15 @@ def anthropic_completion(
Retry with back-off until they respond
"""
try
:
import
anthropic
except
ModuleNotFoundError
:
raise
Exception
(
"attempted to use 'anthropic' LM type, but package `anthropic` is not installed.
\
please install anthropic via `pip install lm-eval[anthropic]` or `pip install -e .[anthropic]`"
,
)
backoff_time
=
3
while
True
:
try
:
...
...
@@ -68,6 +76,14 @@ class AnthropicLM(LM):
"""
super
().
__init__
()
try
:
import
anthropic
except
ModuleNotFoundError
:
raise
Exception
(
"attempted to use 'anthropic' LM type, but package `anthropic` is not installed.
\
please install anthropic via `pip install lm-eval[anthropic]` or `pip install -e .[anthropic]`"
,
)
self
.
model
=
model
# defaults to os.environ.get("ANTHROPIC_API_KEY")
self
.
client
=
anthropic
.
Anthropic
()
...
...
@@ -135,10 +151,10 @@ class AnthropicLM(LM):
res
.
append
(
response
)
self
.
cache_hook
.
add_partial
(
"greedy_until"
,
request
,
response
)
except
anthropic
.
APIConnectionError
as
e
:
except
anthropic
.
APIConnectionError
as
e
:
# noqa: F821
eval_logger
.
critical
(
f
"Server unreachable:
{
e
.
__cause__
}
"
)
break
except
anthropic
.
APIStatusError
as
e
:
except
anthropic
.
APIStatusError
as
e
:
# noqa: F821
eval_logger
.
critical
(
f
"API error
{
e
.
status_code
}
:
{
e
.
message
}
"
)
break
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment