Skip to main content

Use models like Gemini via Google Gen AI SDK

Project description

Google Gen AI Haystack Integration

PyPI - Version PyPI - Python Version


Table of Contents

Installation

pip install google-genai-haystack

Usage

This integration provides components to use Google's Gemini models via the new Google Gen AI SDK.

Chat Generator

from haystack.dataclasses.chat_message import ChatMessage
from haystack_integrations.components.generators.google_genai import GoogleGenAIChatGenerator

# Initialize the chat generator
chat_generator = GoogleGenAIChatGenerator(model="gemini-2.0-flash")

# Generate a response
messages = [ChatMessage.from_user("Tell me about the future of AI")]
response = chat_generator.run(messages=messages)
print(response["replies"][0].text)

Streaming Chat Generator

from haystack.dataclasses.chat_message import ChatMessage
from haystack.dataclasses import StreamingChunk
from haystack_integrations.components.generators.google_genai import GoogleGenAIChatGenerator

def streaming_callback(chunk: StreamingChunk):
    print(chunk.content, end='', flush=True)

# Initialize with streaming callback
chat_generator = GoogleGenAIChatGenerator(
    model="gemini-2.0-flash",
    streaming_callback=streaming_callback
)

# Generate a streaming response
messages = [ChatMessage.from_user("Write a short story")]
response = chat_generator.run(messages=messages)
# Text will stream in real-time via the callback

License

google-genai-haystack is distributed under the terms of the Apache-2.0 license.

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

google_genai_haystack-1.0.0.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

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

google_genai_haystack-1.0.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file google_genai_haystack-1.0.0.tar.gz.

File metadata

  • Download URL: google_genai_haystack-1.0.0.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for google_genai_haystack-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8ba9464f63956fcab09fb89a779ee969df0b7dd51b805ff7fbe232f73e6afe8e
MD5 afcfb67cae11e91f0f570b53889a8d77
BLAKE2b-256 ede0adef6b31e22911ef6ca34fab0d0b6826b3a6f8b0b28d5faed433de8cb0d8

See more details on using hashes here.

File details

Details for the file google_genai_haystack-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for google_genai_haystack-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ebe4c558ed6469ec194567793d08c54b731675b549fad69442f7112d581ef920
MD5 c98a109039a6149e26e0ae62f877995b
BLAKE2b-256 309d37b1195773f070d4ced0f86d0c43a9065645250fb1832e83a7d8b79feed3

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