From 45f13f2b28502fd6e90007b07cc3841c27f326e1 Mon Sep 17 00:00:00 2001 From: Oren Zhang Date: Sun, 30 Jun 2024 12:35:46 +0800 Subject: [PATCH 1/4] feat: tool --- src/api/tool.js | 8 +++ src/components/ChatInput.vue | 112 ++++++++++++++++++++++++++++++++++- src/locale/en-us.js | 5 +- src/locale/zh-cn.js | 3 + 4 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 src/api/tool.js diff --git a/src/api/tool.js b/src/api/tool.js new file mode 100644 index 0000000..96a9f0e --- /dev/null +++ b/src/api/tool.js @@ -0,0 +1,8 @@ +import http from './index'; + +export const listToolsAPI = () => new Promise((resolve, reject) => { + http.get('/tools/').then( + (res) => resolve(res), + (err) => reject(err), + ); +}); diff --git a/src/components/ChatInput.vue b/src/components/ChatInput.vue index 8e25774..aa5313c 100644 --- a/src/components/ChatInput.vue +++ b/src/components/ChatInput.vue @@ -11,6 +11,7 @@ import {extractFileAPI, extractFileStatusAPI, getCOSConfigAPI, getCOSUploadTempK import {loadCOSClient} from '@/utils/cos'; import {IconFile, IconDelete} from '@arco-design/web-vue/es/icon'; import {listSystemPresetAPI} from '@/api/model'; +import {listToolsAPI} from '@/api/tool'; // props const props = defineProps({ @@ -109,6 +110,10 @@ const doChat = async () => { if (props.systemDefine) { params.messages.unshift({role: 'system', content: props.systemDefine}); } + // use tool + if (currentTool.value) { + params['tools'] = [currentTool.value]; + } // call api let key = ''; await preCheckAPI(params) @@ -361,6 +366,43 @@ onMounted(() => { } }); +// tools +const tools = ref([]); +const loadTools = () => { + listToolsAPI().then((res) => tools.value = res.data); +}; +onMounted(() => loadTools()); +const currentTool = ref(''); +const currentToolDesc = computed(() => { + let val = ''; + tools.value.forEach((item) => { + if (item.id === currentTool.value) { + val = item.desc; + } + }); + return val ? val : ''; +}); +const toolVisible = ref(true); +const changeTool = () => toolVisible.value = true; +const doSubmitTool = () => { + toolVisible.value = false; + localStorage.setItem(localToolKey.value, JSON.stringify(currentTool.value)); +}; +const resetTool = () => { + toolVisible.value = false; + currentTool.value = ''; + currentToolDesc.value = ''; +}; +const localToolKey = ref('local-tool'); +onMounted(() => { + const value = localStorage.getItem(localToolKey.value); + if (value) { + try { + currentTool.value = JSON.parse(value); + } catch (_) {} + } +}); + defineExpose({reGenerate, promptForm}); @@ -420,6 +462,16 @@ defineExpose({reGenerate, promptForm}); > + + + + + + + + + + +
+ {{ $t('ToolUseTips') }} +
+ + + {{ $t('Remove') }} + + + {{ $t('Save') }} + + +
+
:deep(.arco-space-item) { + width: 100%; +} diff --git a/src/locale/en-us.js b/src/locale/en-us.js index 3e92ccd..adea444 100644 --- a/src/locale/en-us.js +++ b/src/locale/en-us.js @@ -29,9 +29,12 @@ const mEnUS = { Save: 'Save', PleaseChoosePreset: 'Please choose one preset', Remove: 'Remove', - ModelIgnoreSystemDefineTips: 'Some models may ignore presets, if the output does not meet expectations, try switching models.', + ModelIgnoreSystemDefineTips: 'Some models may ignore presets, if the output does not meet expectations, try switching models', MaxMessagesCount: 'Max Context', ModelContextLengthTips: 'Context refers to historical messages and related information within a conversation. By carrying context, ChatGPT can better understand the user’s intent and adjust the content of its responses accordingly.', + Tools: 'Tools', + ToolUseTips: 'Some models do not support tool, if the output does not meet expectations, please switch models', + PleaseChooseTool: 'Please choose tool', }; export default mEnUS; diff --git a/src/locale/zh-cn.js b/src/locale/zh-cn.js index a35ad29..5f3e9fd 100644 --- a/src/locale/zh-cn.js +++ b/src/locale/zh-cn.js @@ -32,6 +32,9 @@ const mZhCN = { ModelIgnoreSystemDefineTips: '部分模型可能会忽略预设,如果输出不符合预期,请切换模型', MaxMessagesCount: '对话上下文数量', ModelContextLengthTips: '上下文是指对话中的历史消息和相关信息。通过携带上下文,模型可以更好地理解用户的意图,并对回复内容进行调整', + Tools: '插件', + ToolUseTips: '部分模型不支持插件,如果输出不符合预期,请切换模型', + PleaseChooseTool: '请选择插件', }; export default mZhCN; From 0764258dd9fc197e260d0226e8cee3d99f8539a5 Mon Sep 17 00:00:00 2001 From: Oren Zhang Date: Sun, 30 Jun 2024 15:37:49 +0800 Subject: [PATCH 2/4] feat: disable tool modal --- src/components/ChatInput.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ChatInput.vue b/src/components/ChatInput.vue index aa5313c..9012c5f 100644 --- a/src/components/ChatInput.vue +++ b/src/components/ChatInput.vue @@ -382,7 +382,7 @@ const currentToolDesc = computed(() => { }); return val ? val : ''; }); -const toolVisible = ref(true); +const toolVisible = ref(false); const changeTool = () => toolVisible.value = true; const doSubmitTool = () => { toolVisible.value = false; From ab9d1543de3b0bf558f9bac53d7a32fed7bc74dc Mon Sep 17 00:00:00 2001 From: Oren Zhang Date: Sun, 30 Jun 2024 15:50:13 +0800 Subject: [PATCH 3/4] style: show loading when generating --- src/components/MessageContent.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MessageContent.vue b/src/components/MessageContent.vue index 0317a91..3df6315 100644 --- a/src/components/MessageContent.vue +++ b/src/components/MessageContent.vue @@ -80,7 +80,7 @@ const emits = defineEmits(['reGenerate']); {{ message.file.split('/').slice(-1)[0] }} - + Date: Sun, 30 Jun 2024 16:00:56 +0800 Subject: [PATCH 4/4] fix: loading icon unexpected --- src/components/MessageContent.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MessageContent.vue b/src/components/MessageContent.vue index 3df6315..ea8da40 100644 --- a/src/components/MessageContent.vue +++ b/src/components/MessageContent.vue @@ -80,7 +80,7 @@ const emits = defineEmits(['reGenerate']); {{ message.file.split('/').slice(-1)[0] }} - +