From 8f6bf11320ba24af3ebd924480968d776621e5c0 Mon Sep 17 00:00:00 2001 From: Neal_Tan <425088158@qq.com> Date: Sun, 30 Mar 2025 00:51:48 +0000 Subject: [PATCH 1/2] =?UTF-8?q?feat(Assistant):=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E8=AF=8D=E5=8F=98=E9=87=8F=E8=BE=93=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在编辑助手处添加了变量 - 保存智能体时可以保存变量 Fixed #4049 --- src/renderer/src/components/VariableList.tsx | 103 ++++++++++++++++ src/renderer/src/config/models.ts | 18 ++- .../src/pages/home/Tabs/AssistantItem.tsx | 3 + .../AssistantPromptSettings.tsx | 116 ++++++++++++++++-- src/renderer/src/services/ApiService.ts | 9 ++ src/renderer/src/types/index.ts | 7 ++ src/renderer/src/utils/index.ts | 19 +++ 7 files changed, 266 insertions(+), 9 deletions(-) create mode 100644 src/renderer/src/components/VariableList.tsx diff --git a/src/renderer/src/components/VariableList.tsx b/src/renderer/src/components/VariableList.tsx new file mode 100644 index 0000000000..324cf301a6 --- /dev/null +++ b/src/renderer/src/components/VariableList.tsx @@ -0,0 +1,103 @@ +import { DeleteOutlined, ImportOutlined } from '@ant-design/icons' +import { VStack } from '@renderer/components/Layout' +import { Variable } from '@renderer/types' +import { Button, Input, Tooltip } from 'antd' +import { useTranslation } from 'react-i18next' +import styled from 'styled-components' + +interface VariableListProps { + variables: Variable[] + setVariables: (variables: Variable[]) => void + onUpdate?: (variables: Variable[]) => void + onInsertVariable?: (name: string) => void +} + +const VariableList: React.FC = ({ variables, setVariables, onUpdate, onInsertVariable }) => { + const { t } = useTranslation() + + const deleteVariable = (id: string) => { + const updatedVariables = variables.filter((v) => v.id !== id) + setVariables(updatedVariables) + + if (onUpdate) { + onUpdate(updatedVariables) + } + } + + const updateVariable = (id: string, field: 'name' | 'value', value: string) => { + // Only update the local state when typing, don't call the parent's onUpdate + const updatedVariables = variables.map((v) => (v.id === id ? { ...v, [field]: value } : v)) + setVariables(updatedVariables) + } + + // This function will be called when input loses focus + const handleInputBlur = () => { + if (onUpdate) { + onUpdate(variables) + } + } + + return ( + + {variables.length === 0 ? ( + {t('common.no_variables_added')} + ) : ( + + {variables.map((variable) => ( + + updateVariable(variable.id, 'name', e.target.value)} + onBlur={handleInputBlur} + style={{ width: '30%' }} + /> + updateVariable(variable.id, 'value', e.target.value)} + onBlur={handleInputBlur} + style={{ flex: 1 }} + /> + {onInsertVariable && ( + + + + )} + + + diff --git a/src/renderer/src/i18n/locales/en-us.json b/src/renderer/src/i18n/locales/en-us.json index fcb5d9a4fc..2573a6e55f 100644 --- a/src/renderer/src/i18n/locales/en-us.json +++ b/src/renderer/src/i18n/locales/en-us.json @@ -275,7 +275,13 @@ "select": "Select", "topics": "Topics", "warning": "Warning", - "you": "You" + "you": "You", + "variable_name": "Variable Name", + "value": "Value", + "no_variables_added": "No variables added", + "insert_variable_into_prompt": "Insert variable into prompt", + "variables": "Variables", + "variables_help": "Add variables that need to be replaced in the text, triggered by {{variable_name}} in the replacement document" }, "docs": { "title": "Docs" diff --git a/src/renderer/src/i18n/locales/ja-jp.json b/src/renderer/src/i18n/locales/ja-jp.json index 6d752f08a5..281382d64d 100644 --- a/src/renderer/src/i18n/locales/ja-jp.json +++ b/src/renderer/src/i18n/locales/ja-jp.json @@ -275,7 +275,13 @@ "select": "選択", "topics": "トピック", "warning": "警告", - "you": "あなた" + "you": "あなた", + "variable_name": "変数名", + "value": "値", + "no_variables_added": "変数がありません", + "insert_variable_into_prompt": "プロンプトに変数を挿入", + "variables": "変数", + "variables_help": "テキスト内で置換が必要な変数を追加し、置換ドキュメント内で{{variable_name}}の形式でトリガーします" }, "docs": { "title": "ドキュメント" diff --git a/src/renderer/src/i18n/locales/ru-ru.json b/src/renderer/src/i18n/locales/ru-ru.json index de6d5d8200..252d5c4834 100644 --- a/src/renderer/src/i18n/locales/ru-ru.json +++ b/src/renderer/src/i18n/locales/ru-ru.json @@ -275,7 +275,13 @@ "select": "Выбрать", "topics": "Топики", "warning": "Предупреждение", - "you": "Вы" + "you": "Вы", + "variable_name": "Имя переменной", + "value": "Значение", + "no_variables_added": "Нет переменных", + "insert_variable_into_prompt": "Вставить переменную в промпт", + "variables": "Переменные", + "variables_help": "Добавьте переменные, которые нужно заменить в тексте, замена срабатывает в формате {{variable_name}} в документе замены" }, "docs": { "title": "Документация" diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json index cd7d681523..62296d3f73 100644 --- a/src/renderer/src/i18n/locales/zh-cn.json +++ b/src/renderer/src/i18n/locales/zh-cn.json @@ -275,7 +275,13 @@ "select": "选择", "topics": "话题", "warning": "警告", - "you": "用户" + "you": "用户", + "variable_name": "变量名称", + "value": "值", + "no_variables_added": "没有添加变量", + "insert_variable_into_prompt": "插入变量到提示词", + "variables": "变量", + "variables_help": "添加需要替换的变量名字和值即可" }, "docs": { "title": "帮助文档" diff --git a/src/renderer/src/i18n/locales/zh-tw.json b/src/renderer/src/i18n/locales/zh-tw.json index 54b4f5464f..8a42ef4f37 100644 --- a/src/renderer/src/i18n/locales/zh-tw.json +++ b/src/renderer/src/i18n/locales/zh-tw.json @@ -275,7 +275,13 @@ "select": "選擇", "topics": "話題", "warning": "警告", - "you": "您" + "you": "您", + "variable_name": "變量名稱", + "value": "值", + "no_variables_added": "沒有添加變量", + "insert_variable_into_prompt": "插入變量到提示詞", + "variables": "變量", + "variables_help": "添加需要替換的變量名字和值即可" }, "docs": { "title": "說明文件"