跳转到主要内容

如何添加和使用Google VertexAI 模型?

Quentin avatar
作者:Quentin
超过 6 个月前更新

在EvalsOne/ConsoleX上使用Google VertexAI模型需要遵循以下步骤:

获取service account key

在 Google VertexAI 上,您需要使用在项目中创建的用户管理的服务账号。请按照以下步骤生成并下载 Json 类型的 service account key:

  1. 选择您的项目。

  2. 导航到 “IAM & Admin” -> “服务账户”。

  3. 点击“创建服务账号”并填写相关信息。

  4. 在“密钥”选项卡下,点击“添加密钥”并选择“JSON”格式进行下载。

生成 Base64 编码后的 API 密钥

以下是用于将 service account key 进行编码的脚本。运行前请确保您正确设置 service account key 的路径(如果脚本和 key 在同一文件夹下只需设置为文件名即可)。

import base64
import json

def encode_credentials(file_path):
try:
with open(file_path, 'r') as file:
vertex_credentials = json.load(file)
# Load and encode VertexAI credential
credentials_str = json.dumps(vertex_credentials)
encoded_credentials = base64.urlsafe_b64encode(credentials_str.encode('utf-8')).decode('utf-8')
return encoded_credentials
except FileNotFoundError:
print(f"Error: The file at {file_path} was not found.")
return False
except json.JSONDecodeError:
print("Error: Failed to decode JSON from the file.")
return False

# Generate the encoded credential for usage, make sure to set up the path to your service account key before execution
encoded_credentials = encode_credentials('path-to-your-service-account-key.json')
print(encoded_credentials)

在 EvalsOne/ConsoleX 上集成 Google VertexAI 模型

模型管理中,点击“添加新的集成”,然后供应厂商选择Google Vertex,在弹出界面中提供必要的信息。

  1. Project id:输入您在 GCP 上的项目名称。

  2. Location:处理请求的区域。

  3. Encoded key:遵循之前指引生成的 Base64 编码的 service account key。

你的服务账号是安全的

您在 EvalsOne/ConsoleX 上提供的私密信息(如密钥等)都会得到妥善的加密保护。如果您担心安全性,可以随时删除或停用您的密钥。

参考资料

这是否解答了您的问题?