-
-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update anthropic providers to use langchain_anthropic partner package
- Loading branch information
Showing
5 changed files
with
64 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/jupyter-ai-magics/jupyter_ai_magics/partner_providers/anthropic.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from langchain_anthropic import AnthropicLLM, ChatAnthropic | ||
|
||
from ..providers import BaseProvider, EnvAuthStrategy | ||
|
||
|
||
class AnthropicProvider(BaseProvider, AnthropicLLM): | ||
id = "anthropic" | ||
name = "Anthropic" | ||
models = [ | ||
"claude-v1", | ||
"claude-v1.0", | ||
"claude-v1.2", | ||
"claude-2", | ||
"claude-2.0", | ||
"claude-instant-v1", | ||
"claude-instant-v1.0", | ||
"claude-instant-v1.2", | ||
] | ||
model_id_key = "model" | ||
pypi_package_deps = ["anthropic"] | ||
auth_strategy = EnvAuthStrategy(name="ANTHROPIC_API_KEY") | ||
|
||
@property | ||
def allows_concurrency(self): | ||
return False | ||
|
||
@classmethod | ||
def is_api_key_exc(cls, e: Exception): | ||
""" | ||
Determine if the exception is an Anthropic API key error. | ||
""" | ||
import anthropic | ||
|
||
if isinstance(e, anthropic.AuthenticationError): | ||
return e.status_code == 401 and "Invalid API Key" in str(e) | ||
return False | ||
|
||
|
||
class ChatAnthropicProvider( | ||
BaseProvider, ChatAnthropic | ||
): # https://docs.anthropic.com/claude/docs/models-overview | ||
id = "anthropic-chat" | ||
name = "ChatAnthropic" | ||
models = [ | ||
"claude-2.0", | ||
"claude-2.1", | ||
"claude-instant-1.2", | ||
"claude-3-opus-20240229", | ||
"claude-3-sonnet-20240229", | ||
"claude-3-haiku-20240307", | ||
] | ||
model_id_key = "model" | ||
pypi_package_deps = ["anthropic"] | ||
auth_strategy = EnvAuthStrategy(name="ANTHROPIC_API_KEY") | ||
|
||
@property | ||
def allows_concurrency(self): | ||
return False | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters