mirror of
https://github.com/deepset-ai/haystack.git
synced 2026-02-07 07:22:03 +00:00
* Update documentation and remove unused assets. Enhanced the 'agents' and 'components' sections with clearer descriptions and examples. Removed obsolete images and updated links for better navigation. Adjusted formatting for consistency across various documentation pages. * remove dependency * address comments * delete more empty pages * broken link * unduplicate headings * alphabetical components nav
83 lines
3.7 KiB
Plaintext
83 lines
3.7 KiB
Plaintext
---
|
||
title: "VertexAITextGenerator"
|
||
id: vertexaitextgenerator
|
||
slug: "/vertexaitextgenerator"
|
||
description: "This component enables text generation using Google Vertex AI generative models."
|
||
---
|
||
|
||
# VertexAITextGenerator
|
||
|
||
This component enables text generation using Google Vertex AI generative models.
|
||
|
||
| | |
|
||
| --- | --- |
|
||
| **Mandatory run variables** | “prompt”: A string containing the prompt for the model |
|
||
| **Output variables** | “replies”: A list of strings containing answers generated by the model <br /> <br />”safety_attributes”: A dictionary containing scores for safety attributes <br /> <br />”citations”: A list of dictionaries containing grounding citations |
|
||
| **API reference** | [Google Vertex](/reference/integrations-google-vertex) |
|
||
| **GitHub link** | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/google_vertex |
|
||
|
||
`VertexAITextGenerator` supports `text-bison`, `text-unicorn` and `text-bison-32k` models.
|
||
|
||
### Parameters Overview
|
||
|
||
`VertexAITextGenerator` uses Google Cloud Application Default Credentials (ADCs) for authentication. For more information on how to set up ADCs, see the [official documentation](https://cloud.google.com/docs/authentication/provide-credentials-adc).
|
||
|
||
Keep in mind that it’s essential to use an account that has access to a project authorized to use Google Vertex AI endpoints.
|
||
|
||
You can find your project ID in the [GCP resource manager](https://console.cloud.google.com/cloud-resource-manager) or locally by running `gcloud projects list` in your terminal. For more info on the gcloud CLI, see its [official documentation](https://cloud.google.com/cli).
|
||
|
||
## Usage
|
||
|
||
You need to install `google-vertex-haystack` package to use the `VertexAITextGenerator`:
|
||
|
||
```python
|
||
pip install google-vertex-haystack
|
||
```
|
||
|
||
### On its own
|
||
|
||
Basic usage:
|
||
|
||
````python
|
||
from haystack_integrations.components.generators.google_vertex import VertexAITextGenerator
|
||
|
||
generator = VertexAITextGenerator()
|
||
res = generator.run("Tell me a good interview question for a software engineer.")
|
||
|
||
print(res["replies"][0])
|
||
|
||
>>> **Question:** You are given a list of integers and a target sum. Find all unique combinations of numbers in the list that add up to the target sum.
|
||
>>>
|
||
>>> **Example:**
|
||
>>>
|
||
>>> ```
|
||
>>> Input: [1, 2, 3, 4, 5], target = 7
|
||
>>> Output: [[1, 2, 4], [3, 4]]
|
||
>>> ```
|
||
>>>
|
||
>>> **Follow-up:** What if the list contains duplicate numbers?
|
||
````
|
||
|
||
You can also set other parameters like the number of answers generated, temperature to control the randomness, and stop sequences to stop generation. For a full list of possible parameters, see the documentation of [`TextGenerationModel.predict()`](https://cloud.google.com/python/docs/reference/aiplatform/latest/vertexai.language_models.TextGenerationModel#vertexai_language_models_TextGenerationModel_predict).
|
||
|
||
```python
|
||
from haystack_integrations.components.generators.google_vertex import VertexAITextGenerator
|
||
|
||
generator = VertexAITextGenerator(
|
||
candidate_count=3,
|
||
temperature=0.2,
|
||
stop_sequences=["example", "Example"],
|
||
)
|
||
res = generator.run("Tell me a good interview question for a software engineer.")
|
||
|
||
for answer in res["replies"]:
|
||
print(answer)
|
||
print("-----")
|
||
|
||
>>> **Question:** You are given a list of integers, and you need to find the longest increasing subsequence. What is the most efficient algorithm to solve this problem?
|
||
>>> -----
|
||
>>> **Question:** You are given a list of integers and a target sum. Find all unique combinations in the list that sum up to the target sum. The same number can be used multiple times in a combination.
|
||
>>> -----
|
||
>>> **Question:** You are given a list of integers and a target sum. Find all unique combinations of numbers in the list that add up to the target sum.
|
||
>>> -----
|
||
``` |