| 439 | timeout: number, |
| 440 | ): Promise<string> { |
| 441 | const response = await axios.post( |
| 442 | `${normalizedBaseUrl(baseUrl)}/v1beta/models/${encodeURIComponent(model)}:generateContent?key=${encodeURIComponent(apiKey)}`, |
| 443 | { contents: [{ role: "user", parts: [{ text: input }] }] }, |
| 444 | { headers: { "Content-Type": "application/json" }, timeout }, |
| 445 | ); |
| 446 | const content = response.data?.candidates?.[0]?.content?.parts |
| 447 | ?.map((part: any) => part?.text ?? "") |
| 448 | .join("") |
| 449 | .trim(); |
| 450 | if (!content) throw new Error("Gemini 返回内容为空"); |
| 451 | return content; |
| 452 | } |
| 453 | |
| 454 | async function callAnthropic( |
| 455 | apiKey: string, |
| 456 | baseUrl: string, |
| 457 | model: string, |
| 458 | input: string, |
| 459 | timeout: number, |
| 460 | ): Promise<string> { |
| 461 | const response = await axios.post( |
| 462 | `${normalizedBaseUrl(baseUrl)}/v1/messages`, |
| 463 | { model, max_tokens: 2000, messages: [{ role: "user", content: input }] }, |
| 464 | { |
| 465 | headers: { |
| 466 | "x-api-key": apiKey, |
| 467 | "anthropic-version": "2023-06-01", |
| 468 | "Content-Type": "application/json", |
| 469 | }, |