babaohuang/GeminiProChat

fork sync后fetch failed

shaka0919 opened this issue · 0 comments

How is Gemini Pro Chat deployed?

Vercel

Describe the bug

6天前在Vercel上部署过两个repo并修改了BASE_URL,工作要一切正常,今天sync后所有请求都返回:
[GoogleGenerativeAI Error]: Error fetching from [405 Method Not Allowed]
然后我做了如下测试(提供apikey和api_base_url)

  1. 检查vercel 环境变量,GEMINI_API_KEY和API_BASE_URL都存在
  2. 尝试用curl对generateContent发起请求,可以正常返回聊天结果,状态码200
  3. 下载代码本地运行后发现在请求generate.ts中请求streamGenerateContent时抛出异常,返回错误405
  4. 尝试用thunderclient模拟请求,apikey放进header的x-goog-api-key字段,API返回405
  5. 将apikey放进query参数key,请求streamGenerateContent,返回200和正常内容。

请问是不是我配置的有什么问题?我发现我只有把key放进query参数请求streamGenerateContent才能返回正确内容,apikey放进header一直在返回405,但是generate-ai的包里面似乎都是放在header里请求的。
刚刚又试了一下,直接对generativelanguage.googleapis.com发起请求,apikey放在header的x-goog-api-key里面的话,也可以返回正确内容.

Console Logs

(node:20538) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.
(Use node --trace-deprecation ... to show where the warning was created)
warning:65
TypeError: fetch failed
at /Users/me/Code/GeminiProChat/lib/internal/deps/undici/undici.js:12442:11
at process.processTicksAndRejections (/Users/me/Code/GeminiProChat/lib/internal/process/task_queues.js:95:5)
at async makeRequest (/Users/me/Code/GeminiProChat/node_modules/.pnpm/@fuyun+generative-ai@0.1.3/node_modules/@fuyun/generative-ai/dist/index.mjs:194:20)
at async generateContentStream (file:///Users/me/Code/GeminiProChat/node_modules/.pnpm/@fuyun+generative-ai@0.1.3/node_modules/@fuyun/generative-ai/dist/index.mjs:518:22) {stack: 'TypeError: fetch failed
at node:internal/…s/@fuyun/generative-ai/dist/index.mjs:518:22)', message: '[GoogleGenerativeAI Error]: Error fetching f…:streamGenerateContent?alt=sse: fetch failed'}

Participation

  • I am willing to submit a pull request for this issue.