mirror of https://github.com/FlowiseAI/Flowise.git
Add Custom Dimensionality Support for OpenAI Embedding Components (#2249)
* Add Dimentions Feature to the OpenAIEmbeddings, based on https://js.langchain.com/docs/integrations/text_embedding/openai * Fixing typos and pushing it under Additional Data * peer-review comments, incremented version with a major and lintedpull/2260/head
parent
8d549f87b5
commit
f378dcc332
|
|
@ -18,7 +18,7 @@ class OpenAIEmbedding_Embeddings implements INode {
|
|||
constructor() {
|
||||
this.label = 'OpenAI Embeddings'
|
||||
this.name = 'openAIEmbeddings'
|
||||
this.version = 3.0
|
||||
this.version = 4.0
|
||||
this.type = 'OpenAIEmbeddings'
|
||||
this.icon = 'openai.svg'
|
||||
this.category = 'Embeddings'
|
||||
|
|
@ -65,6 +65,13 @@ class OpenAIEmbedding_Embeddings implements INode {
|
|||
type: 'string',
|
||||
optional: true,
|
||||
additionalParams: true
|
||||
},
|
||||
{
|
||||
label: 'Dimensions',
|
||||
name: 'dimensions',
|
||||
type: 'number',
|
||||
optional: true,
|
||||
additionalParams: true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -82,6 +89,7 @@ class OpenAIEmbedding_Embeddings implements INode {
|
|||
const timeout = nodeData.inputs?.timeout as string
|
||||
const basePath = nodeData.inputs?.basepath as string
|
||||
const modelName = nodeData.inputs?.modelName as string
|
||||
const dimensions = nodeData.inputs?.dimensions as string
|
||||
|
||||
if (nodeData.inputs?.credentialId) {
|
||||
nodeData.credential = nodeData.inputs?.credentialId
|
||||
|
|
@ -97,6 +105,7 @@ class OpenAIEmbedding_Embeddings implements INode {
|
|||
if (stripNewLines) obj.stripNewLines = stripNewLines
|
||||
if (batchSize) obj.batchSize = parseInt(batchSize, 10)
|
||||
if (timeout) obj.timeout = parseInt(timeout, 10)
|
||||
if (dimensions) obj.dimensions = parseInt(dimensions, 10)
|
||||
|
||||
const model = new OpenAIEmbeddings(obj, { basePath })
|
||||
return model
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class OpenAIEmbeddingCustom_Embeddings implements INode {
|
|||
constructor() {
|
||||
this.label = 'OpenAI Embeddings Custom'
|
||||
this.name = 'openAIEmbeddingsCustom'
|
||||
this.version = 1.0
|
||||
this.version = 2.0
|
||||
this.type = 'OpenAIEmbeddingsCustom'
|
||||
this.icon = 'openai.svg'
|
||||
this.category = 'Embeddings'
|
||||
|
|
@ -63,6 +63,13 @@ class OpenAIEmbeddingCustom_Embeddings implements INode {
|
|||
name: 'modelName',
|
||||
type: 'string',
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Dimensions',
|
||||
name: 'dimensions',
|
||||
type: 'number',
|
||||
optional: true,
|
||||
additionalParams: true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -73,6 +80,7 @@ class OpenAIEmbeddingCustom_Embeddings implements INode {
|
|||
const timeout = nodeData.inputs?.timeout as string
|
||||
const basePath = nodeData.inputs?.basepath as string
|
||||
const modelName = nodeData.inputs?.modelName as string
|
||||
const dimensions = nodeData.inputs?.dimensions as string
|
||||
|
||||
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||
const openAIApiKey = getCredentialParam('openAIApiKey', credentialData, nodeData)
|
||||
|
|
@ -85,6 +93,7 @@ class OpenAIEmbeddingCustom_Embeddings implements INode {
|
|||
if (batchSize) obj.batchSize = parseInt(batchSize, 10)
|
||||
if (timeout) obj.timeout = parseInt(timeout, 10)
|
||||
if (modelName) obj.modelName = modelName
|
||||
if (dimensions) obj.dimensions = parseInt(dimensions, 10)
|
||||
|
||||
const model = new OpenAIEmbeddings(obj, { basePath })
|
||||
return model
|
||||
|
|
|
|||
Loading…
Reference in New Issue