mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-29 11:01:18 +03:00
Add optional inputs for project ID and location in GoogleVertexAIEmbedding
This commit is contained in:
+26
-3
@@ -1,6 +1,7 @@
|
|||||||
import { GoogleVertexAIEmbeddings, GoogleVertexAIEmbeddingsParams } from 'langchain/embeddings/googlevertexai'
|
import { GoogleVertexAIEmbeddings, GoogleVertexAIEmbeddingsParams } from 'langchain/embeddings/googlevertexai'
|
||||||
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
|
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||||
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
||||||
|
import { GoogleAuthOptions } from 'google-auth-library'
|
||||||
|
|
||||||
class GoogleVertexAIEmbedding_Embeddings implements INode {
|
class GoogleVertexAIEmbedding_Embeddings implements INode {
|
||||||
label: string
|
label: string
|
||||||
@@ -29,20 +30,42 @@ class GoogleVertexAIEmbedding_Embeddings implements INode {
|
|||||||
type: 'credential',
|
type: 'credential',
|
||||||
credentialNames: ['googleVertexAuth']
|
credentialNames: ['googleVertexAuth']
|
||||||
}
|
}
|
||||||
this.inputs = []
|
this.inputs = [
|
||||||
|
{
|
||||||
|
label: 'Project ID',
|
||||||
|
name: 'projectID',
|
||||||
|
description: 'project id of GCP',
|
||||||
|
type: 'string',
|
||||||
|
additionalParams: true,
|
||||||
|
optional: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'location',
|
||||||
|
name: 'location',
|
||||||
|
description: 'location of API',
|
||||||
|
type: 'string',
|
||||||
|
additionalParams: true,
|
||||||
|
optional: true
|
||||||
|
},
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||||
|
const projectID = nodeData.inputs?.projectID as string
|
||||||
|
const location = nodeData.inputs?.location as string
|
||||||
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||||
const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData)
|
const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData)
|
||||||
|
|
||||||
const authOptions = {
|
const authOptions:GoogleAuthOptions = {
|
||||||
keyFile: googleApplicationCredentialFilePath,
|
keyFile: googleApplicationCredentialFilePath,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (projectID) authOptions.projectId = projectID
|
||||||
|
|
||||||
const obj: GoogleVertexAIEmbeddingsParams = {
|
const obj: GoogleVertexAIEmbeddingsParams = {
|
||||||
authOptions,
|
authOptions,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (location) obj.location = location
|
||||||
|
|
||||||
const embedding = new GoogleVertexAIEmbeddings(obj)
|
const embedding = new GoogleVertexAIEmbeddings(obj)
|
||||||
return embedding
|
return embedding
|
||||||
|
|||||||
Reference in New Issue
Block a user