vertexaitextgenerator.mdx
 1  ---
 2  title: "VertexAITextGenerator"
 3  id: vertexaitextgenerator
 4  slug: "/vertexaitextgenerator"
 5  description: "This component enables text generation using Google Vertex AI generative models."
 6  ---
 7  
 8  # VertexAITextGenerator
 9  
10  This component enables text generation using Google Vertex AI generative models.
11  
12  <div className="key-value-table">
13  
14  |  |  |
15  | --- | --- |
16  | **Mandatory run variables** | `prompt`: A string containing the prompt for the model |
17  | **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 |
18  | **API reference** | [Google Vertex](/reference/integrations-google-vertex) |
19  | **GitHub link** | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/google_vertex |
20  
21  </div>
22  
23  `VertexAITextGenerator` supports `text-bison`, `text-unicorn` and `text-bison-32k` models.
24  
25  ### Parameters Overview
26  
27  `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).
28  
29  Keep in mind that it’s essential to use an account that has access to a project authorized to use Google Vertex AI endpoints.
30  
31  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).
32  
33  ## Usage
34  
35  You need to install `google-vertex-haystack` package to use the  `VertexAITextGenerator`:
36  
37  ```python
38  pip install google-vertex-haystack
39  ```
40  
41  ### On its own
42  
43  Basic usage:
44  
45  ````python
46  from haystack_integrations.components.generators.google_vertex import VertexAITextGenerator
47  
48  generator = VertexAITextGenerator()
49  res = generator.run("Tell me a good interview question for a software engineer.")
50  
51  print(res["replies"][0])
52  
53  >>> **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.
54  >>>
55  >>> **Example:**
56  >>>
57  >>> ```
58  >>> Input: [1, 2, 3, 4, 5], target = 7
59  >>> Output: [[1, 2, 4], [3, 4]]
60  >>> ```
61  >>>
62  >>> **Follow-up:** What if the list contains duplicate numbers?
63  ````
64  
65  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).
66  
67  ```python
68  from haystack_integrations.components.generators.google_vertex import VertexAITextGenerator
69  
70  generator = VertexAITextGenerator(
71      candidate_count=3,
72      temperature=0.2,
73      stop_sequences=["example", "Example"],
74  )
75  res = generator.run("Tell me a good interview question for a software engineer.")
76  
77  for answer in res["replies"]:
78      print(answer)
79  		print("-----")
80  
81  >>> **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?
82  >>> -----
83  >>> **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.
84  >>> -----
85  >>> **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.
86  >>> -----
87  ```