Skip to content

Commit 6be3680

Browse files
committed
feat: 拆分默认模型配置,增加知识库设置页面
1 parent 10db92b commit 6be3680

File tree

11 files changed

+266
-104
lines changed

11 files changed

+266
-104
lines changed

messages/en.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@
2525
"error": "Failed"
2626
},
2727
"settings": {
28+
"rag": {
29+
"title": "Knowledge Base",
30+
"desc": "Here, you can configure knowledge base related settings, knowledge base based on RAG technology, through embedding models to convert text into vectors, then through vector search to achieve intelligent search and intelligent answers."
31+
},
2832
"editor": {
29-
"title": "Editor Settings",
33+
"title": "Markdown Editor",
3034
"desc": "Here, you can customize the Markdown editor, creating a writing experience tailored to your needs.",
3135
"typewriterMode": "Typewriter Mode",
3236
"typewriterModeDesc": "In typewriter mode, the editor will simulate a typewriter effect, helping you better immerse in writing."

messages/ja.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@
2323
"error": "失敗"
2424
},
2525
"settings": {
26+
"rag": {
27+
"title": "知識庫",
28+
"desc": "ここでは、知識庫に関する設定を構成できます。知識庫は、RAG技術に基づいて、埋め込みモデルを使用してテキストをベクトルに変換し、ベクトル検索を介して智能的な検索と智能的な回答を達成します。"
29+
},
2630
"editor": {
27-
"title": "エディタ設定です",
31+
"title": "Markdown エディタ",
2832
"desc": "ここでは、Markdown エディタをカスタマイズして、より適した書き込み体験を提供できます。",
2933
"typewriterMode": "打字機モード",
3034
"typewriterModeDesc": "打字機モード下、エディタは打字機の効果を模倣し、より深く浸かる書き込み体験を提供します。"

messages/zh.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@
2323
"error": "失败"
2424
},
2525
"settings": {
26+
"rag": {
27+
"title": "知识库",
28+
"desc": "在这里,你可以配置知识库相关设置,知识库基于 RAG 技术,通过嵌入模型将文本转换为向量,然后通过向量搜索来实现智能搜索和智能回答。"
29+
},
2630
"editor": {
27-
"title": "编辑器设置",
31+
"title": "Markdown 编辑器",
2832
"desc": "在这里,你可以对 Markdown 编辑器进行自定义配置,打造更适合你的写作方式。",
2933
"typewriterMode": "打字机模式",
3034
"typewriterModeDesc": "打字机模式下,编辑器会模拟打字机效果,帮助你更好地沉浸在写作中。"

src/app/core/setting/components/setting-base.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ export function FormItem({title, desc, children}: { title: string, desc?: string
2727
</div>
2828
}
2929

30-
export function SettingPanel({children, title, desc}: {children: React.ReactNode, title?: string, desc?: string}) {
31-
return <div className="flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm mb-8">
30+
export function SettingPanel({children, title, desc, icon}: {children: React.ReactNode, title?: string, desc?: string, icon?: React.ReactNode}) {
31+
return <div className="flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm mb-4">
3232
<div>
33-
{title && <div className="text-sm mb-2 font-bold">{title}</div>}
34-
{desc && <p className="text-sm text-muted-foreground mt-2">{desc}</p>}
33+
<div className="flex items-center gap-2 mb-2">
34+
{icon}
35+
{title && <div className="text-sm font-bold">{title}</div>}
36+
</div>
37+
{desc && <p className="text-sm text-muted-foreground">{desc}</p>}
3538
</div>
3639
{children}
3740
</div>

src/app/core/setting/config.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BotMessageSquare, LayoutTemplate, ScanText, Store, UserRoundCog, Drama, FolderOpen, Package, Database, DatabaseBackup, ImageUp } from "lucide-react"
1+
import { BotMessageSquare, LayoutTemplate, ScanText, Store, UserRoundCog, Drama, FolderOpen, Package, Database, DatabaseBackup, ImageUp, FileCog, Book } from "lucide-react"
22

33
const baseConfig = [
44
{
@@ -27,6 +27,10 @@ const baseConfig = [
2727
icon: <Package className="size-4 lg:size-6" />,
2828
anchor: 'defaultModel',
2929
},
30+
{
31+
icon: <Book className="size-4 lg:size-6" />,
32+
anchor: 'rag',
33+
},
3034
{
3135
icon: <Drama className="size-4 lg:size-6" />,
3236
anchor: 'prompt',
@@ -41,7 +45,7 @@ const baseConfig = [
4145
anchor: 'file',
4246
},
4347
{
44-
icon: <UserRoundCog className="size-4 lg:size-6" />,
48+
icon: <FileCog className="size-4 lg:size-6" />,
4549
anchor: 'editor',
4650
},
4751
{

src/app/core/setting/defaultModel/model-select.tsx

Lines changed: 12 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ import { TooltipButton } from "@/components/tooltip-button"
2727

2828
export function ModelSelect({modelKey}: {modelKey: string}) {
2929
const [list, setList] = useState<AiConfig[]>([])
30-
const { setPlaceholderModel, setTranslateModel, setMarkDescModel, setEmbeddingModel, setRerankingModel, setPrimaryModel } = useSettingStore()
30+
const { setPlaceholderModel, setTranslateModel, setMarkDescModel, setPrimaryModel } = useSettingStore()
3131
const [model, setModel] = useState<string>('')
3232
const [open, setOpen] = React.useState(false)
3333
const t = useTranslations('settings.defaultModel')
34-
const chatModelTypes = ['primaryModel', 'markDesc', 'placeholder', 'translate']
3534

3635
function setPrimaryModelHandler(primaryModel: string) {
3736
setModel(primaryModel)
@@ -48,12 +47,6 @@ export function ModelSelect({modelKey}: {modelKey: string}) {
4847
case 'markDesc':
4948
setMarkDescModel(primaryModel)
5049
break;
51-
case 'embedding':
52-
setEmbeddingModel(primaryModel)
53-
break;
54-
case 'reranking':
55-
setRerankingModel(primaryModel)
56-
break;
5750
default:
5851
break;
5952
}
@@ -104,79 +97,30 @@ export function ModelSelect({modelKey}: {modelKey: string}) {
10497
variant="outline"
10598
role="combobox"
10699
aria-expanded={open}
107-
className="w-full lg:w-[520px] justify-between"
100+
className="w-full lg:w-[280px] justify-between"
108101
>
109102
{model
110103
? `${list.find((item) => item.key === model)?.model}(${list.find((item) => item.key === model)?.title})`
111-
: modelKey === 'primaryModel' ? t('noModel') : chatModelTypes.includes(modelKey) ? t('tooltip') : t('noModel')}
104+
: modelKey === 'primaryModel' ? t('noModel') : t('tooltip')}
112105
<ChevronsUpDown className="opacity-50" />
113106
</Button>
114107
</div>
115108
</PopoverTrigger>
116-
{
117-
chatModelTypes.includes(modelKey) && model && (
118-
<TooltipButton
119-
icon={<X className="h-4 w-4" />}
120-
onClick={resetDefaultModel}
121-
variant="default"
122-
tooltipText={t('tooltip')}
123-
/>
124-
)
125-
}
126-
{
127-
(modelKey === 'embedding' || modelKey === 'reranking') && model && (
128-
<TooltipButton
129-
icon={<X className="h-4 w-4" />}
130-
onClick={resetDefaultModel}
131-
variant="default"
132-
tooltipText={t('noModel')}
133-
/>
134-
)
135-
}
109+
<TooltipButton
110+
disabled={!model}
111+
icon={<X className="h-4 w-4" />}
112+
onClick={resetDefaultModel}
113+
variant="default"
114+
tooltipText={t('tooltip')}
115+
/>
136116
</div>
137-
<PopoverContent align="start" className="w-full lg:w-[480px] p-0">
117+
<PopoverContent align="end" className="p-0">
138118
<Command>
139119
<CommandInput placeholder={t('placeholder')} className="h-9" />
140120
<CommandList>
141121
<CommandEmpty>No model found.</CommandEmpty>
142122
<CommandGroup>
143-
{chatModelTypes.includes(modelKey) && list.filter(item => item.modelType === 'chat' || !item.modelType).map((item) => (
144-
<CommandItem
145-
key={item.key}
146-
value={item.key}
147-
onSelect={(currentValue) => {
148-
modelSelectChangeHandler(currentValue)
149-
setOpen(false)
150-
}}
151-
>
152-
{`${item.model}(${item.title})`}
153-
<Check
154-
className={cn(
155-
"ml-auto",
156-
model === item.key ? "opacity-100" : "opacity-0"
157-
)}
158-
/>
159-
</CommandItem>
160-
))}
161-
{modelKey === 'embedding' && list.filter(item => item.modelType === 'embedding').map((item) => (
162-
<CommandItem
163-
key={item.key}
164-
value={item.key}
165-
onSelect={(currentValue) => {
166-
modelSelectChangeHandler(currentValue)
167-
setOpen(false)
168-
}}
169-
>
170-
{`${item.model}(${item.title})`}
171-
<Check
172-
className={cn(
173-
"ml-auto",
174-
model === item.key ? "opacity-100" : "opacity-0"
175-
)}
176-
/>
177-
</CommandItem>
178-
))}
179-
{modelKey === 'reranking' && list.filter(item => item.modelType === 'rerank').map((item) => (
123+
{list.filter(item => item.modelType === 'chat' || !item.modelType).map((item) => (
180124
<CommandItem
181125
key={item.key}
182126
value={item.key}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
'use client';
2-
2+
import { SettingType } from "../components/setting-base";
33
import { Setting } from "./setting";
44
import { Package } from "lucide-react"
5+
import { useTranslations } from "next-intl";
56

67
export default function DefaultModelPage() {
7-
return <Setting id="defaultModel" icon={<Package />} />
8+
const t = useTranslations('settings.defaultModel');
9+
10+
return <SettingType id="defaultModel" icon={<Package />} title={t('title')} desc={t('desc')}>
11+
<Setting />
12+
</SettingType>
813
}
Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,43 @@
1-
import { FormItem, SettingRow, SettingType } from "../components/setting-base";
1+
import { SettingPanel } from "../components/setting-base";
22
import { useTranslations } from 'next-intl';
33
import { ModelSelect } from "./model-select";
4+
import { Bot, Highlighter, Languages, Lightbulb } from "lucide-react";
45

5-
export function Setting({id, icon}: {id: string, icon?: React.ReactNode}) {
6+
export function Setting() {
67
const t = useTranslations('settings.defaultModel');
78

89
const options = [
910
{
1011
title: t('options.primaryModel.title'),
1112
desc: t('options.primaryModel.desc'),
12-
modelKey: 'primaryModel'
13+
modelKey: 'primaryModel',
14+
icon: <Bot className="size-4" />
1315
},
1416
{
1517
title: t('options.markDesc.title'),
1618
desc: t('options.markDesc.desc'),
17-
modelKey: 'markDesc'
19+
modelKey: 'markDesc',
20+
icon: <Highlighter className="size-4" />
1821
},
1922
{
2023
title: t('options.placeholder.title'),
2124
desc: t('options.placeholder.desc'),
22-
modelKey: 'placeholder'
25+
modelKey: 'placeholder',
26+
icon: <Lightbulb className="size-4" />
2327
},
2428
{
2529
title: t('options.translate.title'),
2630
desc: t('options.translate.desc'),
27-
modelKey: 'translate'
28-
},
29-
{
30-
title: t('options.embedding.title'),
31-
desc: t('options.embedding.desc'),
32-
modelKey: 'embedding'
33-
},
34-
{
35-
title: t('options.reranking.title'),
36-
desc: t('options.reranking.desc'),
37-
modelKey: 'reranking'
31+
modelKey: 'translate',
32+
icon: <Languages className="size-4" />
3833
},
3934
]
4035

4136
return (
42-
<SettingType id={id} icon={icon} title={t('title')} desc={t('desc')}>
43-
{options.map((option) => (
44-
<SettingRow key={option.modelKey}>
45-
<FormItem title={option.title} desc={option.desc}>
46-
<ModelSelect modelKey={option.modelKey} />
47-
</FormItem>
48-
</SettingRow>
49-
))}
50-
</SettingType>
37+
options.map((option) => (
38+
<SettingPanel key={option.modelKey} title={option.title} desc={option.desc} icon={option.icon}>
39+
<ModelSelect modelKey={option.modelKey} />
40+
</SettingPanel>
41+
))
5142
)
5243
}

0 commit comments

Comments
 (0)