From 35ce647a38130e8556f0b25d404cd008e2b7ca6e Mon Sep 17 00:00:00 2001 From: Chirag Date: Mon, 21 Oct 2024 20:32:31 +0530 Subject: [PATCH] Refactor ChatOpenAI_ChatModels to include stopSequence parameter (#3388) * Refactor ChatOpenAI_ChatModels to include stopSequence parameter * lint fix * Stop Sequence String will now be split by comma * Update ChatOpenAI.ts --------- Co-authored-by: Henry Heng --- .../nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts b/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts index 5f3e15429..e12524ad0 100644 --- a/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts +++ b/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts @@ -111,6 +111,15 @@ class ChatOpenAI_ChatModels implements INode { optional: true, additionalParams: true }, + { + 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 + }, { label: 'BaseOptions', name: 'baseOptions', @@ -168,6 +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 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 @@ -199,6 +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 (stopSequence) { + const stopSequenceArray = stopSequence.split(',').map((item) => item.trim()) + obj.stop = stopSequenceArray + } let parsedBaseOptions: any | undefined = undefined