510 - 《手撕源码 35:Gemini-Search》

发布于 2025年1月5日

1、效果见图,感觉够用。

2、关键代码就 20 行。GoogleGenerativeAI 自带 google_search 的 tool,所以无比简单,都没啥好解释的。

import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY);
const model = genAI.getGenerativeModel({
  model: "gemini-2.0-flash-exp",
  generationConfig: {
    temperature: 0.9,
    topP: 1,
    topK: 1,
    maxOutputTokens: 2048,
  },
});
const chat = model.startCh

内容预览已结束

此内容需要会员权限。请先登录以查看完整内容。