Name | llama-index-llms-gemini JSON |
Version |
0.4.0
JSON |
| download |
home_page | None |
Summary | llama-index llms gemini integration |
upload_time | 2024-11-18 00:43:10 |
maintainer | None |
docs_url | None |
author | Your Name |
requires_python | <4.0,>=3.9 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# LlamaIndex Llms Integration: Gemini
## Installation
1. Install the required Python packages:
```bash
%pip install llama-index-llms-gemini
!pip install -q llama-index google-generativeai
```
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.gemini import Gemini
resp = Gemini().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.gemini import Gemini
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 = Gemini().chat(messages)
print(resp)
```
### Streaming Responses
To stream content responses in real-time:
```python
from llama_index.llms.gemini import Gemini
llm = Gemini()
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.llms.gemini import Gemini
from llama_index.core.llms import ChatMessage
llm = Gemini()
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)
```
### Using Other Models
To find suitable models available in the Gemini model site:
```python
import google.generativeai as genai
for m in genai.list_models():
if "generateContent" in m.supported_generation_methods:
print(m.name)
```
### Specific Model Usage
To use a specific model, you can configure it like this:
```python
from llama_index.llms.gemini import Gemini
llm = Gemini(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.gemini import Gemini
llm = Gemini()
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="")
```
### LLM Implementation example
https://docs.llamaindex.ai/en/stable/examples/llm/gemini/
Raw data
{
"_id": null,
"home_page": null,
"name": "llama-index-llms-gemini",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Your Name",
"author_email": "you@example.com",
"download_url": "https://files.pythonhosted.org/packages/7d/3b/90a43f479a50cfb772945518c28766727be945f265be8bb5d4969757c9d3/llama_index_llms_gemini-0.4.0.tar.gz",
"platform": null,
"description": "# LlamaIndex Llms Integration: Gemini\n\n## Installation\n\n1. Install the required Python packages:\n\n ```bash\n %pip install llama-index-llms-gemini\n !pip install -q llama-index google-generativeai\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.gemini import Gemini\n\nresp = Gemini().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.gemini import Gemini\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]\nresp = Gemini().chat(messages)\nprint(resp)\n```\n\n### Streaming Responses\n\nTo stream content responses in real-time:\n\n```python\nfrom llama_index.llms.gemini import Gemini\n\nllm = Gemini()\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.llms.gemini import Gemini\nfrom llama_index.core.llms import ChatMessage\n\nllm = Gemini()\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### Using Other Models\n\nTo find suitable models available in the Gemini model site:\n\n```python\nimport google.generativeai as genai\n\nfor m in genai.list_models():\n if \"generateContent\" in m.supported_generation_methods:\n print(m.name)\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.gemini import Gemini\n\nllm = Gemini(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.gemini import Gemini\n\nllm = Gemini()\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\n### LLM Implementation example\n\nhttps://docs.llamaindex.ai/en/stable/examples/llm/gemini/\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "llama-index llms gemini integration",
"version": "0.4.0",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6b39ad724a5f4c59cac9634068736520864714fb3a00f49650fa4841df705bdf",
"md5": "6a3b41818e4e58bf35942927f39e1ed3",
"sha256": "b7369dfb979c136482c06b8b24c3cedaa74aa92210407491ae1fff761e1f85c0"
},
"downloads": -1,
"filename": "llama_index_llms_gemini-0.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6a3b41818e4e58bf35942927f39e1ed3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 6127,
"upload_time": "2024-11-18T00:43:09",
"upload_time_iso_8601": "2024-11-18T00:43:09.503065Z",
"url": "https://files.pythonhosted.org/packages/6b/39/ad724a5f4c59cac9634068736520864714fb3a00f49650fa4841df705bdf/llama_index_llms_gemini-0.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7d3b90a43f479a50cfb772945518c28766727be945f265be8bb5d4969757c9d3",
"md5": "931130b810f07aeb7f47d313cabf0c0e",
"sha256": "a1fa5a38eddbbe5313dfa9528a8fb38698d05b2f5ab33ad09710ea61719d491e"
},
"downloads": -1,
"filename": "llama_index_llms_gemini-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "931130b810f07aeb7f47d313cabf0c0e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 5431,
"upload_time": "2024-11-18T00:43:10",
"upload_time_iso_8601": "2024-11-18T00:43:10.461239Z",
"url": "https://files.pythonhosted.org/packages/7d/3b/90a43f479a50cfb772945518c28766727be945f265be8bb5d4969757c9d3/llama_index_llms_gemini-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-18 00:43:10",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "llama-index-llms-gemini"
}