feat: add knowledge base settings to assistant (#1112)
* feat: #1047 * fix: allow clear
This commit is contained in:
parent
3f7e84e17c
commit
d4efbbb1bf
@ -6,6 +6,8 @@
|
|||||||
"add.name.placeholder": "Enter name",
|
"add.name.placeholder": "Enter name",
|
||||||
"add.prompt": "Prompt",
|
"add.prompt": "Prompt",
|
||||||
"add.prompt.placeholder": "Enter prompt",
|
"add.prompt.placeholder": "Enter prompt",
|
||||||
|
"add.knowledge_base": "Knowledge Base",
|
||||||
|
"add.knowledge_base.placeholder": "Select Knowledge Base",
|
||||||
"add.title": "Create Agent",
|
"add.title": "Create Agent",
|
||||||
"delete.popup.content": "Are you sure you want to delete this agent?",
|
"delete.popup.content": "Are you sure you want to delete this agent?",
|
||||||
"edit.message.add.title": "Add",
|
"edit.message.add.title": "Add",
|
||||||
@ -51,6 +53,7 @@
|
|||||||
"settings.model": "Model Settings",
|
"settings.model": "Model Settings",
|
||||||
"settings.preset_messages": "Preset Messages",
|
"settings.preset_messages": "Preset Messages",
|
||||||
"settings.prompt": "Prompt Settings",
|
"settings.prompt": "Prompt Settings",
|
||||||
|
"settings.knowledge_base": "Knowledge Base Settings",
|
||||||
"title": "Assistants"
|
"title": "Assistants"
|
||||||
},
|
},
|
||||||
"button": {
|
"button": {
|
||||||
@ -134,6 +137,7 @@
|
|||||||
"copy": "Copy",
|
"copy": "Copy",
|
||||||
"cut": "Cut",
|
"cut": "Cut",
|
||||||
"default": "Default",
|
"default": "Default",
|
||||||
|
"knowledge_base": "Knowledge Base",
|
||||||
"delete": "Delete",
|
"delete": "Delete",
|
||||||
"description": "Description",
|
"description": "Description",
|
||||||
"docs": "Docs",
|
"docs": "Docs",
|
||||||
|
|||||||
@ -6,6 +6,8 @@
|
|||||||
"add.name.placeholder": "名前を入力",
|
"add.name.placeholder": "名前を入力",
|
||||||
"add.prompt": "プロンプト",
|
"add.prompt": "プロンプト",
|
||||||
"add.prompt.placeholder": "プロンプトを入力",
|
"add.prompt.placeholder": "プロンプトを入力",
|
||||||
|
"add.knowledge_base": "ナレッジベース",
|
||||||
|
"add.knowledge_base.placeholder": "ナレッジベースを選択",
|
||||||
"add.title": "エージェントを作成",
|
"add.title": "エージェントを作成",
|
||||||
"delete.popup.content": "このエージェントを削除してもよろしいですか?",
|
"delete.popup.content": "このエージェントを削除してもよろしいですか?",
|
||||||
"edit.message.add.title": "追加",
|
"edit.message.add.title": "追加",
|
||||||
@ -46,6 +48,7 @@
|
|||||||
"settings.model": "モデル設定",
|
"settings.model": "モデル設定",
|
||||||
"settings.preset_messages": "プリセットメッセージ",
|
"settings.preset_messages": "プリセットメッセージ",
|
||||||
"settings.prompt": "プロンプト設定",
|
"settings.prompt": "プロンプト設定",
|
||||||
|
"settings.knowledge_base": "ナレッジベース設定",
|
||||||
"title": "アシスタント"
|
"title": "アシスタント"
|
||||||
},
|
},
|
||||||
"button": {
|
"button": {
|
||||||
@ -129,6 +132,7 @@
|
|||||||
"copy": "コピー",
|
"copy": "コピー",
|
||||||
"cut": "切り取り",
|
"cut": "切り取り",
|
||||||
"default": "デフォルト",
|
"default": "デフォルト",
|
||||||
|
"knowledge_base": "ナレッジベース",
|
||||||
"delete": "削除",
|
"delete": "削除",
|
||||||
"description": "説明",
|
"description": "説明",
|
||||||
"docs": "ドキュメント",
|
"docs": "ドキュメント",
|
||||||
|
|||||||
@ -6,6 +6,8 @@
|
|||||||
"add.name.placeholder": "Введите имя",
|
"add.name.placeholder": "Введите имя",
|
||||||
"add.prompt": "Промпт",
|
"add.prompt": "Промпт",
|
||||||
"add.prompt.placeholder": "Введите промпт",
|
"add.prompt.placeholder": "Введите промпт",
|
||||||
|
"add.knowledge_base": "База знаний",
|
||||||
|
"add.knowledge_base.placeholder": "Выберите базу знаний",
|
||||||
"add.title": "Создать агента",
|
"add.title": "Создать агента",
|
||||||
"delete.popup.content": "Вы уверены, что хотите удалить этого агента?",
|
"delete.popup.content": "Вы уверены, что хотите удалить этого агента?",
|
||||||
"edit.message.add.title": "Добавить",
|
"edit.message.add.title": "Добавить",
|
||||||
@ -46,6 +48,7 @@
|
|||||||
"settings.model": "Настройки модели",
|
"settings.model": "Настройки модели",
|
||||||
"settings.preset_messages": "Предустановленные сообщения",
|
"settings.preset_messages": "Предустановленные сообщения",
|
||||||
"settings.prompt": "Настройки промптов",
|
"settings.prompt": "Настройки промптов",
|
||||||
|
"settings.knowledge_base": "Настройки базы знаний",
|
||||||
"title": "Ассистенты"
|
"title": "Ассистенты"
|
||||||
},
|
},
|
||||||
"button": {
|
"button": {
|
||||||
@ -129,6 +132,7 @@
|
|||||||
"copy": "Копировать",
|
"copy": "Копировать",
|
||||||
"cut": "Вырезать",
|
"cut": "Вырезать",
|
||||||
"default": "По умолчанию",
|
"default": "По умолчанию",
|
||||||
|
"knowledge_base": "База знаний",
|
||||||
"delete": "Удалить",
|
"delete": "Удалить",
|
||||||
"description": "Описание",
|
"description": "Описание",
|
||||||
"docs": "Документы",
|
"docs": "Документы",
|
||||||
|
|||||||
@ -6,6 +6,8 @@
|
|||||||
"add.name.placeholder": "输入名称",
|
"add.name.placeholder": "输入名称",
|
||||||
"add.prompt": "提示词",
|
"add.prompt": "提示词",
|
||||||
"add.prompt.placeholder": "输入提示词",
|
"add.prompt.placeholder": "输入提示词",
|
||||||
|
"add.knowledge_base": "知识库",
|
||||||
|
"add.knowledge_base.placeholder": "选择知识库",
|
||||||
"add.title": "创建智能体",
|
"add.title": "创建智能体",
|
||||||
"delete.popup.content": "确定要删除此智能体吗?",
|
"delete.popup.content": "确定要删除此智能体吗?",
|
||||||
"edit.message.add.title": "添加",
|
"edit.message.add.title": "添加",
|
||||||
@ -51,6 +53,7 @@
|
|||||||
"settings.model": "模型设置",
|
"settings.model": "模型设置",
|
||||||
"settings.preset_messages": "预设消息",
|
"settings.preset_messages": "预设消息",
|
||||||
"settings.prompt": "提示词设置",
|
"settings.prompt": "提示词设置",
|
||||||
|
"settings.knowledge_base": "知识库设置",
|
||||||
"title": "助手"
|
"title": "助手"
|
||||||
},
|
},
|
||||||
"button": {
|
"button": {
|
||||||
@ -134,6 +137,7 @@
|
|||||||
"copy": "复制",
|
"copy": "复制",
|
||||||
"cut": "剪切",
|
"cut": "剪切",
|
||||||
"default": "默认",
|
"default": "默认",
|
||||||
|
"knowledge_base": "知识库",
|
||||||
"delete": "删除",
|
"delete": "删除",
|
||||||
"description": "描述",
|
"description": "描述",
|
||||||
"docs": "文档",
|
"docs": "文档",
|
||||||
|
|||||||
@ -6,6 +6,8 @@
|
|||||||
"add.name.placeholder": "輸入名稱",
|
"add.name.placeholder": "輸入名稱",
|
||||||
"add.prompt": "提示詞",
|
"add.prompt": "提示詞",
|
||||||
"add.prompt.placeholder": "輸入提示詞",
|
"add.prompt.placeholder": "輸入提示詞",
|
||||||
|
"add.knowledge_base": "知識庫",
|
||||||
|
"add.knowledge_base.placeholder": "選擇知識庫",
|
||||||
"add.title": "创建智能體",
|
"add.title": "创建智能體",
|
||||||
"delete.popup.content": "確定要刪除此智能體嗎?",
|
"delete.popup.content": "確定要刪除此智能體嗎?",
|
||||||
"edit.message.add.title": "添加",
|
"edit.message.add.title": "添加",
|
||||||
@ -51,6 +53,7 @@
|
|||||||
"settings.model": "模型設定",
|
"settings.model": "模型設定",
|
||||||
"settings.preset_messages": "預設訊息",
|
"settings.preset_messages": "預設訊息",
|
||||||
"settings.prompt": "提示詞設定",
|
"settings.prompt": "提示詞設定",
|
||||||
|
"settings.knowledge_base": "知識庫設定",
|
||||||
"title": "助手"
|
"title": "助手"
|
||||||
},
|
},
|
||||||
"button": {
|
"button": {
|
||||||
@ -134,6 +137,7 @@
|
|||||||
"copy": "複製",
|
"copy": "複製",
|
||||||
"cut": "剪下",
|
"cut": "剪下",
|
||||||
"default": "預設",
|
"default": "預設",
|
||||||
|
"knowledge_base": "知識庫",
|
||||||
"delete": "刪除",
|
"delete": "刪除",
|
||||||
"description": "描述",
|
"description": "描述",
|
||||||
"docs": "文件",
|
"docs": "文件",
|
||||||
|
|||||||
@ -1,15 +1,16 @@
|
|||||||
import 'emoji-picker-element'
|
import 'emoji-picker-element'
|
||||||
|
|
||||||
import { LoadingOutlined, ThunderboltOutlined } from '@ant-design/icons'
|
import { CheckOutlined, LoadingOutlined, ThunderboltOutlined } from '@ant-design/icons'
|
||||||
import EmojiPicker from '@renderer/components/EmojiPicker'
|
import EmojiPicker from '@renderer/components/EmojiPicker'
|
||||||
import { TopView } from '@renderer/components/TopView'
|
import { TopView } from '@renderer/components/TopView'
|
||||||
import { AGENT_PROMPT } from '@renderer/config/prompts'
|
import { AGENT_PROMPT } from '@renderer/config/prompts'
|
||||||
import { useAgents } from '@renderer/hooks/useAgents'
|
import { useAgents } from '@renderer/hooks/useAgents'
|
||||||
import { fetchGenerate } from '@renderer/services/ApiService'
|
import { fetchGenerate } from '@renderer/services/ApiService'
|
||||||
import { getDefaultModel } from '@renderer/services/AssistantService'
|
import { getDefaultModel } from '@renderer/services/AssistantService'
|
||||||
|
import { useAppSelector } from '@renderer/store'
|
||||||
import { Agent } from '@renderer/types'
|
import { Agent } from '@renderer/types'
|
||||||
import { getLeadingEmoji, uuid } from '@renderer/utils'
|
import { getLeadingEmoji, uuid } from '@renderer/utils'
|
||||||
import { Button, Form, FormInstance, Input, Modal, Popover } from 'antd'
|
import { Button, Form, FormInstance, Input, Modal, Popover, Select, SelectProps } from 'antd'
|
||||||
import TextArea from 'antd/es/input/TextArea'
|
import TextArea from 'antd/es/input/TextArea'
|
||||||
import { useRef, useState } from 'react'
|
import { useRef, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
@ -22,6 +23,7 @@ type FieldType = {
|
|||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
prompt: string
|
prompt: string
|
||||||
|
knowledge_base_id: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const PopupContainer: React.FC<Props> = ({ resolve }) => {
|
const PopupContainer: React.FC<Props> = ({ resolve }) => {
|
||||||
@ -32,6 +34,15 @@ const PopupContainer: React.FC<Props> = ({ resolve }) => {
|
|||||||
const formRef = useRef<FormInstance>(null)
|
const formRef = useRef<FormInstance>(null)
|
||||||
const [emoji, setEmoji] = useState('')
|
const [emoji, setEmoji] = useState('')
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
|
const knowledgeState = useAppSelector((state) => state.knowledge)
|
||||||
|
const knowledgeOptions: SelectProps['options'] = []
|
||||||
|
|
||||||
|
knowledgeState.bases.forEach((base) => {
|
||||||
|
knowledgeOptions.push({
|
||||||
|
label: base.name,
|
||||||
|
value: base.id
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
const onFinish = (values: FieldType) => {
|
const onFinish = (values: FieldType) => {
|
||||||
const _emoji = emoji || getLeadingEmoji(values.name)
|
const _emoji = emoji || getLeadingEmoji(values.name)
|
||||||
@ -43,6 +54,7 @@ const PopupContainer: React.FC<Props> = ({ resolve }) => {
|
|||||||
const _agent: Agent = {
|
const _agent: Agent = {
|
||||||
id: uuid(),
|
id: uuid(),
|
||||||
name: values.name,
|
name: values.name,
|
||||||
|
knowledge_base: knowledgeState.bases.find((t) => t.id === values.knowledge_base_id),
|
||||||
emoji: _emoji,
|
emoji: _emoji,
|
||||||
prompt: values.prompt,
|
prompt: values.prompt,
|
||||||
defaultModel: getDefaultModel(),
|
defaultModel: getDefaultModel(),
|
||||||
@ -133,6 +145,14 @@ const PopupContainer: React.FC<Props> = ({ resolve }) => {
|
|||||||
disabled={loading}
|
disabled={loading}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<Form.Item name="knowledge_base_id" label={t('agents.add.knowledge_base')} rules={[{ required: false }]}>
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
placeholder={t('agents.add.knowledge_base.placeholder')}
|
||||||
|
menuItemSelectedIcon={<CheckOutlined />}
|
||||||
|
options={knowledgeOptions}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -410,12 +410,13 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic }) => {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSelectedKnowledgeBase(undefined)
|
setSelectedKnowledgeBase(assistant.knowledge_base)
|
||||||
}, [assistant.id])
|
}, [assistant.id])
|
||||||
|
|
||||||
const textareaRows = window.innerHeight >= 1000 || isBubbleStyle ? 2 : 1
|
const textareaRows = window.innerHeight >= 1000 || isBubbleStyle ? 2 : 1
|
||||||
|
|
||||||
const handleKnowledgeBaseSelect = (base?: KnowledgeBase) => {
|
const handleKnowledgeBaseSelect = (base?: KnowledgeBase) => {
|
||||||
|
updateAssistant({ ...assistant, knowledge_base: base })
|
||||||
setSelectedKnowledgeBase(base)
|
setSelectedKnowledgeBase(base)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,59 @@
|
|||||||
|
import { CheckOutlined } from '@ant-design/icons'
|
||||||
|
import { Box } from '@renderer/components/Layout'
|
||||||
|
import { useAppSelector } from '@renderer/store'
|
||||||
|
import { Assistant, AssistantSettings } from '@renderer/types'
|
||||||
|
import { Select, SelectProps } from 'antd'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import styled from 'styled-components'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
assistant: Assistant
|
||||||
|
updateAssistant: (assistant: Assistant) => void
|
||||||
|
updateAssistantSettings: (settings: AssistantSettings) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
const AssistantKnowledgeBaseSettings: React.FC<Props> = ({ assistant, updateAssistant }) => {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
const knowledgeState = useAppSelector((state) => state.knowledge)
|
||||||
|
const knowledgeOptions: SelectProps['options'] = []
|
||||||
|
|
||||||
|
knowledgeState.bases.forEach((base) => {
|
||||||
|
knowledgeOptions.push({
|
||||||
|
label: base.name,
|
||||||
|
value: base.id
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const onUpdate = (value) => {
|
||||||
|
const knowledge_base = knowledgeState.bases.find((t) => t.id === value)
|
||||||
|
const _assistant = { ...assistant, knowledge_base }
|
||||||
|
updateAssistant(_assistant)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Container>
|
||||||
|
<Box mb={8} style={{ fontWeight: 'bold' }}>
|
||||||
|
{t('common.knowledge_base')}
|
||||||
|
</Box>
|
||||||
|
<Select
|
||||||
|
allowClear
|
||||||
|
defaultValue={assistant.knowledge_base?.id}
|
||||||
|
placeholder={t('agents.add.knowledge_base.placeholder')}
|
||||||
|
menuItemSelectedIcon={<CheckOutlined />}
|
||||||
|
options={knowledgeOptions}
|
||||||
|
onChange={(value) => onUpdate(value)}
|
||||||
|
/>
|
||||||
|
</Container>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const Container = styled.div`
|
||||||
|
display: flex;
|
||||||
|
flex: 1;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow: hidden;
|
||||||
|
padding: 5px;
|
||||||
|
`
|
||||||
|
|
||||||
|
export default AssistantKnowledgeBaseSettings
|
||||||
@ -8,6 +8,7 @@ import { useState } from 'react'
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
|
|
||||||
|
import AssistantKnowledgeBaseSettings from './AssistantKnowledgeBaseSettings'
|
||||||
import AssistantMessagesSettings from './AssistantMessagesSettings'
|
import AssistantMessagesSettings from './AssistantMessagesSettings'
|
||||||
import AssistantModelSettings from './AssistantModelSettings'
|
import AssistantModelSettings from './AssistantModelSettings'
|
||||||
import AssistantPromptSettings from './AssistantPromptSettings'
|
import AssistantPromptSettings from './AssistantPromptSettings'
|
||||||
@ -57,6 +58,10 @@ const AssistantSettingPopupContainer: React.FC<Props> = ({ resolve, ...props })
|
|||||||
{
|
{
|
||||||
key: 'messages',
|
key: 'messages',
|
||||||
label: t('assistants.settings.preset_messages')
|
label: t('assistants.settings.preset_messages')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'knowledge_base',
|
||||||
|
label: t('assistants.settings.knowledge_base')
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -115,6 +120,13 @@ const AssistantSettingPopupContainer: React.FC<Props> = ({ resolve, ...props })
|
|||||||
updateAssistantSettings={updateAssistantSettings}
|
updateAssistantSettings={updateAssistantSettings}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{menu === 'knowledge_base' && (
|
||||||
|
<AssistantKnowledgeBaseSettings
|
||||||
|
assistant={assistant}
|
||||||
|
updateAssistant={updateAssistant}
|
||||||
|
updateAssistantSettings={updateAssistantSettings}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Settings>
|
</Settings>
|
||||||
</HStack>
|
</HStack>
|
||||||
</StyledModal>
|
</StyledModal>
|
||||||
|
|||||||
@ -5,6 +5,7 @@ export type Assistant = {
|
|||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
prompt: string
|
prompt: string
|
||||||
|
knowledge_base?: KnowledgeBase
|
||||||
topics: Topic[]
|
topics: Topic[]
|
||||||
type: string
|
type: string
|
||||||
emoji?: string
|
emoji?: string
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user