From 001694568291695fc10a6c536358e241d9099ddb Mon Sep 17 00:00:00 2001
From: "Lumberbot (aka Jack)"
 <39504233+meeseeksmachine@users.noreply.github.com>
Date: Wed, 6 Nov 2024 10:10:37 -0800
Subject: [PATCH] Backport PR #1092: Remove retired models and add new
 `Haiku-3.5` model in Anthropic (#1093)

Co-authored-by: Sanjiv Das <srdas@scu.edu>
---
 .../partner_providers/anthropic.py            | 45 ++++++-------------
 .../partner_providers/aws.py                  |  1 +
 packages/jupyter-ai-magics/pyproject.toml     |  1 -
 3 files changed, 14 insertions(+), 33 deletions(-)

diff --git a/packages/jupyter-ai-magics/jupyter_ai_magics/partner_providers/anthropic.py b/packages/jupyter-ai-magics/jupyter_ai_magics/partner_providers/anthropic.py
index e36563f69..8cfee8243 100644
--- a/packages/jupyter-ai-magics/jupyter_ai_magics/partner_providers/anthropic.py
+++ b/packages/jupyter-ai-magics/jupyter_ai_magics/partner_providers/anthropic.py
@@ -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
@@ -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",
     ]
@@ -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
diff --git a/packages/jupyter-ai-magics/jupyter_ai_magics/partner_providers/aws.py b/packages/jupyter-ai-magics/jupyter_ai_magics/partner_providers/aws.py
index e669c9d8e..4baff07a6 100644
--- a/packages/jupyter-ai-magics/jupyter_ai_magics/partner_providers/aws.py
+++ b/packages/jupyter-ai-magics/jupyter_ai_magics/partner_providers/aws.py
@@ -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",
diff --git a/packages/jupyter-ai-magics/pyproject.toml b/packages/jupyter-ai-magics/pyproject.toml
index 91ef5699f..40c7b234d 100644
--- a/packages/jupyter-ai-magics/pyproject.toml
+++ b/packages/jupyter-ai-magics/pyproject.toml
@@ -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"