MCPcopy Create free account
hub / github.com/OpenBitSys/BitDistiller / AnthropicLM

Class AnthropicLM

test/general/lm_eval/models/anthropic_llms.py:38–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36
37
38class AnthropicLM(BaseLM):
39 REQ_CHUNK_SIZE = 20
40
41 def __init__(self, model):
42 """
43
44 :param model: str
45 Anthropic model e.g. claude-instant-v1
46 """
47 super().__init__()
48 import anthropic
49 self.model = model
50 self.client = anthropic.Client(os.environ['ANTHROPIC_API_KEY'])
51
52 @property
53 def eot_token_id(self):
54 raise NotImplementedError("No idea about anthropic tokenization.")
55
56 @property
57 def max_length(self):
58 return 2048
59
60 @property
61 def max_gen_toks(self):
62 return 256
63
64 @property
65 def batch_size(self):
66 # Isn't used because we override _loglikelihood_tokens
67 raise NotImplementedError()
68
69 @property
70 def device(self):
71 # Isn't used because we override _loglikelihood_tokens
72 raise NotImplementedError()
73
74 def tok_encode(self, string: str):
75 raise NotImplementedError("No idea about anthropic tokenization.")
76
77 def tok_decode(self, tokens):
78 raise NotImplementedError("No idea about anthropic tokenization.")
79
80 def _loglikelihood_tokens(self, requests, disable_tqdm=False):
81 raise NotImplementedError("No support for logits.")
82
83 def greedy_until(self, requests):
84 if not requests:
85 return []
86
87 res = []
88 for request in tqdm(requests):
89 inp = request[0]
90 request_args = request[1]
91 until = request_args["until"]
92 response = anthropic_completion(
93 client=self.client,
94 model=self.model,
95 prompt=inp,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected