From a483f944145c6d7de8ce0a825dc427e295f54778 Mon Sep 17 00:00:00 2001 From: definitelynotchirag Date: Mon, 21 Oct 2024 01:05:43 +0530 Subject: [PATCH 1/4] Refactor ChatOpenAI_ChatModels to include stopSequence parameter --- .../nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts b/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts index 5f3e1542904..5e8e34dea37 100644 --- a/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts +++ b/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts @@ -111,6 +111,13 @@ class ChatOpenAI_ChatModels implements INode { optional: true, additionalParams: true }, + { + label: 'Stop Sequence', + name: 'stopSequence', + type: 'string', + optional: true, + additionalParams: true + }, { label: 'BaseOptions', name: 'baseOptions', @@ -168,6 +175,7 @@ class ChatOpenAI_ChatModels implements INode { const frequencyPenalty = nodeData.inputs?.frequencyPenalty as string const presencePenalty = nodeData.inputs?.presencePenalty as string const timeout = nodeData.inputs?.timeout as string + const stopSequenceArray = nodeData.inputs?.stopSequence.split(" "); const streaming = nodeData.inputs?.streaming as boolean const basePath = nodeData.inputs?.basepath as string const proxyUrl = nodeData.inputs?.proxyUrl as string @@ -190,7 +198,7 @@ class ChatOpenAI_ChatModels implements INode { temperature: parseFloat(temperature), modelName, openAIApiKey, - streaming: streaming ?? true + streaming: streaming ?? true, } if (maxTokens) obj.maxTokens = parseInt(maxTokens, 10) @@ -199,6 +207,7 @@ class ChatOpenAI_ChatModels implements INode { if (presencePenalty) obj.presencePenalty = parseFloat(presencePenalty) if (timeout) obj.timeout = parseInt(timeout, 10) if (cache) obj.cache = cache + if (stopSequenceArray) obj.stop = stopSequenceArray let parsedBaseOptions: any | undefined = undefined @@ -230,7 +239,7 @@ class ChatOpenAI_ChatModels implements INode { imageResolution } } - + const model = new ChatOpenAI(nodeData.id, obj) model.setMultiModalOption(multiModalOption) return model From 88e1007b44e6e68c6ad872946617381ed99967cf Mon Sep 17 00:00:00 2001 From: definitelynotchirag Date: Mon, 21 Oct 2024 01:10:48 +0530 Subject: [PATCH 2/4] lint fix --- .../components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts b/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts index 5e8e34dea37..3e033085fbf 100644 --- a/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts +++ b/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts @@ -175,7 +175,7 @@ class ChatOpenAI_ChatModels implements INode { const frequencyPenalty = nodeData.inputs?.frequencyPenalty as string const presencePenalty = nodeData.inputs?.presencePenalty as string const timeout = nodeData.inputs?.timeout as string - const stopSequenceArray = nodeData.inputs?.stopSequence.split(" "); + const stopSequenceArray = nodeData.inputs?.stopSequence.split(' ') const streaming = nodeData.inputs?.streaming as boolean const basePath = nodeData.inputs?.basepath as string const proxyUrl = nodeData.inputs?.proxyUrl as string @@ -198,7 +198,7 @@ class ChatOpenAI_ChatModels implements INode { temperature: parseFloat(temperature), modelName, openAIApiKey, - streaming: streaming ?? true, + streaming: streaming ?? true } if (maxTokens) obj.maxTokens = parseInt(maxTokens, 10) @@ -239,7 +239,7 @@ class ChatOpenAI_ChatModels implements INode { imageResolution } } - + const model = new ChatOpenAI(nodeData.id, obj) model.setMultiModalOption(multiModalOption) return model From acbdef6af4ac189dcf6bb83f891ac729db9199ad Mon Sep 17 00:00:00 2001 From: definitelynotchirag Date: Mon, 21 Oct 2024 17:39:17 +0530 Subject: [PATCH 3/4] Stop Sequence String will now be split by comma --- packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts b/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts index 3e033085fbf..6f7a8e05a49 100644 --- a/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts +++ b/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts @@ -115,7 +115,9 @@ class ChatOpenAI_ChatModels implements INode { label: 'Stop Sequence', name: 'stopSequence', type: 'string', + rows: 4, optional: true, + description: 'List of stop words to use when generating. Use comma to separate multiple stop words.', additionalParams: true }, { @@ -175,7 +177,7 @@ class ChatOpenAI_ChatModels implements INode { const frequencyPenalty = nodeData.inputs?.frequencyPenalty as string const presencePenalty = nodeData.inputs?.presencePenalty as string const timeout = nodeData.inputs?.timeout as string - const stopSequenceArray = nodeData.inputs?.stopSequence.split(' ') + const stopSequenceArray = nodeData.inputs?.stopSequence.split(',') const streaming = nodeData.inputs?.streaming as boolean const basePath = nodeData.inputs?.basepath as string const proxyUrl = nodeData.inputs?.proxyUrl as string From 53b8d46afdd630588d54bf0e2a183bb108f6db26 Mon Sep 17 00:00:00 2001 From: Henry Heng Date: Mon, 21 Oct 2024 15:57:36 +0100 Subject: [PATCH 4/4] Update ChatOpenAI.ts --- .../components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts b/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts index 6f7a8e05a49..e12524ad022 100644 --- a/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts +++ b/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts @@ -177,7 +177,7 @@ class ChatOpenAI_ChatModels implements INode { const frequencyPenalty = nodeData.inputs?.frequencyPenalty as string const presencePenalty = nodeData.inputs?.presencePenalty as string const timeout = nodeData.inputs?.timeout as string - const stopSequenceArray = nodeData.inputs?.stopSequence.split(',') + const stopSequence = nodeData.inputs?.stopSequence as string const streaming = nodeData.inputs?.streaming as boolean const basePath = nodeData.inputs?.basepath as string const proxyUrl = nodeData.inputs?.proxyUrl as string @@ -209,7 +209,10 @@ class ChatOpenAI_ChatModels implements INode { if (presencePenalty) obj.presencePenalty = parseFloat(presencePenalty) if (timeout) obj.timeout = parseInt(timeout, 10) if (cache) obj.cache = cache - if (stopSequenceArray) obj.stop = stopSequenceArray + if (stopSequence) { + const stopSequenceArray = stopSequence.split(',').map((item) => item.trim()) + obj.stop = stopSequenceArray + } let parsedBaseOptions: any | undefined = undefined