LlamaIndex x Gemini Live integration
Project description
LlamaIndex x Gemini Live Integration
Integration between LlamaIndex and Google Gemini Live. Install the integration with:
pip install llama-index-voice-agents-gemini-live
And test it with the following minimal example:
from llama_index.voice_agents.gemini_live import GeminiLiveVoiceAgent
from llama_index.core.tools import FunctionTool
from llama_index.core.voice_agents import BaseVoiceAgentEvent
from llama_index.core.llms import ChatMessage, TextBlock
from typing import List
import random
import json
# use filter functions to export messages and events without your terminal being swamped by base64-encoded audio bytes :)
def filter_events(
events: List[BaseVoiceAgentEvent],
) -> List[BaseVoiceAgentEvent]:
evs = []
for event in events:
if not "audio" in event.type_t:
evs.append(event)
return evs
def filter_messages(messages: List[ChatMessage]) -> List[ChatMessage]:
msgs = []
for message in messages:
msg = ChatMessage(role=message.role, blocks=[])
for b in message.blocks:
if isinstance(b, TextBlock):
msg.blocks.append(b)
if len(msg.blocks) > 0:
msgs.append(msg)
return msgs
def get_weather(location: str) -> dict:
"""Fetch weather data for a given location."""
return json.dumps(
{
"location": location,
"temperature_c": round(random.uniform(15, 30), 1),
"humidity_percent": random.randint(40, 90),
"wind_speed_kmh": round(random.uniform(5, 25), 1),
"precipitation_probability_percent": random.randint(0, 100),
},
indent=4,
)
weather_tool = FunctionTool.from_defaults(
fn=get_weather,
name="get_weather",
description="Get the weather at a given location",
)
async def main():
conversation = GeminiLiveVoiceAgent(tools=[weather_tool])
await conversation.start()
if conversation._quitflag:
print("Events")
print(conversation.export_events(filter=filter_events))
print()
print("Messages")
print(conversation.export_messages(filter=filter_messages))
if __name__ == "__main__":
import asyncio
asyncio.run(main())
Remember that:
- You have to either set
GOOGLE_API_KEYas env variable or pass theapi_keywhen initializingGoogleGeminiVoiceAgent - You have to start the conversation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llama_index_voice_agents_gemini_live-0.2.1.tar.gz.
File metadata
- Download URL: llama_index_voice_agents_gemini_live-0.2.1.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
424da8c628c6d740bbbcd025e5ebdc7dba2a5f9a6c789bb942d2e83b2ef00763
|
|
| MD5 |
34cce5ba6f9a0250df6e5193f25a2f29
|
|
| BLAKE2b-256 |
edf9db40ed05d8027fbc61d9f3be7c29f843a49a7e3858cc8ea092236aae6922
|
File details
Details for the file llama_index_voice_agents_gemini_live-0.2.1-py3-none-any.whl.
File metadata
- Download URL: llama_index_voice_agents_gemini_live-0.2.1-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4152ebfc97211825eb1750610dc8fd3c58c12c3d7c6374291a0f8cddb2bab478
|
|
| MD5 |
c6401316314a5d82b2e760de8cb180c2
|
|
| BLAKE2b-256 |
11cdf7070ec12829e2bb32809f88bb9c617485606b1f69b1ac6970511b18ff87
|