Skip to content

Commit 0fad182

Browse files
meeseeksmachineanthonyhungnguyendlqqq
authored
Backport PR #1417 on branch 2.x (Add VertexAI model provider) (#1421)
* Backport PR #1417: Add VertexAI model provider * add cohere version ceiling, porting fix from #1412 * add cohere version floor * bump cohere version floor * remove hard dep on langchain_google_vertexai * add version floors to langchain_aws and langchain_cohere * loosen cohere version floor to match langchain_cohere>=0.3 --------- Co-authored-by: Phuc Hung Nguyen <[email protected]> Co-authored-by: David L. Qiu <[email protected]>
1 parent 8b5b369 commit 0fad182

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from jupyter_ai_magics.base_provider import BaseProvider
2+
from langchain_google_vertexai import VertexAI, VertexAIEmbeddings
3+
4+
5+
class VertexAIProvider(BaseProvider, VertexAI):
6+
id = "vertexai"
7+
name = "Vertex AI"
8+
models = [
9+
"gemini-2.5-pro",
10+
"gemini-2.5-flash",
11+
]
12+
model_id_key = "model"
13+
auth_strategy = None
14+
pypi_package_deps = ["langchain-google-vertexai"]
15+
help = (
16+
"To use Vertex AI Generative AI you must have the langchain-google-vertexai Python package installed and either:\n\n"
17+
"- Have credentials configured for your environment (gcloud, workload identity, etc...)\n"
18+
"- Store the path to a service account JSON file as the GOOGLE_APPLICATION_CREDENTIALS environment variable\n\n"
19+
"This codebase uses the google.auth library which first looks for the application credentials variable mentioned above, and then looks for system-level auth. "
20+
"For more information, see the [Vertex AI authentication documentation](https://python.langchain.com/docs/integrations/llms/google_vertex_ai_palm/)."
21+
)
22+
23+
class VertexAIEmbeddingsProvider(BaseProvider, VertexAIEmbeddings):
24+
id = "vertexai"
25+
name = "Vertex AI"
26+
models = [
27+
"text-embedding-004",
28+
]
29+
model_id_key = "model"
30+
auth_strategy = None
31+
pypi_package_deps = ["langchain-google-vertexai"]
32+
help = (
33+
"To use Vertex AI Generative AI you must have the langchain-google-vertexai Python package installed and either:\n\n"
34+
"- Have credentials configured for your environment (gcloud, workload identity, etc...)\n"
35+
"- Store the path to a service account JSON file as the GOOGLE_APPLICATION_CREDENTIALS environment variable\n\n"
36+
"This codebase uses the google.auth library which first looks for the application credentials variable mentioned above, and then looks for system-level auth. "
37+
"For more information, see the [Vertex AI authentication documentation](https://python.langchain.com/docs/integrations/llms/google_vertex_ai_palm/)."
38+
)

packages/jupyter-ai-magics/pyproject.toml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ all = [
5050
"huggingface_hub",
5151
"ipywidgets",
5252
"langchain_anthropic",
53-
"langchain_aws",
54-
"langchain_cohere",
53+
# `langchain_aws<0.2` is not compatible with LangChain v0.3
54+
"langchain_aws>=0.2,<0.3",
55+
# `langchain_cohere<0.3` is not compatible with LangChain v0.3
56+
"langchain_cohere>=0.3",
57+
# Pin cohere to <5.16 to prevent langchain_cohere from breaking as it uses ChatResponse removed in cohere 5.16.0
58+
# cohere>=5.5.6 is implied by langchain_cohere>=0.3
59+
# TODO: remove cohere pin when langchain_cohere is updated to work with cohere >=5.16
60+
"cohere>=5.5.6,<5.16",
5561
"langchain_google_genai",
5662
"langchain_mistralai",
5763
"langchain_nvidia_ai_endpoints",
@@ -61,6 +67,7 @@ all = [
6167
"boto3",
6268
"qianfan",
6369
"together",
70+
"langchain-google-vertexai",
6471
]
6572

6673
[project.entry-points."jupyter_ai.model_providers"]
@@ -84,6 +91,7 @@ together-ai = "jupyter_ai_magics:TogetherAIProvider"
8491
gemini = "jupyter_ai_magics.partner_providers.gemini:GeminiProvider"
8592
mistralai = "jupyter_ai_magics.partner_providers.mistralai:MistralAIProvider"
8693
openrouter = "jupyter_ai_magics.partner_providers.openrouter:OpenRouterProvider"
94+
vertexai = "jupyter_ai_magics.partner_providers.vertexai:VertexAIProvider"
8795

8896
[project.entry-points."jupyter_ai.embeddings_model_providers"]
8997
azure = "jupyter_ai_magics.partner_providers.openai:AzureOpenAIEmbeddingsProvider"
@@ -96,6 +104,7 @@ ollama = "jupyter_ai_magics.partner_providers.ollama:OllamaEmbeddingsProvider"
96104
openai = "jupyter_ai_magics.partner_providers.openai:OpenAIEmbeddingsProvider"
97105
openai-custom = "jupyter_ai_magics.partner_providers.openai:OpenAIEmbeddingsCustomProvider"
98106
qianfan = "jupyter_ai_magics:QianfanEmbeddingsEndpointProvider"
107+
vertexai = "jupyter_ai_magics.partner_providers.vertexai:VertexAIEmbeddingsProvider"
99108

100109
[tool.hatch.version]
101110
source = "nodejs"

0 commit comments

Comments
 (0)