-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
♻️ refactor: Remove redundant payload remapping in client-fetch #5267
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,90 +82,25 @@ interface CreateAssistantMessageStream extends FetchSSEOptions { | |
* **Note**: if you try to fetch directly, use `fetchOnClient` instead. | ||
*/ | ||
export function initializeWithClientStore(provider: string, payload: any) { | ||
// add auth payload | ||
/** | ||
* Since PR #5250, we no longer need to map the provider options here. | ||
* Provider options mapping is now be done at `getProviderAuthPayload`. | ||
* @see {@link https://github.com/lobehub/lobe-chat/pull/5250} | ||
* @see {@file src/auth/provider.ts#getProviderAuthPayload} | ||
*/ | ||
const providerAuthPayload = getProviderAuthPayload(provider); | ||
const commonOptions = { | ||
// Some provider base openai sdk, so enable it run on browser | ||
// Allow OpenAI SDK to run on browser | ||
dangerouslyAllowBrowser: true, | ||
}; | ||
let providerOptions = {}; | ||
|
||
switch (provider) { | ||
default: | ||
case ModelProvider.OpenAI: { | ||
providerOptions = { | ||
baseURL: providerAuthPayload?.baseURL, | ||
}; | ||
break; | ||
} | ||
case ModelProvider.Azure: { | ||
providerOptions = { | ||
apiKey: providerAuthPayload?.apiKey, | ||
apiVersion: providerAuthPayload?.azureApiVersion, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. apiVersion 应该也要透传吧 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已修改 b4ab60c |
||
}; | ||
break; | ||
} | ||
case ModelProvider.Google: { | ||
providerOptions = { | ||
baseURL: providerAuthPayload?.baseURL, | ||
}; | ||
break; | ||
} | ||
case ModelProvider.Bedrock: { | ||
if (providerAuthPayload?.apiKey) { | ||
providerOptions = { | ||
accessKeyId: providerAuthPayload?.awsAccessKeyId, | ||
accessKeySecret: providerAuthPayload?.awsSecretAccessKey, | ||
region: providerAuthPayload?.awsRegion, | ||
sessionToken: providerAuthPayload?.awsSessionToken, | ||
}; | ||
} | ||
break; | ||
} | ||
case ModelProvider.Ollama: { | ||
providerOptions = { | ||
baseURL: providerAuthPayload?.baseURL, | ||
}; | ||
break; | ||
} | ||
case ModelProvider.Perplexity: { | ||
providerOptions = { | ||
apikey: providerAuthPayload?.apiKey, | ||
baseURL: providerAuthPayload?.baseURL, | ||
}; | ||
break; | ||
} | ||
case ModelProvider.Anthropic: { | ||
providerOptions = { | ||
baseURL: providerAuthPayload?.baseURL, | ||
}; | ||
break; | ||
} | ||
case ModelProvider.Groq: { | ||
providerOptions = { | ||
apikey: providerAuthPayload?.apiKey, | ||
baseURL: providerAuthPayload?.baseURL, | ||
}; | ||
break; | ||
} | ||
case ModelProvider.Cloudflare: { | ||
providerOptions = { | ||
apikey: providerAuthPayload?.apiKey, | ||
baseURLOrAccountID: providerAuthPayload?.cloudflareBaseURLOrAccountID, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 还有 baseURLOrAccountID There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已修改 b4ab60c |
||
}; | ||
break; | ||
} | ||
} | ||
|
||
/** | ||
* Configuration override order: | ||
* payload -> providerOptions -> providerAuthPayload -> commonOptions | ||
* payload -> providerAuthPayload -> commonOptions | ||
*/ | ||
return AgentRuntime.initializeWithProviderOptions(provider, { | ||
[provider]: { | ||
...commonOptions, | ||
...providerAuthPayload, | ||
...providerOptions, | ||
...payload, | ||
}, | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不仅仅是 OpenAI SDK,Anthropic 的 SDK 也有这个配置的