Skip to content

Commit 40248a1

Browse files
authored
Add Claude 2 support (#231)
* Add Claude 2 support. * Add Claude-2 support.
1 parent a3ee82e commit 40248a1

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

spacy_llm/models/rest/anthropic/model.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import srsly # type: ignore[import]
88
from requests import HTTPError
99

10-
from ....compat import Literal
1110
from ..base import REST
1211

1312

@@ -25,10 +24,6 @@ class SystemPrompt(str, Enum):
2524

2625

2726
class Anthropic(REST):
28-
MODEL_NAMES = {
29-
"claude-1": Literal["claude-1", "claude-1-100k"],
30-
}
31-
3227
@property
3328
def credentials(self) -> Dict[str, str]:
3429
# Fetch and check the key, set up headers
@@ -115,6 +110,9 @@ def _request(json_data: Dict[str, Any]) -> Dict[str, Any]:
115110
@classmethod
116111
def get_model_names(cls) -> Tuple[str, ...]:
117112
return (
113+
# claude-1
114+
"claude-2",
115+
"claude-2-100k",
118116
# claude-1
119117
"claude-1",
120118
"claude-1-100k",

spacy_llm/models/rest/anthropic/registry.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,40 @@
77
from .model import Anthropic, Endpoints
88

99

10+
@registry.llm_models("spacy.Claude-2.v1")
11+
def anthropic_claude_2(
12+
config: Dict[Any, Any] = SimpleFrozenDict(),
13+
name: Literal["claude-2", "claude-2-100k"] = "claude-2", # noqa: F722
14+
strict: bool = Anthropic.DEFAULT_STRICT,
15+
max_tries: int = Anthropic.DEFAULT_MAX_TRIES,
16+
interval: float = Anthropic.DEFAULT_INTERVAL,
17+
max_request_time: float = Anthropic.DEFAULT_MAX_REQUEST_TIME,
18+
) -> Callable[[Iterable[str]], Iterable[str]]:
19+
"""Returns Anthropic instance for 'claude-2' model using REST to prompt API.
20+
config (Dict[Any, Any]): LLM config arguments passed on to the initialization of the model instance.
21+
name (Literal["claude-2", "claude-2-100k"]): Model to use.
22+
strict (bool): If True, ValueError is raised if the LLM API returns a malformed response (i. e. any kind of JSON
23+
or other response object that does not conform to the expectation of how a well-formed response object from
24+
this API should look like). If False, the API error responses are returned by __call__(), but no error will
25+
be raised.
26+
max_tries (int): Max. number of tries for API request.
27+
interval (float): Time interval (in seconds) for API retries in seconds. We implement a base 2 exponential backoff
28+
at each retry.
29+
max_request_time (float): Max. time (in seconds) to wait for request to terminate before raising an exception.
30+
RETURNS (Callable[[Iterable[str]], Iterable[str]]]): Anthropic instance for 'claude-1' model using REST to
31+
prompt API.
32+
"""
33+
return Anthropic(
34+
name=name,
35+
endpoint=Endpoints.COMPLETIONS,
36+
config=config,
37+
strict=strict,
38+
max_tries=max_tries,
39+
interval=interval,
40+
max_request_time=max_request_time,
41+
)
42+
43+
1044
@registry.llm_models("spacy.Claude-1.v1")
1145
def anthropic_claude_1(
1246
config: Dict[Any, Any] = SimpleFrozenDict(),

0 commit comments

Comments
 (0)