@ core-ai/ google- 顶点
Vertex AI供应商软件包上的谷歌 @core-ai/core-ai它使用 @google/genai vertex AI模式中的客户端并共享聊天、嵌入、图像生成、结构化输出和推理行为 @core-ai/google-genai。 。 。 .
安装
npm install @core-ai/core-ai @core-ai/google-vertex zod
使用量
import { generate } from '@core-ai/core-ai';
import { createGoogleVertex } from '@core-ai/google-vertex';
const googleVertex = createGoogleVertex({
projectId: process.env.GOOGLE_VERTEX_PROJECT,
region: 'europe-west1',
});
const model = googleVertex.chatModel('gemini-2.5-flash');
const result = await generate({
model,
messages: [{ role: 'user', content: 'Hello!' }],
});
console.log(result.content);
认证
默认情况下,提供者使用 Google 应用程序默认证书( ADC)数字 :
const googleVertex = createGoogleVertex({
projectId: process.env.GOOGLE_VERTEX_PROJECT,
region: 'europe-west1',
});
用明确的服务账户认证, 解析其 JSON 密钥, 并将其传递为 credentials数字 :
const rawCredentials = process.env.GOOGLE_APPLICATION_CREDENTIALS_JSON;
const credentialsJson = rawCredentials?.trim().startsWith('{')
? rawCredentials
: Buffer.from(rawCredentials ?? '', 'base64').toString('utf8');
const googleVertex = createGoogleVertex({
projectId: process.env.GOOGLE_VERTEX_PROJECT,
region: 'europe-west1',
credentials: JSON.parse(credentialsJson),
});
您也可以输入预配置 GoogleGenAI 客户端 :
import { GoogleGenAI } from '@google/genai';
const googleVertex = createGoogleVertex({
client: new GoogleGenAI({
vertexai: true,
project: 'my-project',
location: 'europe-west1',
}),
});
模式和区域
将 Vertex AI 型号ID 传到相应的型号工厂:
const chat = googleVertex.chatModel('gemini-2.5-flash');
const embeddings = googleVertex.embeddingModel('gemini-embedding-001');
const image = googleVertex.imageModel('gemini-2.5-flash-image');
模型提供情况因区域而异。 一个供应商实例针对一个区域,因此在不同地点托管模型时创建单独的供应商.
图像生成
import { generateImage } from '@core-ai/core-ai';
const result = await generateImage({
model: googleVertex.imageModel('gemini-2.5-flash-image'),
prompt: 'A watercolor robot in a mountain cabin at sunrise',
size: '1024x1024',
});
console.log(result.images[0]?.base64);
双子座图像模型使用本土多模式生成并返回基础64图像 数据.
供应商的选择和能力
这个提供者分享其模式行为 @core-ai/google-genai选项 google。 。 。 . @core-ai/google-vertex 再导出适用的提供者-选项计划、能力助手和推理元数据类型.