refactor(LLM): Reorganize system providers and add provider reordering utility

This commit is contained in:
kangfenmao 2025-03-10 17:54:45 +08:00
parent 0250ec6f2e
commit 3791f30d8f
3 changed files with 66 additions and 49 deletions

View File

@ -36,7 +36,7 @@ const persistedReducer = persistReducer(
{
key: 'cherry-studio',
storage,
version: 77,
version: 78,
blacklist: ['runtime', 'messages'],
migrate
},

View File

@ -36,16 +36,6 @@ const initialState: LlmState = {
isSystem: true,
enabled: true
},
{
id: 'o3',
name: 'O3',
type: 'openai',
apiKey: '',
apiHost: 'https://api.o3.fan',
models: SYSTEM_MODELS.o3,
isSystem: true,
enabled: false
},
{
id: 'aihubmix',
name: 'AiHubMix',
@ -57,12 +47,12 @@ const initialState: LlmState = {
enabled: false
},
{
id: 'deepseek',
name: 'deepseek',
id: 'o3',
name: 'O3',
type: 'openai',
apiKey: '',
apiHost: 'https://api.deepseek.com',
models: SYSTEM_MODELS.deepseek,
apiHost: 'https://api.o3.fan',
models: SYSTEM_MODELS.o3,
isSystem: true,
enabled: false
},
@ -77,12 +67,22 @@ const initialState: LlmState = {
enabled: false
},
{
id: 'baidu-cloud',
name: 'Baidu Cloud',
id: 'openrouter',
name: 'OpenRouter',
type: 'openai',
apiKey: '',
apiHost: 'https://qianfan.baidubce.com/v2/',
models: SYSTEM_MODELS['baidu-cloud'],
apiHost: 'https://openrouter.ai/api/v1/',
models: SYSTEM_MODELS.openrouter,
isSystem: true,
enabled: false
},
{
id: 'deepseek',
name: 'deepseek',
type: 'openai',
apiKey: '',
apiHost: 'https://api.deepseek.com',
models: SYSTEM_MODELS.deepseek,
isSystem: true,
enabled: false
},
@ -106,6 +106,36 @@ const initialState: LlmState = {
isSystem: true,
enabled: false
},
{
id: 'ppio',
name: 'PPIO',
type: 'openai',
apiKey: '',
apiHost: 'https://api.ppinfra.com/v3/openai',
models: SYSTEM_MODELS.ppio,
isSystem: true,
enabled: false
},
{
id: 'infini',
name: 'Infini',
type: 'openai',
apiKey: '',
apiHost: 'https://cloud.infini-ai.com/maas',
models: SYSTEM_MODELS.infini,
isSystem: true,
enabled: false
},
{
id: 'baidu-cloud',
name: 'Baidu Cloud',
type: 'openai',
apiKey: '',
apiHost: 'https://qianfan.baidubce.com/v2/',
models: SYSTEM_MODELS['baidu-cloud'],
isSystem: true,
enabled: false
},
{
id: 'anthropic',
name: 'Anthropic',
@ -247,16 +277,6 @@ const initialState: LlmState = {
isSystem: true,
enabled: false
},
{
id: 'openrouter',
name: 'OpenRouter',
type: 'openai',
apiKey: '',
apiHost: 'https://openrouter.ai/api/v1/',
models: SYSTEM_MODELS.openrouter,
isSystem: true,
enabled: false
},
{
id: 'groq',
name: 'Groq',
@ -367,16 +387,6 @@ const initialState: LlmState = {
isSystem: true,
enabled: false
},
{
id: 'ppio',
name: 'PPIO',
type: 'openai',
apiKey: '',
apiHost: 'https://api.ppinfra.com/v3/openai',
models: SYSTEM_MODELS.ppio,
isSystem: true,
enabled: false
},
{
id: 'perplexity',
name: 'Perplexity',
@ -387,16 +397,6 @@ const initialState: LlmState = {
isSystem: true,
enabled: false
},
{
id: 'infini',
name: 'Infini',
type: 'openai',
apiKey: '',
apiHost: 'https://cloud.infini-ai.com/maas',
models: SYSTEM_MODELS.infini,
isSystem: true,
enabled: false
},
{
id: 'modelscope',
name: 'ModelScope',
@ -467,6 +467,17 @@ const getIntegratedInitialState = () => {
} as LlmState
}
export const moveProvider = (providers: Provider[], id: string, position: number) => {
const index = providers.findIndex((p) => p.id === id)
if (index === -1) return providers
const provider = providers[index]
const newProviders = [...providers]
newProviders.splice(index, 1)
newProviders.splice(position - 1, 0, provider)
return newProviders
}
const settingsSlice = createSlice({
name: 'llm',
initialState: isLocalAi ? getIntegratedInitialState() : initialState,

View File

@ -10,6 +10,7 @@ import { isEmpty } from 'lodash'
import { createMigrate } from 'redux-persist'
import { RootState } from '.'
import { moveProvider } from './llm'
import { DEFAULT_SIDEBAR_ICONS } from './settings'
// remove logo base64 data to reduce the size of the state
@ -1238,6 +1239,11 @@ const migrateConfig = {
})
}
return state
},
'78': (state: RootState) => {
state.llm.providers = moveProvider(state.llm.providers, 'ppio', 9)
state.llm.providers = moveProvider(state.llm.providers, 'infini', 10)
return state
}
}