From 54282ba7e05109306485794c7f7f1b81b3a6bc31 Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Wed, 28 Feb 2024 02:23:50 +0100 Subject: [PATCH 1/3] feat: Use new API endpoint from Helix --- .../src/apps/helix/actions/new-chat/index.js | 47 ++++++------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/packages/backend/src/apps/helix/actions/new-chat/index.js b/packages/backend/src/apps/helix/actions/new-chat/index.js index aed5c131..54fa1c60 100644 --- a/packages/backend/src/apps/helix/actions/new-chat/index.js +++ b/packages/backend/src/apps/helix/actions/new-chat/index.js @@ -1,4 +1,3 @@ -import FormData from 'form-data'; import defineAction from '../../../../helpers/define-action.js'; export default defineAction({ @@ -17,39 +16,21 @@ export default defineAction({ ], async run($) { - const formData = new FormData(); - formData.append('input', $.step.parameters.input); - formData.append('mode', 'inference'); - formData.append('type', 'text'); - - const sessionResponse = await $.http.post('/api/v1/sessions', formData, { - headers: { - ...formData.getHeaders(), - }, + const response = await $.http.post('/api/v1/sessions/chat', { + session_id: '', + messages: [ + { + role: 'user', + content: { + content_type: 'text', + parts: [$.step.parameters.input], + }, + }, + ], }); - const sessionId = sessionResponse.data.id; - - let attempts = 0; - - while (attempts < 10) { - const response = await $.http.get(`/api/v1/sessions/${sessionId}`); - - const message = - response.data.interactions[response.data.interactions.length - 1]; - - if (message.creator === 'system' && message.state === 'complete') { - $.setActionItem({ - raw: message, - }); - - return; - } - - await new Promise((resolve) => setTimeout(resolve, 1000)); - attempts++; - } - - throw new Error('Failed to start a new chat session for Helix API!'); + $.setActionItem({ + raw: response.data, + }); }, }); From 2667548041ed8b1add7928a24b66b35e6d36ae5b Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Wed, 28 Feb 2024 13:44:04 +0100 Subject: [PATCH 2/3] feat: Introduce optional session ID for helix app --- .../backend/src/apps/helix/actions/new-chat/index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/apps/helix/actions/new-chat/index.js b/packages/backend/src/apps/helix/actions/new-chat/index.js index 54fa1c60..c0ba74da 100644 --- a/packages/backend/src/apps/helix/actions/new-chat/index.js +++ b/packages/backend/src/apps/helix/actions/new-chat/index.js @@ -13,11 +13,20 @@ export default defineAction({ description: 'Prompt to start the chat with.', variables: true, }, + { + label: 'Session ID', + key: 'sessionId', + type: 'string', + required: false, + description: + 'ID of the chat session to continue. Leave empty to start a new chat.', + variables: true, + }, ], async run($) { const response = await $.http.post('/api/v1/sessions/chat', { - session_id: '', + session_id: $.step.parameters.sessionId, messages: [ { role: 'user', From 31c92b43b4a57c0e3d5fdff9e356cbe12e8dae79 Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Wed, 28 Feb 2024 14:18:55 +0100 Subject: [PATCH 3/3] feat: Add optional system prompt variable to Helix app --- .../src/apps/helix/actions/new-chat/index.js | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/apps/helix/actions/new-chat/index.js b/packages/backend/src/apps/helix/actions/new-chat/index.js index c0ba74da..c430fbb0 100644 --- a/packages/backend/src/apps/helix/actions/new-chat/index.js +++ b/packages/backend/src/apps/helix/actions/new-chat/index.js @@ -5,14 +5,6 @@ export default defineAction({ key: 'newChat', description: 'Create a new chat session for Helix AI.', arguments: [ - { - label: 'Input', - key: 'input', - type: 'string', - required: true, - description: 'Prompt to start the chat with.', - variables: true, - }, { label: 'Session ID', key: 'sessionId', @@ -22,11 +14,29 @@ export default defineAction({ 'ID of the chat session to continue. Leave empty to start a new chat.', variables: true, }, + { + label: 'System Prompt', + key: 'systemPrompt', + type: 'string', + required: false, + description: + 'Optional system prompt to start the chat with. It will be used only for new chat sessions.', + variables: true, + }, + { + label: 'Input', + key: 'input', + type: 'string', + required: true, + description: 'User input to start the chat with.', + variables: true, + }, ], async run($) { const response = await $.http.post('/api/v1/sessions/chat', { session_id: $.step.parameters.sessionId, + system: $.step.parameters.systemPrompt, messages: [ { role: 'user',