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

View File

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

View File

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

View File

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

View File

@ -28,6 +28,32 @@ export function getReasoningEffort(assistant: Assistant, model: Model): Reasonin
} }
const reasoningEffort = assistant?.settings?.reasoning_effort 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 思考模式支持 // Doubao 思考模式支持
if (isSupportedThinkingTokenDoubaoModel(model)) { if (isSupportedThinkingTokenDoubaoModel(model)) {
// reasoningEffort 为空,默认开启 enabled // reasoningEffort 为空,默认开启 enabled

View File

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