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

llama_index_voice_agents_gemini_live-0.2.0.tar.gz (7.0 kB view details)

Uploaded Source

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.2.0.tar.gz.

File metadata

File hashes

Hashes for llama_index_voice_agents_gemini_live-0.2.0.tar.gz
Algorithm Hash digest
SHA256 177553b08805938d6364a4181a6aed26275dc5d510538cc7d5b0ff0ad1755a09
MD5 dd286b12ecceb86d1458eac7bca4fb31
BLAKE2b-256 a50cddacfc963a69055e15ca20447bf12fc6d5e613102fcdc798733bfe53afe2

See more details on using hashes here.

File details

Details for the file llama_index_voice_agents_gemini_live-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_voice_agents_gemini_live-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ef2378c165ed5a769bd5ae299c4f765147ed915ffb84d2ef7d4eb0230cb8bd5c
MD5 b6b26d91956f75e2cf4faaf98c5e9acf
BLAKE2b-256 ba9cc10bad194dfd732b4dc5e3ffe54f724055f5b83fc086950b0378949bcfcb

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