mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-09 14:59:27 +08:00
fix(settings): reading undefined caused crash (#8901)
* fix(settings): 修复OpenAI推理条件中provider未定义的判断问题 修复useProvider钩子中provider可能为undefined时的模型获取逻辑 * feat(provider): 添加供应商不存在时的默认回退逻辑 当供应商不存在时,自动回退到默认供应商并显示警告信息 * feat(i18n): 添加缺失供应商的警告信息翻译 * fix(SettingsTab): 移除对provider的冗余检查
This commit is contained in:
parent
6283ffdfe4
commit
3435dfe5e3
@ -1,5 +1,6 @@
|
||||
import { createSelector } from '@reduxjs/toolkit'
|
||||
import { isSystemProvider } from '@renderer/config/providers'
|
||||
import { getDefaultProvider } from '@renderer/services/AssistantService'
|
||||
import { useAppDispatch, useAppSelector } from '@renderer/store'
|
||||
import {
|
||||
addModel,
|
||||
@ -11,6 +12,8 @@ import {
|
||||
updateProviders
|
||||
} from '@renderer/store/llm'
|
||||
import { Assistant, Model, Provider } from '@renderer/types'
|
||||
import { getFancyProviderName } from '@renderer/utils'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import { useDefaultModel } from './useAssistant'
|
||||
|
||||
@ -45,12 +48,18 @@ export function useAllProviders() {
|
||||
}
|
||||
|
||||
export function useProvider(id: string) {
|
||||
const provider = useAppSelector((state) => state.llm.providers.find((p) => p.id === id) as Provider)
|
||||
let provider = useAppSelector((state) => state.llm.providers.find((p) => p.id === id))
|
||||
const dispatch = useAppDispatch()
|
||||
const { t } = useTranslation()
|
||||
|
||||
if (!provider) {
|
||||
provider = getDefaultProvider()
|
||||
window.message.warning(t('warning.missing_provider', { provider: getFancyProviderName(provider) }))
|
||||
}
|
||||
|
||||
return {
|
||||
provider,
|
||||
models: provider?.models || [],
|
||||
models: provider?.models ?? [],
|
||||
updateProvider: (updates: Partial<Provider>) => dispatch(updateProvider({ id, ...updates })),
|
||||
addModel: (model: Model) => dispatch(addModel({ providerId: id, model })),
|
||||
removeModel: (model: Model) => dispatch(removeModel({ providerId: id, model })),
|
||||
|
||||
@ -3565,6 +3565,9 @@
|
||||
"noReleaseNotes": "No release notes",
|
||||
"title": "Update"
|
||||
},
|
||||
"warning": {
|
||||
"missing_provider": "The supplier does not exist; reverted to the default supplier {{provider}}. This may cause issues."
|
||||
},
|
||||
"words": {
|
||||
"knowledgeGraph": "Knowledge Graph",
|
||||
"quit": "Quit",
|
||||
|
||||
@ -3565,6 +3565,9 @@
|
||||
"noReleaseNotes": "暫無更新日誌",
|
||||
"title": "更新"
|
||||
},
|
||||
"warning": {
|
||||
"missing_provider": "サプライヤーが存在しないため、デフォルトのサプライヤー {{provider}} にロールバックされました。これにより問題が発生する可能性があります。"
|
||||
},
|
||||
"words": {
|
||||
"knowledgeGraph": "ナレッジグラフ",
|
||||
"quit": "終了",
|
||||
|
||||
@ -3565,6 +3565,9 @@
|
||||
"noReleaseNotes": "Нет заметок об обновлении",
|
||||
"title": "Обновление"
|
||||
},
|
||||
"warning": {
|
||||
"missing_provider": "Поставщик не существует, возвращение к поставщику по умолчанию {{provider}}. Это может привести к проблемам."
|
||||
},
|
||||
"words": {
|
||||
"knowledgeGraph": "Граф знаний",
|
||||
"quit": "Выйти",
|
||||
|
||||
@ -3565,6 +3565,9 @@
|
||||
"noReleaseNotes": "暂无更新日志",
|
||||
"title": "更新提示"
|
||||
},
|
||||
"warning": {
|
||||
"missing_provider": "供应商不存在,已回退到默认供应商 {{provider}}。这可能导致问题。"
|
||||
},
|
||||
"words": {
|
||||
"knowledgeGraph": "知识图谱",
|
||||
"quit": "退出",
|
||||
|
||||
@ -3565,6 +3565,9 @@
|
||||
"noReleaseNotes": "暫無更新日誌",
|
||||
"title": "更新提示"
|
||||
},
|
||||
"warning": {
|
||||
"missing_provider": "供應商不存在,已回退到預設供應商 {{provider}}。這可能導致問題。"
|
||||
},
|
||||
"words": {
|
||||
"knowledgeGraph": "知識圖譜",
|
||||
"quit": "結束",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user