refactor: remove OpenRouter provider support and streamline reasoning logic

- Commented out the OpenRouter provider in `registry.ts` and related configurations due to excessive bugs.
- Simplified reasoning logic in `transformParameters.ts` and `options.ts` by removing unnecessary checks for `enableReasoning`.
- Enhanced logging in `transformParameters.ts` to provide better insights into reasoning capabilities.
- Updated `getReasoningEffort` to handle cases where reasoning effort is not defined, improving model compatibility.
This commit is contained in:
suyao 2025-06-29 15:16:47 +08:00
parent 592a7ddc3f
commit 6c87b42607
No known key found for this signature in database
6 changed files with 43 additions and 22 deletions

View File

@ -24,7 +24,7 @@ import { type ReplicateProviderSettings } from '@ai-sdk/replicate'
import { type TogetherAIProviderSettings } from '@ai-sdk/togetherai'
import { type VercelProviderSettings } from '@ai-sdk/vercel'
import { type XaiProviderSettings } from '@ai-sdk/xai'
import { type OpenRouterProviderSettings } from '@openrouter/ai-sdk-provider'
// import { type OpenRouterProviderSettings } from '@openrouter/ai-sdk-provider'
import { type AnthropicVertexProviderSettings } from 'anthropic-vertex-ai'
import { type OllamaProviderSettings } from 'ollama-ai-provider'
import { type QwenProviderSettings } from 'qwen-ai-provider'
@ -56,7 +56,6 @@ export type ProviderSettingsMap = {
qwen: QwenProviderSettings
zhipu: ZhipuProviderSettings
'anthropic-vertex': AnthropicVertexProviderSettings
openrouter: OpenRouterProviderSettings
}
export type ProviderId = keyof ProviderSettingsMap
@ -267,14 +266,15 @@ export class AiProviderRegistry {
import: () => import('anthropic-vertex-ai'),
creatorFunctionName: 'createAnthropicVertex',
supportsImageGeneration: false
},
{
id: 'openrouter',
name: 'OpenRouter',
import: () => import('@openrouter/ai-sdk-provider'),
creatorFunctionName: 'createOpenRouter',
supportsImageGeneration: false
}
// bug太多
// {
// id: 'openrouter',
// name: 'OpenRouter',
// import: () => import('@openrouter/ai-sdk-provider'),
// creatorFunctionName: 'createOpenRouter',
// supportsImageGeneration: false
// }
]
providers.forEach((config) => {
@ -365,7 +365,6 @@ export type {
OllamaProviderSettings,
OpenAICompatibleProviderSettings,
OpenAIProviderSettings,
OpenRouterProviderSettings,
PerplexityProviderSettings,
QwenProviderSettings,
ReplicateProviderSettings,

View File

@ -119,12 +119,11 @@ export default class ModernAiProvider {
*/
private buildPlugins(middlewareConfig: AiSdkMiddlewareConfig) {
const plugins: AiPlugin[] = []
const model = middlewareConfig.model
// 1. 总是添加通用插件
plugins.push(textPlugin)
// 2. 推理模型时添加推理插件
if (model && middlewareConfig.enableReasoning) {
if (middlewareConfig.enableReasoning) {
plugins.push(
smoothReasoningPlugin({
delayInMs: 80,

View File

@ -210,8 +210,7 @@ export async function buildStreamTextParams(
const enableReasoning =
((isSupportedThinkingTokenModel(model) || isSupportedReasoningEffortModel(model)) &&
reasoning_effort !== undefined) ||
(isReasoningModel(model) && (!isSupportedThinkingTokenModel(model) || !isSupportedReasoningEffortModel(model)))
(isReasoningModel(model) && !isSupportedThinkingTokenModel(model) && !isSupportedReasoningEffortModel(model))
const enableWebSearch =
(assistant.enableWebSearch && isWebSearchModel(model)) ||
isOpenRouterBuiltInWebSearchModel(model) ||

View File

@ -179,16 +179,13 @@ function buildGenericProviderOptions(
enableGenerateImage: boolean
}
): Record<string, any> {
const { enableReasoning, enableWebSearch, enableGenerateImage } = capabilities
const { enableWebSearch, enableGenerateImage } = capabilities
let providerOptions: Record<string, any> = {}
// 使用原有的通用推理逻辑
if (enableReasoning) {
const reasoningParams = getReasoningEffort(assistant, model)
providerOptions = {
...providerOptions,
...reasoningParams
}
const reasoningParams = getReasoningEffort(assistant, model)
providerOptions = {
...providerOptions,
...reasoningParams
}
if (enableWebSearch) {

View File

@ -28,6 +28,32 @@ export function getReasoningEffort(assistant: Assistant, model: Model): Reasonin
}
const reasoningEffort = assistant?.settings?.reasoning_effort
if (!reasoningEffort) {
if (model.provider === 'openrouter') {
return { reasoning: { enabled: false } }
}
if (isSupportedThinkingTokenQwenModel(model)) {
return { enable_thinking: false }
}
if (isSupportedThinkingTokenClaudeModel(model)) {
return {}
}
if (isSupportedThinkingTokenGeminiModel(model)) {
if (GEMINI_FLASH_MODEL_REGEX.test(model.id)) {
return { reasoning_effort: 'none' }
}
return {}
}
if (isSupportedThinkingTokenDoubaoModel(model)) {
return { thinking: { type: 'disabled' } }
}
return {}
}
// Doubao 思考模式支持
if (isSupportedThinkingTokenDoubaoModel(model)) {
// reasoningEffort 为空,默认开启 enabled

View File

@ -116,6 +116,7 @@ export const getAssistantSettings = (assistant: Assistant): AssistantSettings =>
streamOutput: assistant?.settings?.streamOutput ?? true,
toolUseMode: assistant?.settings?.toolUseMode ?? 'prompt',
defaultModel: assistant?.defaultModel ?? undefined,
reasoning_effort: assistant?.settings?.reasoning_effort ?? undefined,
customParameters: assistant?.settings?.customParameters ?? []
}
}