Skip to content

Commit 493c4ba

Browse files
committed
Add anthropic support
1 parent e573a72 commit 493c4ba

9 files changed

+111
-2
lines changed

β€Žaisploit/core/model.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ class BaseLLM(Runnable[LanguageModelInput, str]):
1313
class BaseChatModel(Runnable[LanguageModelInput, BaseMessage]):
1414
@abstractmethod
1515
def supports_functions(self) -> bool:
16+
"""
17+
Check if the model supports additional functions beyond basic chat.
18+
19+
Returns:
20+
bool: True if the model supports additional functions, False otherwise.
21+
"""
1622
pass
1723

1824

β€Žaisploit/core/report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __iter__(self):
3232

3333
def __len__(self):
3434
return len(self._entries)
35-
35+
3636
def __getitem__(self, index: int) -> T:
3737
"""Get an entry from the report by index."""
3838
return self._entries[index]

β€Žaisploit/model/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from .bedrock_chat import BedrockChat
2+
from .chat_anthropic import ChatAnthropic
23
from .chat_ollama import ChatOllama
34
from .chat_openai import ChatOpenAI
45

56
__all__ = [
67
"BedrockChat",
8+
"ChatAnthropic",
79
"ChatOllama",
810
"ChatOpenAI",
911
]

β€Žaisploit/model/bedrock_chat.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@ def __init__(
1616
)
1717

1818
def supports_functions(self) -> bool:
19+
"""
20+
Check if the model supports additional functions beyond basic chat.
21+
22+
Returns:
23+
bool: True if the model supports additional functions, False otherwise.
24+
"""
1925
return False

β€Žaisploit/model/chat_anthropic.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from typing import Optional
2+
from langchain_core.utils.utils import convert_to_secret_str
3+
from langchain_anthropic import ChatAnthropic as LangchainChatAnthropic
4+
5+
from ..core import BaseChatModel
6+
7+
8+
class ChatAnthropic(LangchainChatAnthropic, BaseChatModel):
9+
"""A chat model based on Anthropic's language generation technology."""
10+
11+
def __init__(
12+
self,
13+
*,
14+
api_key: Optional[str],
15+
model_name: str = "claude-3-opus-20240229",
16+
temperature: float = 1.0,
17+
**kwargs,
18+
) -> None:
19+
"""
20+
Initialize the ChatAnthropic instance.
21+
22+
Args:
23+
api_key (str or None): The API key for accessing the Anthropic API.
24+
model_name (str): The name of the language model to use.
25+
temperature (float): The temperature parameter controlling the randomness of the generated text.
26+
**kwargs: Additional keyword arguments to be passed to the base class constructor.
27+
"""
28+
super().__init__(
29+
anthropic_api_key=convert_to_secret_str(api_key) if api_key else None,
30+
model_name=model_name,
31+
temperature=temperature,
32+
**kwargs,
33+
)
34+
35+
def supports_functions(self) -> bool:
36+
"""
37+
Check if the model supports additional functions beyond basic chat.
38+
39+
Returns:
40+
bool: True if the model supports additional functions, False otherwise.
41+
"""
42+
return False

β€Žaisploit/model/chat_ollama.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,10 @@ def __init__(
3030
)
3131

3232
def supports_functions(self) -> bool:
33+
"""
34+
Check if the model supports additional functions beyond basic chat.
35+
36+
Returns:
37+
bool: True if the model supports additional functions, False otherwise.
38+
"""
3339
return False

β€Žaisploit/model/chat_openai.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,10 @@ def __init__(
3838
)
3939

4040
def supports_functions(self) -> bool:
41+
"""
42+
Check if the model supports additional functions beyond basic chat.
43+
44+
Returns:
45+
bool: True if the model supports additional functions, False otherwise.
46+
"""
4147
return True

β€Žpoetry.lock

Lines changed: 41 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žpyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ torch = "^2.2.2"
3838
jinja2 = "^3.1.3"
3939
ipython = "^8.23.0"
4040
imapclient = "^3.0.1"
41+
langchain-anthropic = "^0.1.6"
4142

4243
[tool.poetry.group.dev.dependencies]
4344
chromadb = "^0.4.23"

0 commit comments

Comments
Β (0)