feat: add customFetch config

This commit is contained in:
Simon
2025-12-24 16:42:31 +08:00
parent 17befe4bab
commit 59fcfaa503
5 changed files with 23 additions and 10 deletions

View File

@@ -6,10 +6,12 @@ import type { InvokeResult, LLMClient, LLMConfig, MacroToolInput, Message, Tool
import { lenientParseMacroToolCall, modelPatch, zodToOpenAITool } from './utils'
export class OpenAIClient implements LLMClient {
config: LLMConfig
config: Required<LLMConfig>
private fetch: typeof globalThis.fetch
constructor(config: LLMConfig) {
constructor(config: Required<LLMConfig>) {
this.config = config
this.fetch = config.customFetch
}
async invoke(
@@ -23,7 +25,7 @@ export class OpenAIClient implements LLMClient {
// 2. Call API
let response: Response
try {
response = await fetch(`${this.config.baseURL}/chat/completions`, {
response = await this.fetch(`${this.config.baseURL}/chat/completions`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',