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

Fix Cohere models by using new langchain-cohere partner package #848

Merged
merged 3 commits into from
Jun 21, 2024
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
2 changes: 1 addition & 1 deletion docs/source/users/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Jupyter AI supports the following model providers:
| Anthropic (chat) | `anthropic-chat` | `ANTHROPIC_API_KEY` | `langchain-anthropic` |
| Bedrock | `bedrock` | N/A | `boto3` |
| Bedrock (chat) | `bedrock-chat` | N/A | `boto3` |
| Cohere | `cohere` | `COHERE_API_KEY` | `cohere` |
| 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` |
Expand Down
2 changes: 0 additions & 2 deletions packages/jupyter-ai-magics/jupyter_ai_magics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from .embedding_providers import (
BaseEmbeddingsProvider,
BedrockEmbeddingsProvider,
CohereEmbeddingsProvider,
GPT4AllEmbeddingsProvider,
HfHubEmbeddingsProvider,
QianfanEmbeddingsEndpointProvider,
Expand All @@ -22,7 +21,6 @@
BaseProvider,
BedrockChatProvider,
BedrockProvider,
CohereProvider,
GPT4AllProvider,
HfHubProvider,
QianfanProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
from langchain.pydantic_v1 import BaseModel, Extra
from langchain_community.embeddings import (
BedrockEmbeddings,
CohereEmbeddings,
GPT4AllEmbeddings,
HuggingFaceHubEmbeddings,
OpenAIEmbeddings,
QianfanEmbeddingsEndpoint,
)

Expand Down Expand Up @@ -68,23 +66,6 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs, **model_kwargs)


class CohereEmbeddingsProvider(BaseEmbeddingsProvider, CohereEmbeddings):
id = "cohere"
name = "Cohere"
models = [
"embed-english-v2.0",
"embed-english-light-v2.0",
"embed-multilingual-v2.0",
"embed-english-v3.0",
"embed-english-light-v3.0",
"embed-multilingual-v3.0",
"embed-multilingual-light-v3.0",
]
model_id_key = "model"
pypi_package_deps = ["cohere"]
auth_strategy = EnvAuthStrategy(name="COHERE_API_KEY")


class HfHubEmbeddingsProvider(BaseEmbeddingsProvider, HuggingFaceHubEmbeddings):
id = "huggingface_hub"
name = "Hugging Face Hub"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from langchain_cohere import ChatCohere, CohereEmbeddings

from ..embedding_providers import BaseEmbeddingsProvider
from ..providers import BaseProvider, EnvAuthStrategy


class CohereProvider(BaseProvider, ChatCohere):
id = "cohere"
name = "Cohere"
# https://docs.cohere.com/docs/models
# note: This provider uses the Chat endpoint instead of the Generate
# endpoint, which is now deprecated.
models = [
"command",
"command-nightly",
"command-light",
"command-light-nightly",
"command-r-plus",
"command-r",
]
model_id_key = "model"
pypi_package_deps = ["langchain_cohere"]
auth_strategy = EnvAuthStrategy(name="COHERE_API_KEY")


class CohereEmbeddingsProvider(BaseEmbeddingsProvider, CohereEmbeddings):
id = "cohere"
name = "Cohere"
models = [
"embed-english-v2.0",
"embed-english-light-v2.0",
"embed-multilingual-v2.0",
"embed-english-v3.0",
"embed-english-light-v3.0",
"embed-multilingual-v3.0",
"embed-multilingual-light-v3.0",
]
model_id_key = "model"
pypi_package_deps = ["langchain_cohere"]
auth_strategy = EnvAuthStrategy(name="COHERE_API_KEY")
21 changes: 0 additions & 21 deletions packages/jupyter-ai-magics/jupyter_ai_magics/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from langchain_community.llms import (
AI21,
Bedrock,
Cohere,
GPT4All,
HuggingFaceEndpoint,
SagemakerEndpoint,
Expand Down Expand Up @@ -546,26 +545,6 @@ def is_api_key_exc(cls, e: Exception):
return False


class CohereProvider(BaseProvider, Cohere):
id = "cohere"
name = "Cohere"
# Source: https://docs.cohere.com/reference/generate; https://docs.cohere.com/docs/models
models = [
"command",
"command-nightly",
"command-light",
"command-light-nightly",
"command-r-plus",
"command-r",
]
model_id_key = "model"
pypi_package_deps = ["cohere"]
auth_strategy = EnvAuthStrategy(name="COHERE_API_KEY")

async def _acall(self, *args, **kwargs) -> Coroutine[Any, Any, str]:
return await self._call_in_executor(*args, **kwargs)


class GPT4AllProvider(BaseProvider, GPT4All):
def __init__(self, **kwargs):
model = kwargs.get("model_id")
Expand Down
12 changes: 6 additions & 6 deletions packages/jupyter-ai-magics/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ test = ["coverage", "pytest", "pytest-asyncio", "pytest-cov"]

all = [
"ai21",
"cohere>4.40,<5",
"gpt4all",
"huggingface_hub",
"ipywidgets",
"langchain_anthropic",
"langchain-mistralai",
"langchain_cohere",
"langchain_google_genai",
"langchain_mistralai",
"langchain_nvidia_ai_endpoints",
"langchain-google-genai",
"langchain-openai",
"langchain_openai",
"pillow",
"boto3",
"qianfan",
Expand All @@ -55,7 +55,7 @@ all = [
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:CohereProvider"
cohere = "jupyter_ai_magics.partner_providers.cohere:CohereProvider"
gpt4all = "jupyter_ai_magics:GPT4AllProvider"
huggingface_hub = "jupyter_ai_magics:HfHubProvider"
openai = "jupyter_ai_magics.partner_providers.openai:OpenAIProvider"
Expand All @@ -72,7 +72,7 @@ mistralai = "jupyter_ai_magics.partner_providers.mistralai:MistralAIProvider"

[project.entry-points."jupyter_ai.embeddings_model_providers"]
bedrock = "jupyter_ai_magics:BedrockEmbeddingsProvider"
cohere = "jupyter_ai_magics:CohereEmbeddingsProvider"
cohere = "jupyter_ai_magics.partner_providers.cohere:CohereEmbeddingsProvider"
mistralai = "jupyter_ai_magics.partner_providers.mistralai:MistralAIEmbeddingsProvider"
gpt4all = "jupyter_ai_magics:GPT4AllEmbeddingsProvider"
huggingface_hub = "jupyter_ai_magics:HfHubEmbeddingsProvider"
Expand Down
Loading