mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-29 03:01:10 +03:00
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 linted
This commit is contained in:
@@ -18,7 +18,7 @@ class OpenAIEmbedding_Embeddings implements INode {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.label = 'OpenAI Embeddings'
|
this.label = 'OpenAI Embeddings'
|
||||||
this.name = 'openAIEmbeddings'
|
this.name = 'openAIEmbeddings'
|
||||||
this.version = 3.0
|
this.version = 4.0
|
||||||
this.type = 'OpenAIEmbeddings'
|
this.type = 'OpenAIEmbeddings'
|
||||||
this.icon = 'openai.svg'
|
this.icon = 'openai.svg'
|
||||||
this.category = 'Embeddings'
|
this.category = 'Embeddings'
|
||||||
@@ -65,6 +65,13 @@ class OpenAIEmbedding_Embeddings implements INode {
|
|||||||
type: 'string',
|
type: 'string',
|
||||||
optional: true,
|
optional: true,
|
||||||
additionalParams: 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 timeout = nodeData.inputs?.timeout as string
|
||||||
const basePath = nodeData.inputs?.basepath as string
|
const basePath = nodeData.inputs?.basepath as string
|
||||||
const modelName = nodeData.inputs?.modelName as string
|
const modelName = nodeData.inputs?.modelName as string
|
||||||
|
const dimensions = nodeData.inputs?.dimensions as string
|
||||||
|
|
||||||
if (nodeData.inputs?.credentialId) {
|
if (nodeData.inputs?.credentialId) {
|
||||||
nodeData.credential = nodeData.inputs?.credentialId
|
nodeData.credential = nodeData.inputs?.credentialId
|
||||||
@@ -97,6 +105,7 @@ class OpenAIEmbedding_Embeddings implements INode {
|
|||||||
if (stripNewLines) obj.stripNewLines = stripNewLines
|
if (stripNewLines) obj.stripNewLines = stripNewLines
|
||||||
if (batchSize) obj.batchSize = parseInt(batchSize, 10)
|
if (batchSize) obj.batchSize = parseInt(batchSize, 10)
|
||||||
if (timeout) obj.timeout = parseInt(timeout, 10)
|
if (timeout) obj.timeout = parseInt(timeout, 10)
|
||||||
|
if (dimensions) obj.dimensions = parseInt(dimensions, 10)
|
||||||
|
|
||||||
const model = new OpenAIEmbeddings(obj, { basePath })
|
const model = new OpenAIEmbeddings(obj, { basePath })
|
||||||
return model
|
return model
|
||||||
|
|||||||
+10
-1
@@ -17,7 +17,7 @@ class OpenAIEmbeddingCustom_Embeddings implements INode {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.label = 'OpenAI Embeddings Custom'
|
this.label = 'OpenAI Embeddings Custom'
|
||||||
this.name = 'openAIEmbeddingsCustom'
|
this.name = 'openAIEmbeddingsCustom'
|
||||||
this.version = 1.0
|
this.version = 2.0
|
||||||
this.type = 'OpenAIEmbeddingsCustom'
|
this.type = 'OpenAIEmbeddingsCustom'
|
||||||
this.icon = 'openai.svg'
|
this.icon = 'openai.svg'
|
||||||
this.category = 'Embeddings'
|
this.category = 'Embeddings'
|
||||||
@@ -63,6 +63,13 @@ class OpenAIEmbeddingCustom_Embeddings implements INode {
|
|||||||
name: 'modelName',
|
name: 'modelName',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
optional: true
|
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 timeout = nodeData.inputs?.timeout as string
|
||||||
const basePath = nodeData.inputs?.basepath as string
|
const basePath = nodeData.inputs?.basepath as string
|
||||||
const modelName = nodeData.inputs?.modelName as string
|
const modelName = nodeData.inputs?.modelName as string
|
||||||
|
const dimensions = nodeData.inputs?.dimensions as string
|
||||||
|
|
||||||
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||||
const openAIApiKey = getCredentialParam('openAIApiKey', credentialData, nodeData)
|
const openAIApiKey = getCredentialParam('openAIApiKey', credentialData, nodeData)
|
||||||
@@ -85,6 +93,7 @@ class OpenAIEmbeddingCustom_Embeddings implements INode {
|
|||||||
if (batchSize) obj.batchSize = parseInt(batchSize, 10)
|
if (batchSize) obj.batchSize = parseInt(batchSize, 10)
|
||||||
if (timeout) obj.timeout = parseInt(timeout, 10)
|
if (timeout) obj.timeout = parseInt(timeout, 10)
|
||||||
if (modelName) obj.modelName = modelName
|
if (modelName) obj.modelName = modelName
|
||||||
|
if (dimensions) obj.dimensions = parseInt(dimensions, 10)
|
||||||
|
|
||||||
const model = new OpenAIEmbeddings(obj, { basePath })
|
const model = new OpenAIEmbeddings(obj, { basePath })
|
||||||
return model
|
return model
|
||||||
|
|||||||
Reference in New Issue
Block a user