From ab15d99fe537b161e923e1647c79ac65b3a76eb4 Mon Sep 17 00:00:00 2001 From: "David L. Qiu" Date: Mon, 29 Jul 2024 10:59:12 -0700 Subject: [PATCH 1/6] add BedrockCustomProvider --- .../partner_providers/aws.py | 23 +++++++++++++++++++ packages/jupyter-ai-magics/pyproject.toml | 1 + 2 files changed, 24 insertions(+) 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 0b06adcc8..62a44baa0 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 @@ -104,6 +104,28 @@ def allows_concurrency(self): return not "anthropic" in self.model_id +class BedrockCustomProvider(BaseProvider, ChatBedrock): + id = "bedrock-custom" + name = "Amazon Bedrock (custom/provisioned)" + models = ["*"] + model_id_key = "model_id" + pypi_package_deps = ["langchain-aws"] + auth_strategy = AwsAuthStrategy() + fields = [ + TextField(key="provider", label="Provider (required)", format="text"), + TextField(key="region_name", label="Region name (optional)", format="text"), + TextField( + key="credentials_profile_name", + label="AWS profile (optional)", + format="text", + ), + ] + help = ( + "Specify the ARN of the custom/provisioned model as the model ID. For more information, see the [Amazon Bedrock model IDs documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html)" + "The model provider must be provided. This is the provider of your foundation model, e.g. `amazon`, `anthropic`, `meta`, or `mistral`." + ) + + # See model ID list here: https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html class BedrockEmbeddingsProvider(BaseEmbeddingsProvider, BedrockEmbeddings): id = "bedrock" @@ -188,3 +210,4 @@ def __init__(self, *args, **kwargs): async def _acall(self, *args, **kwargs) -> Coroutine[Any, Any, str]: return await self._call_in_executor(*args, **kwargs) + diff --git a/packages/jupyter-ai-magics/pyproject.toml b/packages/jupyter-ai-magics/pyproject.toml index c73df8aea..02eb8b9e5 100644 --- a/packages/jupyter-ai-magics/pyproject.toml +++ b/packages/jupyter-ai-magics/pyproject.toml @@ -68,6 +68,7 @@ azure-chat-openai = "jupyter_ai_magics.partner_providers.openai:AzureChatOpenAIP sagemaker-endpoint = "jupyter_ai_magics.partner_providers.aws:SmEndpointProvider" amazon-bedrock = "jupyter_ai_magics.partner_providers.aws:BedrockProvider" amazon-bedrock-chat = "jupyter_ai_magics.partner_providers.aws:BedrockChatProvider" +amazon-bedrock-custom = "jupyter_ai_magics.partner_providers.aws:BedrockCustomProvider" qianfan = "jupyter_ai_magics:QianfanProvider" nvidia-chat = "jupyter_ai_magics.partner_providers.nvidia:ChatNVIDIAProvider" together-ai = "jupyter_ai_magics:TogetherAIProvider" From c3faf0da198280a27ec8bf64a0d41f7611653e2d Mon Sep 17 00:00:00 2001 From: "David L. Qiu" Date: Tue, 30 Jul 2024 15:02:44 -0700 Subject: [PATCH 2/6] pre-commit --- .../jupyter-ai-magics/jupyter_ai_magics/partner_providers/aws.py | 1 - 1 file changed, 1 deletion(-) 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 62a44baa0..0ec69cf9d 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 @@ -210,4 +210,3 @@ def __init__(self, *args, **kwargs): async def _acall(self, *args, **kwargs) -> Coroutine[Any, Any, str]: return await self._call_in_executor(*args, **kwargs) - From 092f5a355ce3a2f7a371f32c30ffcd1dd8b58f44 Mon Sep 17 00:00:00 2001 From: "David L. Qiu" Date: Tue, 30 Jul 2024 15:09:52 -0700 Subject: [PATCH 3/6] format help text --- .../jupyter_ai_magics/partner_providers/aws.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 0ec69cf9d..9576d88fa 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 @@ -121,8 +121,8 @@ class BedrockCustomProvider(BaseProvider, ChatBedrock): ), ] help = ( - "Specify the ARN of the custom/provisioned model as the model ID. For more information, see the [Amazon Bedrock model IDs documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html)" - "The model provider must be provided. This is the provider of your foundation model, e.g. `amazon`, `anthropic`, `meta`, or `mistral`." + "Specify the ARN of the custom/provisioned model as the model ID. For more information, see the [Amazon Bedrock model IDs documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html).\n\n" + "The model provider must also be specified below. This is the provider of your foundation model, e.g. `amazon`, `anthropic`, `meta`, or `mistral`." ) From 41cd2c7a5fcf32411baa0c37c36d1764888b0869 Mon Sep 17 00:00:00 2001 From: "David L. Qiu" Date: Tue, 30 Jul 2024 15:22:56 -0700 Subject: [PATCH 4/6] show model ID field --- .../jupyter_ai_magics/partner_providers/aws.py | 2 ++ 1 file changed, 2 insertions(+) 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 9576d88fa..ef7056364 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 @@ -109,6 +109,7 @@ class BedrockCustomProvider(BaseProvider, ChatBedrock): name = "Amazon Bedrock (custom/provisioned)" models = ["*"] model_id_key = "model_id" + model_id_label = "Model ID" pypi_package_deps = ["langchain-aws"] auth_strategy = AwsAuthStrategy() fields = [ @@ -124,6 +125,7 @@ class BedrockCustomProvider(BaseProvider, ChatBedrock): "Specify the ARN of the custom/provisioned model as the model ID. For more information, see the [Amazon Bedrock model IDs documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html).\n\n" "The model provider must also be specified below. This is the provider of your foundation model, e.g. `amazon`, `anthropic`, `meta`, or `mistral`." ) + registry = True # See model ID list here: https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html From 833d999de6eb5fff54bfa45c6177d54f42d2246d Mon Sep 17 00:00:00 2001 From: "David L. Qiu" Date: Wed, 31 Jul 2024 14:31:54 -0700 Subject: [PATCH 5/6] edit BedrockCustomProvider help text --- .../jupyter_ai_magics/partner_providers/aws.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 ef7056364..4635a2e2a 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 @@ -122,8 +122,8 @@ class BedrockCustomProvider(BaseProvider, ChatBedrock): ), ] help = ( - "Specify the ARN of the custom/provisioned model as the model ID. For more information, see the [Amazon Bedrock model IDs documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html).\n\n" - "The model provider must also be specified below. This is the provider of your foundation model, e.g. `amazon`, `anthropic`, `meta`, or `mistral`." + "Specify the ARN (Amazon Resource Name) of the custom/provisioned model as the model ID. For more information, see the [Amazon Bedrock model IDs documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html).\n\n" + "The model provider must also be specified below. This is the provider of your foundation model *in lowercase*, e.g. `amazon`, `anthropic`, `meta`, or `mistral`." ) registry = True From 5221813f40370bb18058e79d7863b734d4d63391 Mon Sep 17 00:00:00 2001 From: "David L. Qiu" Date: Wed, 31 Jul 2024 14:49:43 -0700 Subject: [PATCH 6/6] add mention of BedrockCustom in docs --- docs/source/users/index.md | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/docs/source/users/index.md b/docs/source/users/index.md index 6cd1118d6..bb660c882 100644 --- a/docs/source/users/index.md +++ b/docs/source/users/index.md @@ -153,23 +153,24 @@ Jupyter AI supports a wide range of model providers and models. To use Jupyter A Jupyter AI supports the following model providers: -| Provider | Provider ID | Environment variable(s) | Python package(s) | -|---------------------|----------------------|----------------------------|---------------------------------| -| AI21 | `ai21` | `AI21_API_KEY` | `ai21` | -| Anthropic | `anthropic` | `ANTHROPIC_API_KEY` | `langchain-anthropic` | -| Anthropic (chat) | `anthropic-chat` | `ANTHROPIC_API_KEY` | `langchain-anthropic` | -| Bedrock | `bedrock` | N/A | `langchain-aws` | -| Bedrock (chat) | `bedrock-chat` | N/A | `langchain-aws` | -| Cohere | `cohere` | `COHERE_API_KEY` | `langchain_cohere` | -| ERNIE-Bot | `qianfan` | `QIANFAN_AK`, `QIANFAN_SK` | `qianfan` | -| Gemini | `gemini` | `GOOGLE_API_KEY` | `langchain-google-genai` | -| GPT4All | `gpt4all` | N/A | `gpt4all` | -| Hugging Face Hub | `huggingface_hub` | `HUGGINGFACEHUB_API_TOKEN` | `huggingface_hub`, `ipywidgets`, `pillow` | -| MistralAI | `mistralai` | `MISTRAL_API_KEY` | `langchain-mistralai` | -| NVIDIA | `nvidia-chat` | `NVIDIA_API_KEY` | `langchain_nvidia_ai_endpoints` | -| OpenAI | `openai` | `OPENAI_API_KEY` | `langchain-openai` | -| OpenAI (chat) | `openai-chat` | `OPENAI_API_KEY` | `langchain-openai` | -| SageMaker | `sagemaker-endpoint` | N/A | `langchain-aws` | +| Provider | Provider ID | Environment variable(s) | Python package(s) | +|------------------------------|----------------------|----------------------------|-------------------------------------------| +| AI21 | `ai21` | `AI21_API_KEY` | `ai21` | +| Anthropic | `anthropic` | `ANTHROPIC_API_KEY` | `langchain-anthropic` | +| Anthropic (chat) | `anthropic-chat` | `ANTHROPIC_API_KEY` | `langchain-anthropic` | +| Bedrock | `bedrock` | N/A | `langchain-aws` | +| Bedrock (chat) | `bedrock-chat` | N/A | `langchain-aws` | +| Bedrock (custom/provisioned) | `bedrock-custom` | N/A | `langchain-aws` | +| Cohere | `cohere` | `COHERE_API_KEY` | `langchain-cohere` | +| ERNIE-Bot | `qianfan` | `QIANFAN_AK`, `QIANFAN_SK` | `qianfan` | +| Gemini | `gemini` | `GOOGLE_API_KEY` | `langchain-google-genai` | +| GPT4All | `gpt4all` | N/A | `gpt4all` | +| Hugging Face Hub | `huggingface_hub` | `HUGGINGFACEHUB_API_TOKEN` | `huggingface_hub`, `ipywidgets`, `pillow` | +| MistralAI | `mistralai` | `MISTRAL_API_KEY` | `langchain-mistralai` | +| NVIDIA | `nvidia-chat` | `NVIDIA_API_KEY` | `langchain_nvidia_ai_endpoints` | +| OpenAI | `openai` | `OPENAI_API_KEY` | `langchain-openai` | +| OpenAI (chat) | `openai-chat` | `OPENAI_API_KEY` | `langchain-openai` | +| SageMaker endpoint | `sagemaker-endpoint` | N/A | `langchain-aws` | The environment variable names shown above are also the names of the settings keys used when setting up the chat interface. If multiple variables are listed for a provider, **all** must be specified. @@ -615,6 +616,7 @@ We currently support the following language model providers: - `anthropic-chat` - `bedrock` - `bedrock-chat` +- `bedrock-custom` - `cohere` - `huggingface_hub` - `nvidia-chat`