implementation of embedding model

This commit is contained in:
Yongtae 2023-08-24 11:39:22 +09:00
parent 51e9cdf4c1
commit 0830b8fbe5
1 changed files with 21 additions and 8 deletions

View File

@ -80,20 +80,32 @@ class GoogleVertexAI_LLMs implements INode {
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const skipExtraCredentialFile = getCredentialParam('skipExtraCredentialFile', credentialData, nodeData)
const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData)
const googleApplicationCredential = getCredentialParam('googleApplicationCredential', credentialData, nodeData)
const projectID = getCredentialParam('projectID', credentialData, nodeData)
if (!googleApplicationCredentialFilePath && !googleApplicationCredential)
if (!skipExtraCredentialFile && !googleApplicationCredentialFilePath && !googleApplicationCredential)
throw new Error('Please specify your Google Application Credential')
if (googleApplicationCredentialFilePath && googleApplicationCredential)
throw new Error('Please use either Google Application Credential File Path or Google Credential JSON Object')
const inputs = [
googleApplicationCredentialFilePath,
googleApplicationCredential,
skipExtraCredentialFile
];
if (inputs.filter(Boolean).length > 1) {
throw new Error('Error: More than one component has been inputted. Please use only one of the following: Google Application Credential File Path, Google Credential JSON Object, or Skip Extra Credential File.')
}
const authOptions: GoogleAuthOptions = {}
if (googleApplicationCredentialFilePath && !googleApplicationCredential) authOptions.keyFile = googleApplicationCredentialFilePath
else if (!googleApplicationCredentialFilePath && googleApplicationCredential)
authOptions.credentials = JSON.parse(googleApplicationCredential)
if (projectID) authOptions.projectId = projectID
if (!skipExtraCredentialFile){
if (googleApplicationCredentialFilePath && !googleApplicationCredential) authOptions.keyFile = googleApplicationCredentialFilePath
else if (!googleApplicationCredentialFilePath && googleApplicationCredential)
authOptions.credentials = JSON.parse(googleApplicationCredential)
if (projectID) authOptions.projectId = projectID
}
const temperature = nodeData.inputs?.temperature as string
const modelName = nodeData.inputs?.modelName as string
@ -103,9 +115,10 @@ class GoogleVertexAI_LLMs implements INode {
const obj: Partial<GoogleVertexAITextInput> = {
temperature: parseFloat(temperature),
model: modelName,
authOptions
}
if (authOptions) obj.authOptions = authOptions
if (maxOutputTokens) obj.maxOutputTokens = parseInt(maxOutputTokens, 10)
if (topP) obj.topP = parseFloat(topP)