Skip to content

Commit

Permalink
Refactor ChatOpenAI_ChatModels to include stopSequence parameter (Flo…
Browse files Browse the repository at this point in the history
…wiseAI#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 <[email protected]>
  • Loading branch information
definitelynotchirag and HenryHengZJ authored Oct 21, 2024
1 parent a0d93f9 commit 35ce647
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 35ce647

Please sign in to comment.