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
5a49b2a3
Unverified
Commit
5a49b2a3
authored
Aug 06, 2023
by
Hailey Schoelkopf
Committed by
GitHub
Aug 06, 2023
Browse files
Merge pull request #738 from baberabb/master_anthropic
[Main] updated to new anthropic API
parents
fe803c29
d504944b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
5 deletions
+8
-5
lm_eval/models/anthropic_llms.py
lm_eval/models/anthropic_llms.py
+8
-5
No files found.
lm_eval/models/anthropic_llms.py
View file @
5a49b2a3
...
...
@@ -4,7 +4,9 @@ from tqdm import tqdm
import
time
def
anthropic_completion
(
client
,
model
,
prompt
,
max_tokens_to_sample
,
temperature
,
stop
):
def
anthropic_completion
(
client
,
model
,
prompt
,
max_tokens_to_sample
,
temperature
,
stop
):
"""Query Anthropic API for completion.
Retry with back-off until they respond
...
...
@@ -14,7 +16,7 @@ def anthropic_completion(client, model, prompt, max_tokens_to_sample, temperatur
backoff_time
=
3
while
True
:
try
:
response
=
client
.
completion
(
response
=
client
.
completion
s
.
create
(
prompt
=
f
"
{
anthropic
.
HUMAN_PROMPT
}
{
prompt
}{
anthropic
.
AI_PROMPT
}
"
,
model
=
model
,
# NOTE: Claude really likes to do CoT, and overly aggressive stop sequences
...
...
@@ -24,7 +26,7 @@ def anthropic_completion(client, model, prompt, max_tokens_to_sample, temperatur
temperature
=
temperature
,
)
print
(
response
)
return
response
[
"
completion
"
]
return
response
.
completion
except
RuntimeError
:
# TODO: I don't actually know what error Anthropic raises when it times out
# So err update this error when we find out.
...
...
@@ -38,7 +40,7 @@ def anthropic_completion(client, model, prompt, max_tokens_to_sample, temperatur
class
AnthropicLM
(
BaseLM
):
REQ_CHUNK_SIZE
=
20
def
__init__
(
self
,
model
):
def
__init__
(
self
,
model
=
"claude-2"
):
"""
:param model: str
...
...
@@ -46,8 +48,9 @@ class AnthropicLM(BaseLM):
"""
super
().
__init__
()
import
anthropic
self
.
model
=
model
self
.
client
=
anthropic
.
Client
(
os
.
environ
[
'
ANTHROPIC_API_KEY
'
])
self
.
client
=
anthropic
.
Anthropic
(
api_key
=
os
.
environ
[
"
ANTHROPIC_API_KEY
"
])
@
property
def
eot_token_id
(
self
):
...
...
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