VertexAITextGenerator
此组件支持使用 Google Vertex AI 生成模型进行文本生成。
| 强制运行变量 | “prompt”: 包含模型提示的字符串 |
| 输出变量 | “replies”:一个包含模型生成的答案的字符串列表 ”safety_attributes”:一个包含安全属性分数的字典 ”citations”:一个包含归因引用的字典列表 |
| API 参考 | Google Vertex |
| GitHub 链接 | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/google_vertex |
VertexAITextGenerator 支持text-bison, text-unicorn 和text-bison-32k 模型。
参数概述
VertexAITextGenerator 使用 Google Cloud 应用程序默认凭据 (ADC) 进行身份验证。有关如何设置 ADC 的更多信息,请参阅 官方文档。
请记住,使用有权访问已授权使用 Google Vertex AI 端点的项目的帐户至关重要。
您可以在GCP 资源管理器中找到您的项目 ID,或者通过在终端中运行gcloud projects list 来在本地找到。有关 gcloud CLI 的更多信息,请参阅其官方文档。
用法
您需要首先安装google-vertex-haystack 包以使用VertexAITextGenerator:
pip install google-vertex-haystack
单独使用
基本用法
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?
您还可以设置其他参数,例如生成的答案数量、控制随机性的温度以及停止生成的停止序列。有关可能参数的完整列表,请参阅 TextGenerationModel.predict() 的文档。
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.
>>> -----
更新于 大约 1 年前
