Skip to main content

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_KEY as env variable or pass the api_key when initializing GoogleGeminiVoiceAgent
  • You have to start the conversation

Project details


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

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file llama_index_voice_agents_gemini_live-0.1.0b0.tar.gz.

File metadata

File hashes

Hashes for llama_index_voice_agents_gemini_live-0.1.0b0.tar.gz
Algorithm Hash digest
SHA256 86ad6e447e79ea5168dedee7cdf5ddc40d9c1e3a417f620f4fe5ce890e3837b0
MD5 c895d83859cb8ffc6515f6a7ee5c0bc4
BLAKE2b-256 e85c04bc2eaf77a069a2253c96bd56664f003457e1dab3a9e051de27e0517cd1

See more details on using hashes here.

File details

Details for the file llama_index_voice_agents_gemini_live-0.1.0b0-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_voice_agents_gemini_live-0.1.0b0-py3-none-any.whl
Algorithm Hash digest
SHA256 b6ef23ed5c6ebb95d008ea8b1727b15bbcb3b178b5492487324b39e42609e14d
MD5 f42eec04e94a4350730efaee2a17080b
BLAKE2b-256 42d4b5d077dce19be733f60ac45a2c1d2819b9c1b00f1df697971eeb82b36753

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page