From a851aefd5ade545b4107097b6ecf44a0620a8973 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Thu, 20 Feb 2025 22:47:35 -0600 Subject: [PATCH 1/2] integrate chat completion endpoint --- src/lib/helpers/http.js | 3 +- src/lib/helpers/types/conversationTypes.js | 6 - src/lib/helpers/types/instructTypes.js | 17 ++ src/lib/scss/app.scss | 1 + src/lib/scss/custom/pages/_instruction.scss | 85 ++++++ src/lib/services/api-endpoints.js | 1 + src/lib/services/instruct-service.js | 15 +- .../page/conversation/state-search.svelte | 2 +- src/routes/page/instruction/+page.svelte | 244 ++++++++++++++++++ .../instruction-setting.svelte | 180 +++++++++++++ .../instruction-state.svelte | 94 +++++++ svelte.config.js | 2 + 12 files changed, 640 insertions(+), 10 deletions(-) create mode 100644 src/lib/helpers/types/instructTypes.js create mode 100644 src/lib/scss/custom/pages/_instruction.scss create mode 100644 src/routes/page/instruction/+page.svelte create mode 100644 src/routes/page/instruction/instruction-components/instruction-setting.svelte create mode 100644 src/routes/page/instruction/instruction-components/instruction-state.svelte diff --git a/src/lib/helpers/http.js b/src/lib/helpers/http.js index 46799e05..e5003153 100644 --- a/src/lib/helpers/http.js +++ b/src/lib/helpers/http.js @@ -74,7 +74,8 @@ function skipLoader(config) { new RegExp('http(s*)://(.*?)/knowledge/(.*?)/search', 'g'), new RegExp('http(s*)://(.*?)/knowledge/vector/(.*?)/create', 'g'), new RegExp('http(s*)://(.*?)/knowledge/document/(.*?)/page', 'g'), - new RegExp('http(s*)://(.*?)/users', 'g') + new RegExp('http(s*)://(.*?)/users', 'g'), + new RegExp('http(s*)://(.*?)/instruct/chat-completion', 'g') ]; /** @type {RegExp[]} */ diff --git a/src/lib/helpers/types/conversationTypes.js b/src/lib/helpers/types/conversationTypes.js index 070b7b2a..577fe067 100644 --- a/src/lib/helpers/types/conversationTypes.js +++ b/src/lib/helpers/types/conversationTypes.js @@ -1,9 +1,3 @@ -/** - * @typedef {Object} InstructMessageModel - * @property {string} [instruction] - User provided prompt instead of predefined template. - * @property {string} [template] - The template name. - */ - /** * @typedef {Object} MessageConfig * @property {string} [taskId] - Optional task id. diff --git a/src/lib/helpers/types/instructTypes.js b/src/lib/helpers/types/instructTypes.js new file mode 100644 index 00000000..14054cf6 --- /dev/null +++ b/src/lib/helpers/types/instructTypes.js @@ -0,0 +1,17 @@ +/** + * @typedef {Object} InstructMessageModel + * @property {string} [instruction] - User provided prompt instead of predefined template. + * @property {string} [template] - The template name. + */ + +/** + * @typedef {Object} IncomingInstructRequest + * @property {string} text + * @property {string} [agentId] + * @property {string} [instruction] + * @property {string} [provider] + * @property {string} [model] + * @property {import('$conversationTypes').ConversationStateModel[]} [states] + */ + +export default {}; \ No newline at end of file diff --git a/src/lib/scss/app.scss b/src/lib/scss/app.scss index 604f0c2d..02692538 100644 --- a/src/lib/scss/app.scss +++ b/src/lib/scss/app.scss @@ -95,6 +95,7 @@ File: Main Css File @import "custom/pages/knowledgebase"; @import "custom/pages/users"; @import "custom/pages/roles"; +@import "custom/pages/instruction"; // Common @import "custom/common/animation"; diff --git a/src/lib/scss/custom/pages/_instruction.scss b/src/lib/scss/custom/pages/_instruction.scss new file mode 100644 index 00000000..3a06401c --- /dev/null +++ b/src/lib/scss/custom/pages/_instruction.scss @@ -0,0 +1,85 @@ +.instruction-container { + .text-count { + margin-top: 2px; + font-size: 10px; + } + + .instruction-result-container { + .instruction-result-body { + font-size: 15px; + padding: 5px 10px; + overflow-y: auto; + max-height: 500px; + scrollbar-width: thin; + } + } +} + +.instruction-border { + border: 1px dashed var(--bs-primary); + border-radius: 5px; +} + +.instruct-header { + font-size: 17px; + display: flex; + justify-content: space-between; +} + +.instruct-text-header { + font-size: 17px; + display: flex; + gap: 5px; +} + +.instruct-setting-container { + display: flex; + flex-wrap: wrap; + + .instruct-setting-section { + display: flex; + flex-direction: column; + gap: 20px; + } + + @media (max-width: 992px) { + .instruct-setting-section { + margin-top: 10px; + } + + .instruction-gap { + margin-top: 10px; + } + } + + .instruct-setting-item { + display: flex; + justify-content: center; + + .instruct-setting-dropdown { + width: 60%; + } + + @media (max-width: 992px) { + .instruct-setting-dropdown { + width: 100%; + } + } + } +} + +.instruct-setting-padding { + padding: 20px 10px; +} + +.instruct-state-container { + display: flex; + flex-direction: column; + gap: 10px; + + .instruct-state-item { + display: flex; + gap: 10px; + justify-content: center; + } +} \ No newline at end of file diff --git a/src/lib/services/api-endpoints.js b/src/lib/services/api-endpoints.js index 024db209..fca17e29 100644 --- a/src/lib/services/api-endpoints.js +++ b/src/lib/services/api-endpoints.js @@ -44,6 +44,7 @@ export const endpoints = { // agent instruct instructCompletionUrl: `${host}/instruct/{agentId}`, + chatCompletionUrl: `${host}/instruct/chat-completion`, // agent realtime interaction agentInitRealtimeSessionUrl: `${host}/agent/{agentId}/realtime/session`, diff --git a/src/lib/services/instruct-service.js b/src/lib/services/instruct-service.js index b8c9963c..f9bf8ff3 100644 --- a/src/lib/services/instruct-service.js +++ b/src/lib/services/instruct-service.js @@ -5,9 +5,20 @@ import axios from 'axios'; /** * Execute agent instruction by template or user provided prompt. * @param {string} agentId - * @param {import('$conversationTypes').InstructMessageModel} instruction + * @param {import('$instructTypes').InstructMessageModel} instruction */ export async function executeAgentInstruction(agentId, instruction) { let url = replaceUrl(endpoints.instructCompletionUrl, {agentId: agentId}); await axios.post(url, instruction); -} \ No newline at end of file +} + + +/** + * Execute chat completion. + * @param {import('$instructTypes').IncomingInstructRequest} request + */ +export async function sendChatCompletion(request) { + const url = endpoints.chatCompletionUrl; + const response = await axios.post(url, request); + return response.data; +} diff --git a/src/routes/page/conversation/state-search.svelte b/src/routes/page/conversation/state-search.svelte index 9067ace2..7296ae1f 100644 --- a/src/routes/page/conversation/state-search.svelte +++ b/src/routes/page/conversation/state-search.svelte @@ -53,7 +53,7 @@ placeholder="Enter a value" /> -