| Name | langchain-google-vertexai JSON |
| Version |
3.0.1
JSON |
| download |
| home_page | None |
| Summary | An integration package connecting Google VertexAI and LangChain |
| upload_time | 2025-10-23 20:24:46 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | <4.0.0,>=3.10.0 |
| license | MIT |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# langchain-google-vertexai
This package contains the LangChain integrations for Google Cloud generative models.
## Contents
- [langchain-google-vertexai](#langchain-google-vertexai)
- [Contents](#contents)
- [Installation](#installation)
- [Chat Models](#chat-models)
- [Multimodal inputs](#multimodal-inputs)
- [Multimodal Outputs](#multimodal-outputs)
- [Embeddings](#embeddings)
- [LLMs](#llms)
- [Code Generation](#code-generation)
- [Example: Generate a Python function](#example-generate-a-python-function)
- [Example: Generate JavaScript code](#example-generate-javascript-code)
- [Notes](#notes)
## Installation
```bash
pip install -U langchain-google-vertexai
```
## Chat Models
`ChatVertexAI` class exposes models such as `gemini-pro` and other Gemini variants.
To use, you should have a Google Cloud project with APIs enabled, and configured credentials. Initialize the model as:
```python
from langchain_google_vertexai import ChatVertexAI
llm = ChatVertexAI(model_name="gemini-2.5-flash")
llm.invoke("Sing a ballad of LangChain.")
```
### Multimodal inputs
Gemini supports image inputs when providing a single chat message. Example:
```python
from langchain_core.messages import HumanMessage
from langchain_google_vertexai import ChatVertexAI
llm = ChatVertexAI(model_name="gemini-2.0-flash-001")
message = HumanMessage(
content=[
{
"type": "text",
"text": "What's in this image?",
},
{
"type": "image_url",
"image_url": {"url": "https://picsum.photos/seed/picsum/200/300"}
},
]
)
response = llm.invoke([message])
```
The value of `image_url` can be:
- A public image URL
- An accessible Google Cloud Storage (GCS) file (e.g., `"gcs://path/to/file.png"`)
- A base64 encoded image (e.g., `"data:image/png;base64,abcd124"`)
### Multimodal Outputs
Gemini supports image output. Example:
```python
from langchain_core.messages import HumanMessage
from langchain_google_vertexai import ChatVertexAI, Modality
llm = ChatVertexAI(model_name="imagen-3.0-generate-002",
response_modalities = [Modality.TEXT, Modality.IMAGE])
message = HumanMessage(
content=[
{
"type": "text",
"text": "Generate an image of a cat.",
},
]
)
response = llm.invoke([message])
```
## Embeddings
Google Cloud embeddings models can be used as:
```python
from langchain_google_vertexai import VertexAIEmbeddings
embeddings = VertexAIEmbeddings()
embeddings.embed_query("hello, world!")
```
## LLMs
Use Google Cloud's generative AI models as old-style LangChain LLMs:
```python
from langchain_core.prompts import PromptTemplate
from langchain_google_vertexai import ChatVertexAI
template = """Question: {question}
Answer: Let's think step by step."""
prompt = PromptTemplate.from_template(template)
llm = ChatVertexAI(model_name="gemini-2.5-flash")
chain = prompt | llm
question = "Who was the president of the USA in 1994?"
print(chain.invoke({"question": question}))
```
## Code Generation
You can use Gemini models for code generation tasks to generate code snippets, functions, or scripts in various programming languages.
### Example: Generate a Python function
```python
from langchain_google_vertexai import ChatVertexAI
llm = ChatVertexAI(model_name="gemini-2.5-flash", temperature=0.3, max_output_tokens=1000)
prompt = "Write a Python function that checks if a string is a valid email address."
generated_code = llm.invoke(prompt)
print(generated_code)
```
### Example: Generate JavaScript code
```python
from langchain_google_vertexai import ChatVertexAI
llm = ChatVertexAI(model_name="gemini-2.5-flash", temperature=0.3, max_output_tokens=1000)
prompt_js = "Write a JavaScript function that returns the factorial of a number."
print(llm.invoke(prompt_js))
```
### Notes
- Adjust `temperature` to control creativity (higher values increase randomness).
- Use `max_output_tokens` to limit the length of the generated code.
- Gemini models are well-suited for code generation tasks with advanced understanding of programming concepts.
Raw data
{
"_id": null,
"home_page": null,
"name": "langchain-google-vertexai",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0.0,>=3.10.0",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/49/05/a0c19b1e1de578ff88a80108b74d478d79ff3cfdaba11ec076ea04d9979f/langchain_google_vertexai-3.0.1.tar.gz",
"platform": null,
"description": "# langchain-google-vertexai\n\nThis package contains the LangChain integrations for Google Cloud generative models.\n\n## Contents\n\n- [langchain-google-vertexai](#langchain-google-vertexai)\n - [Contents](#contents)\n - [Installation](#installation)\n - [Chat Models](#chat-models)\n - [Multimodal inputs](#multimodal-inputs)\n - [Multimodal Outputs](#multimodal-outputs)\n - [Embeddings](#embeddings)\n - [LLMs](#llms)\n - [Code Generation](#code-generation)\n - [Example: Generate a Python function](#example-generate-a-python-function)\n - [Example: Generate JavaScript code](#example-generate-javascript-code)\n - [Notes](#notes)\n\n## Installation\n\n```bash\npip install -U langchain-google-vertexai\n```\n\n## Chat Models\n\n`ChatVertexAI` class exposes models such as `gemini-pro` and other Gemini variants.\n\nTo use, you should have a Google Cloud project with APIs enabled, and configured credentials. Initialize the model as:\n\n```python\nfrom langchain_google_vertexai import ChatVertexAI\n\nllm = ChatVertexAI(model_name=\"gemini-2.5-flash\")\nllm.invoke(\"Sing a ballad of LangChain.\")\n```\n\n### Multimodal inputs\n\nGemini supports image inputs when providing a single chat message. Example:\n\n```python\nfrom langchain_core.messages import HumanMessage\nfrom langchain_google_vertexai import ChatVertexAI\n\nllm = ChatVertexAI(model_name=\"gemini-2.0-flash-001\")\nmessage = HumanMessage(\n content=[\n {\n \"type\": \"text\",\n \"text\": \"What's in this image?\",\n },\n {\n \"type\": \"image_url\",\n \"image_url\": {\"url\": \"https://picsum.photos/seed/picsum/200/300\"}\n },\n ]\n)\nresponse = llm.invoke([message])\n```\n\nThe value of `image_url` can be:\n\n- A public image URL\n- An accessible Google Cloud Storage (GCS) file (e.g., `\"gcs://path/to/file.png\"`)\n- A base64 encoded image (e.g., `\"data:image/png;base64,abcd124\"`)\n\n### Multimodal Outputs\n\nGemini supports image output. Example:\n\n```python\nfrom langchain_core.messages import HumanMessage\nfrom langchain_google_vertexai import ChatVertexAI, Modality\n\nllm = ChatVertexAI(model_name=\"imagen-3.0-generate-002\",\n response_modalities = [Modality.TEXT, Modality.IMAGE])\nmessage = HumanMessage(\n content=[\n {\n \"type\": \"text\",\n \"text\": \"Generate an image of a cat.\",\n },\n ]\n)\nresponse = llm.invoke([message])\n```\n\n## Embeddings\n\nGoogle Cloud embeddings models can be used as:\n\n```python\nfrom langchain_google_vertexai import VertexAIEmbeddings\n\nembeddings = VertexAIEmbeddings()\nembeddings.embed_query(\"hello, world!\")\n```\n\n## LLMs\n\nUse Google Cloud's generative AI models as old-style LangChain LLMs:\n\n```python\nfrom langchain_core.prompts import PromptTemplate\nfrom langchain_google_vertexai import ChatVertexAI\n\ntemplate = \"\"\"Question: {question}\n\nAnswer: Let's think step by step.\"\"\"\nprompt = PromptTemplate.from_template(template)\n\nllm = ChatVertexAI(model_name=\"gemini-2.5-flash\")\nchain = prompt | llm\n\nquestion = \"Who was the president of the USA in 1994?\"\nprint(chain.invoke({\"question\": question}))\n```\n\n## Code Generation\n\nYou can use Gemini models for code generation tasks to generate code snippets, functions, or scripts in various programming languages.\n\n### Example: Generate a Python function\n\n```python\nfrom langchain_google_vertexai import ChatVertexAI\n\nllm = ChatVertexAI(model_name=\"gemini-2.5-flash\", temperature=0.3, max_output_tokens=1000)\n\nprompt = \"Write a Python function that checks if a string is a valid email address.\"\n\ngenerated_code = llm.invoke(prompt)\nprint(generated_code)\n```\n\n### Example: Generate JavaScript code\n\n```python\nfrom langchain_google_vertexai import ChatVertexAI\n\nllm = ChatVertexAI(model_name=\"gemini-2.5-flash\", temperature=0.3, max_output_tokens=1000)\nprompt_js = \"Write a JavaScript function that returns the factorial of a number.\"\n\nprint(llm.invoke(prompt_js))\n```\n\n### Notes\n\n- Adjust `temperature` to control creativity (higher values increase randomness).\n- Use `max_output_tokens` to limit the length of the generated code.\n- Gemini models are well-suited for code generation tasks with advanced understanding of programming concepts.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "An integration package connecting Google VertexAI and LangChain",
"version": "3.0.1",
"project_urls": {
"Release Notes": "https://github.com/langchain-ai/langchain-google/releases",
"Source Code": "https://github.com/langchain-ai/langchain-google/tree/main/libs/vertexai",
"repository": "https://github.com/langchain-ai/langchain-google"
},
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "9313059e1620f95559398ed42cf0b4f564fe33f50356e58c1fb7c92581deb219",
"md5": "52f699233e18f18363b6e63dcdf543c0",
"sha256": "d6a94857a2413c1a81fe8d20f2a40e9ce999120fee93033a00ce50351e24855a"
},
"downloads": -1,
"filename": "langchain_google_vertexai-3.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "52f699233e18f18363b6e63dcdf543c0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0.0,>=3.10.0",
"size": 102204,
"upload_time": "2025-10-23T20:24:45",
"upload_time_iso_8601": "2025-10-23T20:24:45.156426Z",
"url": "https://files.pythonhosted.org/packages/93/13/059e1620f95559398ed42cf0b4f564fe33f50356e58c1fb7c92581deb219/langchain_google_vertexai-3.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "4905a0c19b1e1de578ff88a80108b74d478d79ff3cfdaba11ec076ea04d9979f",
"md5": "01dc206284469fe0db33418a7bc2149a",
"sha256": "f18249bbdd8a3bcff1f38d40ca7ae2132edcb8d7af51896581dd24c835940e69"
},
"downloads": -1,
"filename": "langchain_google_vertexai-3.0.1.tar.gz",
"has_sig": false,
"md5_digest": "01dc206284469fe0db33418a7bc2149a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0.0,>=3.10.0",
"size": 147908,
"upload_time": "2025-10-23T20:24:46",
"upload_time_iso_8601": "2025-10-23T20:24:46.254307Z",
"url": "https://files.pythonhosted.org/packages/49/05/a0c19b1e1de578ff88a80108b74d478d79ff3cfdaba11ec076ea04d9979f/langchain_google_vertexai-3.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-23 20:24:46",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "langchain-ai",
"github_project": "langchain-google",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "langchain-google-vertexai"
}