|
3 | 3 | [](https://pypi.org/project/google-genai-haystack)
|
4 | 4 | [](https://pypi.org/project/google-genai-haystack)
|
5 | 5 |
|
6 |
| ------ |
| 6 | +- [Integration page](https://haystack.deepset.ai/integrations/google-genai) |
| 7 | +- [Changelog](https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/google_genai/CHANGELOG.md) |
7 | 8 |
|
8 |
| -**Table of Contents** |
| 9 | +--- |
9 | 10 |
|
10 |
| -- [Installation](#installation) |
11 |
| -- [Usage](#usage) |
12 |
| -- [License](#license) |
| 11 | +## Contributing |
13 | 12 |
|
14 |
| -## Installation |
| 13 | +Refer to the general [Contribution Guidelines](https://github.com/deepset-ai/haystack-core-integrations/blob/main/CONTRIBUTING.md). |
15 | 14 |
|
16 |
| -```console |
17 |
| -pip install google-genai-haystack |
18 |
| -``` |
19 |
| - |
20 |
| -## Usage |
21 |
| - |
22 |
| -This integration provides components to use Google's Gemini models via the new Google Gen AI SDK. |
23 |
| - |
24 |
| -### Chat Generator |
25 |
| - |
26 |
| -```python |
27 |
| -from haystack.dataclasses.chat_message import ChatMessage |
28 |
| -from haystack_integrations.components.generators.google_genai import GoogleGenAIChatGenerator |
29 |
| - |
30 |
| -# Initialize the chat generator |
31 |
| -chat_generator = GoogleGenAIChatGenerator(model="gemini-2.0-flash") |
32 |
| - |
33 |
| -# Generate a response |
34 |
| -messages = [ChatMessage.from_user("Tell me about the future of AI")] |
35 |
| -response = chat_generator.run(messages=messages) |
36 |
| -print(response["replies"][0].text) |
37 |
| -``` |
38 |
| - |
39 |
| -### Streaming Chat Generator |
40 |
| - |
41 |
| -```python |
42 |
| -from haystack.dataclasses.chat_message import ChatMessage |
43 |
| -from haystack.dataclasses import StreamingChunk |
44 |
| -from haystack_integrations.components.generators.google_genai import GoogleGenAIChatGenerator |
45 |
| - |
46 |
| -def streaming_callback(chunk: StreamingChunk): |
47 |
| - print(chunk.content, end='', flush=True) |
48 |
| - |
49 |
| -# Initialize with streaming callback |
50 |
| -chat_generator = GoogleGenAIChatGenerator( |
51 |
| - model="gemini-2.0-flash", |
52 |
| - streaming_callback=streaming_callback |
53 |
| -) |
54 |
| - |
55 |
| -# Generate a streaming response |
56 |
| -messages = [ChatMessage.from_user("Write a short story")] |
57 |
| -response = chat_generator.run(messages=messages) |
58 |
| -# Text will stream in real-time via the callback |
59 |
| -``` |
60 |
| - |
61 |
| -## License |
62 |
| - |
63 |
| -`google-genai-haystack` is distributed under the terms of the [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) license. |
| 15 | +To run integration tests locally, you need to export the `GOOGLE_API_KEY` environment variable. |
0 commit comments