问题定位
使用Gemini1.0 Pro API代码
执行报错
node:internal/process/promises:289
triggerUncaughtException(err, true /* fromPromise */);
^
TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11372:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
验证代理配置
应是fetch没有使用代理
解决方案
安装undici库
加入代码
const { setGlobalDispatcher, ProxyAgent } = require("undici");
const dispatcher = new ProxyAgent({ uri: new URL(process.env.https_proxy).toString() });
setGlobalDispatcher(dispatcher);
再次执行,成功得到回复