Name | llama-index-llms-google-genai JSON |
Version |
0.2.5
JSON |
| download |
home_page | None |
Summary | llama-index llms google genai integration |
upload_time | 2025-07-16 09:49:22 |
maintainer | None |
docs_url | None |
author | None |
requires_python | <4.0,>=3.9 |
license | None |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# LlamaIndex Llms Integration: Google GenAI
## Installation
1. Install the required Python packages:
```bash
%pip install llama-index-llms-google-genai
```
2. Set the Google API key as an environment variable:
```bash
%env GOOGLE_API_KEY=your_api_key_here
```
## Usage
### Basic Content Generation
To generate a poem using the Gemini model, use the following code:
```python
from llama_index.llms.google_genai import GoogleGenAI
llm = GoogleGenAI(model="gemini-2.0-flash")
resp = llm.complete("Write a poem about a magic backpack")
print(resp)
```
### Chat with Messages
To simulate a conversation, send a list of messages:
```python
from llama_index.core.llms import ChatMessage
from llama_index.llms.google_genai import GoogleGenAI
messages = [
ChatMessage(role="user", content="Hello friend!"),
ChatMessage(role="assistant", content="Yarr what is shakin' matey?"),
ChatMessage(
role="user", content="Help me decide what to have for dinner."
),
]
llm = GoogleGenAI(model="gemini-2.0-flash")
resp = llm.chat(messages)
print(resp)
```
### Streaming Responses
To stream content responses in real-time:
```python
from llama_index.llms.google_genai import GoogleGenAI
llm = GoogleGenAI(model="gemini-2.0-flash")
resp = llm.stream_complete(
"The story of Sourcrust, the bread creature, is really interesting. It all started when..."
)
for r in resp:
print(r.text, end="")
```
To stream chat responses:
```python
from llama_index.core.llms import ChatMessage
from llama_index.llms.google_genai import GoogleGenAI
llm = GoogleGenAI(model="gemini-2.0-flash")
messages = [
ChatMessage(role="user", content="Hello friend!"),
ChatMessage(role="assistant", content="Yarr what is shakin' matey?"),
ChatMessage(
role="user", content="Help me decide what to have for dinner."
),
]
resp = llm.stream_chat(messages)
```
### Specific Model Usage
To use a specific model, you can configure it like this:
```python
from llama_index.llms.google_genai import GoogleGenAI
llm = GoogleGenAI(model="models/gemini-pro")
resp = llm.complete("Write a short, but joyous, ode to LlamaIndex")
print(resp)
```
### Asynchronous API
To use the asynchronous completion API:
```python
from llama_index.llms.google_genai import GoogleGenAI
llm = GoogleGenAI(model="models/gemini-pro")
resp = await llm.acomplete("Llamas are famous for ")
print(resp)
```
For asynchronous streaming of responses:
```python
resp = await llm.astream_complete("Llamas are famous for ")
async for chunk in resp:
print(chunk.text, end="")
```
Raw data
{
"_id": null,
"home_page": null,
"name": "llama-index-llms-google-genai",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Your Name <you@example.com>",
"download_url": "https://files.pythonhosted.org/packages/2c/ce/0be30bf12300ddeb7768d3c99dc20c1092e08c5bc40fb889f8db8b0ae27c/llama_index_llms_google_genai-0.2.5.tar.gz",
"platform": null,
"description": "# LlamaIndex Llms Integration: Google GenAI\n\n## Installation\n\n1. Install the required Python packages:\n\n ```bash\n %pip install llama-index-llms-google-genai\n ```\n\n2. Set the Google API key as an environment variable:\n\n ```bash\n %env GOOGLE_API_KEY=your_api_key_here\n ```\n\n## Usage\n\n### Basic Content Generation\n\nTo generate a poem using the Gemini model, use the following code:\n\n```python\nfrom llama_index.llms.google_genai import GoogleGenAI\n\nllm = GoogleGenAI(model=\"gemini-2.0-flash\")\nresp = llm.complete(\"Write a poem about a magic backpack\")\nprint(resp)\n```\n\n### Chat with Messages\n\nTo simulate a conversation, send a list of messages:\n\n```python\nfrom llama_index.core.llms import ChatMessage\nfrom llama_index.llms.google_genai import GoogleGenAI\n\nmessages = [\n ChatMessage(role=\"user\", content=\"Hello friend!\"),\n ChatMessage(role=\"assistant\", content=\"Yarr what is shakin' matey?\"),\n ChatMessage(\n role=\"user\", content=\"Help me decide what to have for dinner.\"\n ),\n]\n\nllm = GoogleGenAI(model=\"gemini-2.0-flash\")\nresp = llm.chat(messages)\nprint(resp)\n```\n\n### Streaming Responses\n\nTo stream content responses in real-time:\n\n```python\nfrom llama_index.llms.google_genai import GoogleGenAI\n\nllm = GoogleGenAI(model=\"gemini-2.0-flash\")\nresp = llm.stream_complete(\n \"The story of Sourcrust, the bread creature, is really interesting. It all started when...\"\n)\nfor r in resp:\n print(r.text, end=\"\")\n```\n\nTo stream chat responses:\n\n```python\nfrom llama_index.core.llms import ChatMessage\nfrom llama_index.llms.google_genai import GoogleGenAI\n\nllm = GoogleGenAI(model=\"gemini-2.0-flash\")\nmessages = [\n ChatMessage(role=\"user\", content=\"Hello friend!\"),\n ChatMessage(role=\"assistant\", content=\"Yarr what is shakin' matey?\"),\n ChatMessage(\n role=\"user\", content=\"Help me decide what to have for dinner.\"\n ),\n]\nresp = llm.stream_chat(messages)\n```\n\n### Specific Model Usage\n\nTo use a specific model, you can configure it like this:\n\n```python\nfrom llama_index.llms.google_genai import GoogleGenAI\n\nllm = GoogleGenAI(model=\"models/gemini-pro\")\nresp = llm.complete(\"Write a short, but joyous, ode to LlamaIndex\")\nprint(resp)\n```\n\n### Asynchronous API\n\nTo use the asynchronous completion API:\n\n```python\nfrom llama_index.llms.google_genai import GoogleGenAI\n\nllm = GoogleGenAI(model=\"models/gemini-pro\")\nresp = await llm.acomplete(\"Llamas are famous for \")\nprint(resp)\n```\n\nFor asynchronous streaming of responses:\n\n```python\nresp = await llm.astream_complete(\"Llamas are famous for \")\nasync for chunk in resp:\n print(chunk.text, end=\"\")\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "llama-index llms google genai integration",
"version": "0.2.5",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "8a96cc64aae80826254c95f9b5360ee7bc54d8939e58229a8db7e366cd36c4f4",
"md5": "28877528ad34d9ecff929da412296d5e",
"sha256": "29cdc679f073cfbcd9098f51a678611b405638246660f18707849b4df4a02146"
},
"downloads": -1,
"filename": "llama_index_llms_google_genai-0.2.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "28877528ad34d9ecff929da412296d5e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 11701,
"upload_time": "2025-07-16T09:49:21",
"upload_time_iso_8601": "2025-07-16T09:49:21.970792Z",
"url": "https://files.pythonhosted.org/packages/8a/96/cc64aae80826254c95f9b5360ee7bc54d8939e58229a8db7e366cd36c4f4/llama_index_llms_google_genai-0.2.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "2cce0be30bf12300ddeb7768d3c99dc20c1092e08c5bc40fb889f8db8b0ae27c",
"md5": "424ae4e067c81a04f9023ab9d3bf76bc",
"sha256": "17c2b84ca2299c1cb41d514b763c23b65104617fef3e991774cadadd37f128ad"
},
"downloads": -1,
"filename": "llama_index_llms_google_genai-0.2.5.tar.gz",
"has_sig": false,
"md5_digest": "424ae4e067c81a04f9023ab9d3bf76bc",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 11325,
"upload_time": "2025-07-16T09:49:22",
"upload_time_iso_8601": "2025-07-16T09:49:22.766971Z",
"url": "https://files.pythonhosted.org/packages/2c/ce/0be30bf12300ddeb7768d3c99dc20c1092e08c5bc40fb889f8db8b0ae27c/llama_index_llms_google_genai-0.2.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-16 09:49:22",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "llama-index-llms-google-genai"
}