Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport PR #1092 on branch v3-dev (Remove retired models and add new Haiku-3.5 model in Anthropic) #1093

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,39 +1,8 @@
from langchain_anthropic import AnthropicLLM, ChatAnthropic
from langchain_anthropic import ChatAnthropic

from ..providers import BaseProvider, EnvAuthStrategy


class AnthropicProvider(BaseProvider, AnthropicLLM):
id = "anthropic"
name = "Anthropic"
models = [
"claude-v1",
"claude-v1.0",
"claude-v1.2",
"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/en/docs/about-claude/models
Expand All @@ -45,6 +14,7 @@ class ChatAnthropicProvider(
"claude-3-opus-20240229",
"claude-3-sonnet-20240229",
"claude-3-haiku-20240307",
"claude-3-5-haiku-20241022",
"claude-3-5-sonnet-20240620",
"claude-3-5-sonnet-20241022",
]
Expand All @@ -55,3 +25,14 @@ class ChatAnthropicProvider(
@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
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class BedrockChatProvider(BaseProvider, ChatBedrock):
"anthropic.claude-3-sonnet-20240229-v1:0",
"anthropic.claude-3-haiku-20240307-v1:0",
"anthropic.claude-3-opus-20240229-v1:0",
"anthropic.claude-3-5-haiku-20241022-v1:0",
"anthropic.claude-3-5-sonnet-20240620-v1:0",
"anthropic.claude-3-5-sonnet-20241022-v2:0",
"meta.llama2-13b-chat-v1",
Expand Down
1 change: 0 additions & 1 deletion packages/jupyter-ai-magics/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ all = [

[project.entry-points."jupyter_ai.model_providers"]
ai21 = "jupyter_ai_magics:AI21Provider"
anthropic = "jupyter_ai_magics.partner_providers.anthropic:AnthropicProvider"
anthropic-chat = "jupyter_ai_magics.partner_providers.anthropic:ChatAnthropicProvider"
cohere = "jupyter_ai_magics.partner_providers.cohere:CohereProvider"
gpt4all = "jupyter_ai_magics:GPT4AllProvider"
Expand Down
Loading