如何通过Genkit Node.js SDK向Vertex模型传入systemInstruction
关于Genkit Node.js SDK传入Vertex模型systemInstruction的问题解答
Genkit Node.js SDK完全支持将{parts: [{text: ..}]}格式的systemInstruction传入Vertex模型,具体实现只需在调用generate方法时添加对应配置字段即可,修改后的代码示例如下:
export const processDocuemntFlow = defineFlow( { name: 'processDocuemntFlow', inputSchema: z.string(), outputSchema: noteSchema, }, async (docuemntUrl) => { const llmResponse = await generate({ model: gemini15FlashPreview, // 添加符合格式要求的systemInstruction配置 systemInstruction: { parts: [{ text: '这里填写你的系统指令内容' }] }, prompt: [{ text: `prompt` }], output: { format: "json", schema: noteSchema }, config: { temperature: 1, }, }); console.log(JSON.stringify(llmResponse)); return llmResponse.output(); } );
核心修改点是在generate的参数对象中新增systemInstruction字段,传入{parts: [{text: '...'}]}结构的对象即可。这个配置会被Genkit转译为Vertex模型能识别的系统指令格式,直接生效。
内容的提问来源于stack exchange,提问作者d-feverx
相关产品推荐
相关产品推荐

