mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-10 15:49:29 +08:00
feat: initialize painting model with first available option and update default provider to 'cherryin'
This commit is contained in:
parent
b8da00a99f
commit
7fb6b1377b
@ -481,6 +481,13 @@ const NewApiPage: FC<{ Options: string[] }> = ({ Options }) => {
|
|||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
// if painting.model is not set, set it to the first model in modelOptions
|
||||||
|
useEffect(() => {
|
||||||
|
if (!painting.model && modelOptions.length > 0) {
|
||||||
|
updatePaintingState({ model: modelOptions[0].value })
|
||||||
|
}
|
||||||
|
}, [modelOptions, painting.model, updatePaintingState])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
<Navbar>
|
<Navbar>
|
||||||
|
|||||||
@ -3,8 +3,10 @@ import { isNewApiProvider } from '@renderer/config/providers'
|
|||||||
import { useAllProviders } from '@renderer/hooks/useProvider'
|
import { useAllProviders } from '@renderer/hooks/useProvider'
|
||||||
import { useAppDispatch } from '@renderer/store'
|
import { useAppDispatch } from '@renderer/store'
|
||||||
import { setDefaultPaintingProvider } from '@renderer/store/settings'
|
import { setDefaultPaintingProvider } from '@renderer/store/settings'
|
||||||
import { PaintingProvider, SystemProviderId } from '@renderer/types'
|
import { updateTab } from '@renderer/store/tabs'
|
||||||
import { FC, useEffect, useMemo } from 'react'
|
import type { PaintingProvider, SystemProviderId } from '@renderer/types'
|
||||||
|
import type { FC } from 'react'
|
||||||
|
import { useEffect, useMemo } from 'react'
|
||||||
import { Route, Routes, useParams } from 'react-router-dom'
|
import { Route, Routes, useParams } from 'react-router-dom'
|
||||||
|
|
||||||
import AihubmixPage from './AihubmixPage'
|
import AihubmixPage from './AihubmixPage'
|
||||||
@ -23,31 +25,30 @@ const PaintingsRoutePage: FC = () => {
|
|||||||
const provider = params['*']
|
const provider = params['*']
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
const providers = useAllProviders()
|
const providers = useAllProviders()
|
||||||
const Options = useMemo(() => {
|
|
||||||
return [...BASE_OPTIONS, ...providers.filter((p) => isNewApiProvider(p)).map((p) => p.id)]
|
const Options = useMemo(() => [...BASE_OPTIONS, ...providers.filter(isNewApiProvider).map((p) => p.id)], [providers])
|
||||||
}, [providers])
|
const newApiProviders = useMemo(() => providers.filter(isNewApiProvider), [providers])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
logger.debug(`defaultPaintingProvider: ${provider}`)
|
logger.debug(`defaultPaintingProvider: ${provider}`)
|
||||||
if (provider && Options.includes(provider)) {
|
if (provider && Options.includes(provider)) {
|
||||||
dispatch(setDefaultPaintingProvider(provider as PaintingProvider))
|
dispatch(setDefaultPaintingProvider(provider as PaintingProvider))
|
||||||
|
dispatch(updateTab({ id: 'paintings', updates: { path: `/paintings/${provider}` } }))
|
||||||
}
|
}
|
||||||
}, [provider, dispatch, Options])
|
}, [provider, dispatch, Options])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="*" element={<ZhipuPage Options={Options} />} />
|
<Route path="*" element={<NewApiPage Options={Options} />} />
|
||||||
<Route path="/zhipu" element={<ZhipuPage Options={Options} />} />
|
<Route path="/zhipu" element={<ZhipuPage Options={Options} />} />
|
||||||
<Route path="/aihubmix" element={<AihubmixPage Options={Options} />} />
|
<Route path="/aihubmix" element={<AihubmixPage Options={Options} />} />
|
||||||
<Route path="/silicon" element={<SiliconPage Options={Options} />} />
|
<Route path="/silicon" element={<SiliconPage Options={Options} />} />
|
||||||
<Route path="/dmxapi" element={<DmxapiPage Options={Options} />} />
|
<Route path="/dmxapi" element={<DmxapiPage Options={Options} />} />
|
||||||
<Route path="/tokenflux" element={<TokenFluxPage Options={Options} />} />
|
<Route path="/tokenflux" element={<TokenFluxPage Options={Options} />} />
|
||||||
{/* new-api family providers are mounted dynamically below */}
|
{/* new-api family providers are mounted dynamically below */}
|
||||||
{providers
|
{newApiProviders.map((p) => (
|
||||||
.filter((p) => isNewApiProvider(p))
|
<Route key={p.id} path={`/${p.id}`} element={<NewApiPage Options={Options} />} />
|
||||||
.map((p) => (
|
))}
|
||||||
<Route key={p.id} path={`/${p.id}`} element={<NewApiPage Options={Options} />} />
|
|
||||||
))}
|
|
||||||
</Routes>
|
</Routes>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2614,6 +2614,7 @@ const migrateConfig = {
|
|||||||
try {
|
try {
|
||||||
addProvider(state, 'sophnet')
|
addProvider(state, 'sophnet')
|
||||||
state.llm.providers = moveProvider(state.llm.providers, 'sophnet', 17)
|
state.llm.providers = moveProvider(state.llm.providers, 'sophnet', 17)
|
||||||
|
state.settings.defaultPaintingProvider = 'cherryin'
|
||||||
return state
|
return state
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('migrate 164 error', error as Error)
|
logger.error('migrate 164 error', error as Error)
|
||||||
|
|||||||
@ -388,7 +388,7 @@ export const initialState: SettingsState = {
|
|||||||
localBackupSyncInterval: 0,
|
localBackupSyncInterval: 0,
|
||||||
localBackupMaxBackups: 0,
|
localBackupMaxBackups: 0,
|
||||||
localBackupSkipBackupFile: false,
|
localBackupSkipBackupFile: false,
|
||||||
defaultPaintingProvider: 'zhipu',
|
defaultPaintingProvider: 'cherryin',
|
||||||
s3: {
|
s3: {
|
||||||
endpoint: '',
|
endpoint: '',
|
||||||
region: '',
|
region: '',
|
||||||
|
|||||||
@ -425,7 +425,7 @@ export type PaintingParams = {
|
|||||||
providerId?: string
|
providerId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PaintingProvider = 'zhipu' | 'aihubmix' | 'silicon' | 'dmxapi' | 'new-api'
|
export type PaintingProvider = 'zhipu' | 'aihubmix' | 'silicon' | 'dmxapi' | 'new-api' | 'cherryin'
|
||||||
|
|
||||||
export interface Painting extends PaintingParams {
|
export interface Painting extends PaintingParams {
|
||||||
model?: string
|
model?: string
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user