mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-28 05:11:24 +08:00
refactor(aiCore): enhance temperature and TopP parameter handling
- Updated `getTemperature` and `getTopP` functions to incorporate reasoning effort checks for Claude models. - Refactored logic to ensure temperature and TopP settings are only returned when applicable. - Improved clarity and maintainability of parameter retrieval functions.
This commit is contained in:
parent
2ca5116769
commit
c9d0265872
@ -6,6 +6,7 @@
|
||||
import { loggerService } from '@logger'
|
||||
import { DEFAULT_MAX_TOKENS } from '@renderer/config/constant'
|
||||
import {
|
||||
isClaudeReasoningModel,
|
||||
isGenerateImageModel,
|
||||
isNotSupportTemperatureAndTopP,
|
||||
isOpenRouterBuiltInWebSearchModel,
|
||||
@ -44,15 +45,29 @@ const logger = loggerService.withContext('transformParameters')
|
||||
/**
|
||||
* 获取温度参数
|
||||
*/
|
||||
export function getTemperature(assistant: Assistant, model: Model): number | undefined {
|
||||
return isNotSupportTemperatureAndTopP(model) ? undefined : assistant.settings?.temperature
|
||||
function getTemperature(assistant: Assistant, model: Model): number | undefined {
|
||||
if (assistant.settings?.reasoning_effort && isClaudeReasoningModel(model)) {
|
||||
return undefined
|
||||
}
|
||||
if (isNotSupportTemperatureAndTopP(model)) {
|
||||
return undefined
|
||||
}
|
||||
const assistantSettings = getAssistantSettings(assistant)
|
||||
return assistantSettings?.enableTemperature ? assistantSettings?.temperature : undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 TopP 参数
|
||||
*/
|
||||
export function getTopP(assistant: Assistant, model: Model): number | undefined {
|
||||
return isNotSupportTemperatureAndTopP(model) ? undefined : assistant.settings?.topP
|
||||
function getTopP(assistant: Assistant, model: Model): number | undefined {
|
||||
if (assistant.settings?.reasoning_effort && isClaudeReasoningModel(model)) {
|
||||
return undefined
|
||||
}
|
||||
if (isNotSupportTemperatureAndTopP(model)) {
|
||||
return undefined
|
||||
}
|
||||
const assistantSettings = getAssistantSettings(assistant)
|
||||
return assistantSettings?.enableTopP ? assistantSettings?.topP : undefined
|
||||
}
|
||||
|
||||
/**
|
||||
@ -372,7 +387,7 @@ export async function buildStreamTextParams(
|
||||
if (assistant.prompt) {
|
||||
params.system = assistant.prompt
|
||||
}
|
||||
|
||||
console.log('params', params)
|
||||
return {
|
||||
params,
|
||||
modelId: model.id,
|
||||
|
||||
@ -77,7 +77,7 @@ export function buildProviderOptions(
|
||||
case 'openai':
|
||||
case 'azure':
|
||||
providerSpecificOptions = {
|
||||
...buildOpenAIProviderOptions(assistant, model, capabilities),
|
||||
...buildOpenAIProviderOptions(assistant, model, capabilities, actualProvider),
|
||||
serviceTier: serviceTierSetting
|
||||
}
|
||||
break
|
||||
@ -126,7 +126,8 @@ function buildOpenAIProviderOptions(
|
||||
enableReasoning: boolean
|
||||
enableWebSearch: boolean
|
||||
enableGenerateImage: boolean
|
||||
}
|
||||
},
|
||||
actualProvider: Provider
|
||||
): Record<string, any> {
|
||||
const { enableReasoning } = capabilities
|
||||
let providerOptions: Record<string, any> = {}
|
||||
@ -139,6 +140,11 @@ function buildOpenAIProviderOptions(
|
||||
}
|
||||
}
|
||||
|
||||
if (actualProvider.id === 'azure') {
|
||||
providerOptions.apiVersion = actualProvider.apiVersion
|
||||
providerOptions.useDeploymentBasedUrls = true
|
||||
}
|
||||
|
||||
return providerOptions
|
||||
}
|
||||
|
||||
|
||||
@ -263,9 +263,9 @@ const HomeWindow: FC<{ draggable?: boolean }> = ({ draggable = true }) => {
|
||||
}
|
||||
newAssistant.settings.streamOutput = true
|
||||
// 显式关闭这些功能
|
||||
// newAssistant.webSearchProviderId = undefined
|
||||
newAssistant.webSearchProviderId = undefined
|
||||
newAssistant.mcpServers = undefined
|
||||
// newAssistant.knowledge_bases = undefined
|
||||
newAssistant.knowledge_bases = undefined
|
||||
const llmMessages = await ConversationService.prepareMessagesForModel(messagesForContext, newAssistant)
|
||||
|
||||
await fetchChatCompletion({
|
||||
|
||||
@ -63,7 +63,7 @@ export const processMessages = async (
|
||||
// 显式关闭这些功能
|
||||
newAssistant.webSearchProviderId = undefined
|
||||
newAssistant.mcpServers = undefined
|
||||
// newAssistant.knowledge_bases = undefined
|
||||
newAssistant.knowledge_bases = undefined
|
||||
const llmMessages = await ConversationService.prepareMessagesForModel([userMessage], newAssistant)
|
||||
|
||||
await fetchChatCompletion({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user