Skip to content

Commit

Permalink
Backport PR jupyterlab#1092: Remove retired models and add new `Haiku…
Browse files Browse the repository at this point in the history
…-3.5` model in Anthropic
  • Loading branch information
srdas authored and meeseeksmachine committed Nov 6, 2024
1 parent 1175cfc commit ce31f80
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 33 deletions.
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

0 comments on commit ce31f80

Please sign in to comment.