refactor: migrate to v5 patch-2
This commit is contained in:
@@ -17,7 +17,7 @@ import {
|
||||
type ProviderSettingsMap,
|
||||
StreamTextParams
|
||||
} from '@cherrystudio/ai-core'
|
||||
import { createMCPPromptPlugin } from '@cherrystudio/ai-core/core/plugins/built-in'
|
||||
import { createPromptToolUsePlugin } from '@cherrystudio/ai-core/core/plugins/built-in'
|
||||
import { isDedicatedImageGenerationModel } from '@renderer/config/models'
|
||||
import { createVertexProvider, isVertexAIConfigured, isVertexProvider } from '@renderer/hooks/useVertexAI'
|
||||
import type { GenerateImageParams, Model, Provider } from '@renderer/types'
|
||||
@@ -136,7 +136,7 @@ export default class ModernAiProvider {
|
||||
// 3. 启用Prompt工具调用时添加工具插件
|
||||
if (middlewareConfig.enableTool && middlewareConfig.mcpTools && middlewareConfig.mcpTools.length > 0) {
|
||||
plugins.push(
|
||||
createMCPPromptPlugin({
|
||||
createPromptToolUsePlugin({
|
||||
enabled: true,
|
||||
createSystemMessage: (systemPrompt, params, context) => {
|
||||
if (context.modelId.includes('o1-mini') || context.modelId.includes('o1-preview')) {
|
||||
@@ -157,6 +157,10 @@ export default class ModernAiProvider {
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
// if (!middlewareConfig.enableTool && middlewareConfig.mcpTools && middlewareConfig.mcpTools.length > 0) {
|
||||
// plugins.push(createNativeToolUsePlugin())
|
||||
// }
|
||||
console.log(
|
||||
'最终插件列表:',
|
||||
plugins.map((p) => p.name)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* 统一管理从各个 apiClient 提取的参数处理和转换功能
|
||||
*/
|
||||
|
||||
import { type ModelMessage, type StreamTextParams } from '@cherrystudio/ai-core'
|
||||
import { type ModelMessage, stepCountIs, type StreamTextParams } from '@cherrystudio/ai-core'
|
||||
import { DEFAULT_MAX_TOKENS } from '@renderer/config/constant'
|
||||
import {
|
||||
isGenerateImageModel,
|
||||
@@ -245,7 +245,8 @@ export async function buildStreamTextParams(
|
||||
abortSignal: options.requestOptions?.signal,
|
||||
headers: options.requestOptions?.headers,
|
||||
providerOptions,
|
||||
tools
|
||||
tools,
|
||||
stopWhen: stepCountIs(10)
|
||||
}
|
||||
|
||||
return { params, modelId: model.id, capabilities: { enableReasoning, enableWebSearch, enableGenerateImage } }
|
||||
|
||||
@@ -42,7 +42,7 @@ export function getReasoningEffort(assistant: Assistant, model: Model): Reasonin
|
||||
|
||||
if (isSupportedThinkingTokenGeminiModel(model)) {
|
||||
if (GEMINI_FLASH_MODEL_REGEX.test(model.id)) {
|
||||
return { reasoning_effort: 'none' }
|
||||
return { reasoningEffort: 'none' }
|
||||
}
|
||||
return {}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ export function getReasoningEffort(assistant: Assistant, model: Model): Reasonin
|
||||
return { reasoning: { max_tokens: 0, exclude: true } }
|
||||
}
|
||||
if (GEMINI_FLASH_MODEL_REGEX.test(model.id)) {
|
||||
return { reasoning_effort: 'none' }
|
||||
return { reasoningEffort: 'none' }
|
||||
}
|
||||
return {}
|
||||
}
|
||||
@@ -123,14 +123,14 @@ export function getReasoningEffort(assistant: Assistant, model: Model): Reasonin
|
||||
// Grok models
|
||||
if (isSupportedReasoningEffortGrokModel(model)) {
|
||||
return {
|
||||
reasoning_effort: reasoningEffort
|
||||
reasoningEffort: reasoningEffort
|
||||
}
|
||||
}
|
||||
|
||||
// OpenAI models
|
||||
if (isSupportedReasoningEffortOpenAIModel(model) || isSupportedThinkingTokenGeminiModel(model)) {
|
||||
return {
|
||||
reasoning_effort: reasoningEffort
|
||||
reasoningEffort: reasoningEffort
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -172,7 +172,6 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
|
||||
const uploadedFiles = await FileManager.uploadFiles(files)
|
||||
|
||||
const baseUserMessage: MessageInputBaseParams = { assistant, topic, content: text }
|
||||
Logger.log('baseUserMessage', baseUserMessage)
|
||||
|
||||
// getUserMessage()
|
||||
if (uploadedFiles) {
|
||||
|
||||
@@ -49,7 +49,7 @@ type OpenAIParamsWithoutReasoningEffort = Omit<OpenAI.Chat.Completions.ChatCompl
|
||||
export type ReasoningEffortOptionalParams = {
|
||||
thinking?: { type: 'disabled' | 'enabled' | 'auto'; budget_tokens?: number }
|
||||
reasoning?: { max_tokens?: number; exclude?: boolean; effort?: string; enabled?: boolean } | OpenAI.Reasoning
|
||||
reasoning_effort?: OpenAI.Chat.Completions.ChatCompletionCreateParams['reasoning_effort'] | 'none' | 'auto'
|
||||
reasoningEffort?: OpenAI.Chat.Completions.ChatCompletionCreateParams['reasoning_effort'] | 'none' | 'auto'
|
||||
enable_thinking?: boolean
|
||||
thinking_budget?: number
|
||||
enable_reasoning?: boolean
|
||||
|
||||
Reference in New Issue
Block a user