Skip to content

Commit b386743

Browse files
authored
Merge pull request #713 from Yongtae723/feature/add_vertexAI
Feature/add vertex ai
2 parents b4f3d70 + 74abaa3 commit b386743

File tree

8 files changed

+357
-0
lines changed

8 files changed

+357
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { INodeParams, INodeCredential } from '../src/Interface'
2+
3+
class GoogleVertexAuth implements INodeCredential {
4+
label: string
5+
name: string
6+
version: number
7+
inputs: INodeParams[]
8+
9+
constructor() {
10+
this.label = 'Google Vertex Auth'
11+
this.name = 'googleVertexAuth'
12+
this.version = 1.0
13+
this.inputs = [
14+
{
15+
label: 'Google Application Credential File Path',
16+
name: 'googleApplicationCredentialFilePath',
17+
description:
18+
'Path to your google application credential json file. You can also use the credential JSON object (either one)',
19+
placeholder: 'your-path/application_default_credentials.json',
20+
type: 'string',
21+
optional: true
22+
},
23+
{
24+
label: 'Google Credential JSON Object',
25+
name: 'googleApplicationCredential',
26+
description: 'JSON object of your google application credential. You can also use the file path (either one)',
27+
placeholder: `{
28+
"type": ...,
29+
"project_id": ...,
30+
"private_key_id": ...,
31+
"private_key": ...,
32+
"client_email": ...,
33+
"client_id": ...,
34+
"auth_uri": ...,
35+
"token_uri": ...,
36+
"auth_provider_x509_cert_url": ...,
37+
"client_x509_cert_url": ...
38+
}`,
39+
type: 'string',
40+
rows: 4,
41+
optional: true
42+
},
43+
{
44+
label: 'Project ID',
45+
name: 'projectID',
46+
description: 'Project ID of GCP. If not provided, it will be read from the credential file',
47+
type: 'string',
48+
optional: true,
49+
additionalParams: true
50+
}
51+
]
52+
}
53+
}
54+
55+
module.exports = { credClass: GoogleVertexAuth }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
2+
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
3+
import { ChatGoogleVertexAI, GoogleVertexAIChatInput } from 'langchain/chat_models/googlevertexai'
4+
import { GoogleAuthOptions } from 'google-auth-library'
5+
6+
class GoogleVertexAI_ChatModels implements INode {
7+
label: string
8+
name: string
9+
version: number
10+
type: string
11+
icon: string
12+
category: string
13+
description: string
14+
baseClasses: string[]
15+
credential: INodeParams
16+
inputs: INodeParams[]
17+
18+
constructor() {
19+
this.label = 'ChatGoogleVertexAI'
20+
this.name = 'chatGoogleVertexAI'
21+
this.version = 1.0
22+
this.type = 'ChatGoogleVertexAI'
23+
this.icon = 'vertexai.svg'
24+
this.category = 'Chat Models'
25+
this.description = 'Wrapper around VertexAI large language models that use the Chat endpoint'
26+
this.baseClasses = [this.type, ...getBaseClasses(ChatGoogleVertexAI)]
27+
this.credential = {
28+
label: 'Connect Credential',
29+
name: 'credential',
30+
type: 'credential',
31+
credentialNames: ['googleVertexAuth']
32+
}
33+
this.inputs = [
34+
{
35+
label: 'Model Name',
36+
name: 'modelName',
37+
type: 'options',
38+
options: [
39+
{
40+
label: 'chat-bison',
41+
name: 'chat-bison'
42+
},
43+
{
44+
label: 'codechat-bison',
45+
name: 'codechat-bison'
46+
}
47+
],
48+
default: 'chat-bison',
49+
optional: true
50+
},
51+
{
52+
label: 'Temperature',
53+
name: 'temperature',
54+
type: 'number',
55+
step: 0.1,
56+
default: 0.9,
57+
optional: true
58+
},
59+
{
60+
label: 'Max Output Tokens',
61+
name: 'maxOutputTokens',
62+
type: 'number',
63+
step: 1,
64+
optional: true,
65+
additionalParams: true
66+
},
67+
{
68+
label: 'Top Probability',
69+
name: 'topP',
70+
type: 'number',
71+
step: 0.1,
72+
optional: true,
73+
additionalParams: true
74+
}
75+
]
76+
}
77+
78+
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
79+
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
80+
const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData)
81+
const googleApplicationCredential = getCredentialParam('googleApplicationCredential', credentialData, nodeData)
82+
const projectID = getCredentialParam('projectID', credentialData, nodeData)
83+
84+
if (!googleApplicationCredentialFilePath && !googleApplicationCredential)
85+
throw new Error('Please specify your Google Application Credential')
86+
if (googleApplicationCredentialFilePath && googleApplicationCredential)
87+
throw new Error('Please use either Google Application Credential File Path or Google Credential JSON Object')
88+
89+
const authOptions: GoogleAuthOptions = {}
90+
if (googleApplicationCredentialFilePath && !googleApplicationCredential) authOptions.keyFile = googleApplicationCredentialFilePath
91+
else if (!googleApplicationCredentialFilePath && googleApplicationCredential)
92+
authOptions.credentials = JSON.parse(googleApplicationCredential)
93+
94+
if (projectID) authOptions.projectId = projectID
95+
96+
const temperature = nodeData.inputs?.temperature as string
97+
const modelName = nodeData.inputs?.modelName as string
98+
const maxOutputTokens = nodeData.inputs?.maxOutputTokens as string
99+
const topP = nodeData.inputs?.topP as string
100+
101+
const obj: Partial<GoogleVertexAIChatInput> = {
102+
temperature: parseFloat(temperature),
103+
model: modelName,
104+
authOptions
105+
}
106+
107+
if (maxOutputTokens) obj.maxOutputTokens = parseInt(maxOutputTokens, 10)
108+
if (topP) obj.topP = parseFloat(topP)
109+
110+
const model = new ChatGoogleVertexAI(obj)
111+
return model
112+
}
113+
}
114+
115+
module.exports = { nodeClass: GoogleVertexAI_ChatModels }
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { GoogleVertexAIEmbeddings, GoogleVertexAIEmbeddingsParams } from 'langchain/embeddings/googlevertexai'
2+
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
3+
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
4+
import { GoogleAuthOptions } from 'google-auth-library'
5+
6+
class GoogleVertexAIEmbedding_Embeddings implements INode {
7+
label: string
8+
name: string
9+
version: number
10+
type: string
11+
icon: string
12+
category: string
13+
description: string
14+
baseClasses: string[]
15+
credential: INodeParams
16+
inputs: INodeParams[]
17+
18+
constructor() {
19+
this.label = 'GoogleVertexAI Embeddings'
20+
this.name = 'googlevertexaiEmbeddings'
21+
this.version = 1.0
22+
this.type = 'GoogleVertexAIEmbeddings'
23+
this.icon = 'vertexai.svg'
24+
this.category = 'Embeddings'
25+
this.description = 'Google vertexAI API to generate embeddings for a given text'
26+
this.baseClasses = [this.type, ...getBaseClasses(GoogleVertexAIEmbeddings)]
27+
this.credential = {
28+
label: 'Connect Credential',
29+
name: 'credential',
30+
type: 'credential',
31+
credentialNames: ['googleVertexAuth']
32+
}
33+
this.inputs = []
34+
}
35+
36+
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
37+
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
38+
const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData)
39+
const googleApplicationCredential = getCredentialParam('googleApplicationCredential', credentialData, nodeData)
40+
const projectID = getCredentialParam('projectID', credentialData, nodeData)
41+
42+
if (!googleApplicationCredentialFilePath && !googleApplicationCredential)
43+
throw new Error('Please specify your Google Application Credential')
44+
if (googleApplicationCredentialFilePath && googleApplicationCredential)
45+
throw new Error('Please use either Google Application Credential File Path or Google Credential JSON Object')
46+
47+
const authOptions: GoogleAuthOptions = {}
48+
if (googleApplicationCredentialFilePath && !googleApplicationCredential) authOptions.keyFile = googleApplicationCredentialFilePath
49+
else if (!googleApplicationCredentialFilePath && googleApplicationCredential)
50+
authOptions.credentials = JSON.parse(googleApplicationCredential)
51+
52+
if (projectID) authOptions.projectId = projectID
53+
54+
const obj: GoogleVertexAIEmbeddingsParams = {
55+
authOptions
56+
}
57+
58+
const model = new GoogleVertexAIEmbeddings(obj)
59+
return model
60+
}
61+
}
62+
63+
module.exports = { nodeClass: GoogleVertexAIEmbedding_Embeddings }
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
2+
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
3+
import { GoogleVertexAI, GoogleVertexAITextInput } from 'langchain/llms/googlevertexai'
4+
import { GoogleAuthOptions } from 'google-auth-library'
5+
6+
class GoogleVertexAI_LLMs implements INode {
7+
label: string
8+
name: string
9+
version: number
10+
type: string
11+
icon: string
12+
category: string
13+
description: string
14+
baseClasses: string[]
15+
credential: INodeParams
16+
inputs: INodeParams[]
17+
18+
constructor() {
19+
this.label = 'GoogleVertexAI'
20+
this.name = 'googlevertexai'
21+
this.version = 1.0
22+
this.type = 'GoogleVertexAI'
23+
this.icon = 'vertexai.svg'
24+
this.category = 'LLMs'
25+
this.description = 'Wrapper around GoogleVertexAI large language models'
26+
this.baseClasses = [this.type, ...getBaseClasses(GoogleVertexAI)]
27+
this.credential = {
28+
label: 'Connect Credential',
29+
name: 'credential',
30+
type: 'credential',
31+
credentialNames: ['googleVertexAuth']
32+
}
33+
this.inputs = [
34+
{
35+
label: 'Model Name',
36+
name: 'modelName',
37+
type: 'options',
38+
options: [
39+
{
40+
label: 'text-bison',
41+
name: 'text-bison'
42+
},
43+
{
44+
label: 'code-bison',
45+
name: 'code-bison'
46+
},
47+
{
48+
label: 'code-gecko',
49+
name: 'code-gecko'
50+
}
51+
],
52+
default: 'text-bison'
53+
},
54+
{
55+
label: 'Temperature',
56+
name: 'temperature',
57+
type: 'number',
58+
step: 0.1,
59+
default: 0.7,
60+
optional: true
61+
},
62+
{
63+
label: 'max Output Tokens',
64+
name: 'maxOutputTokens',
65+
type: 'number',
66+
step: 1,
67+
optional: true,
68+
additionalParams: true
69+
},
70+
{
71+
label: 'Top Probability',
72+
name: 'topP',
73+
type: 'number',
74+
step: 0.1,
75+
optional: true,
76+
additionalParams: true
77+
}
78+
]
79+
}
80+
81+
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
82+
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
83+
const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData)
84+
const googleApplicationCredential = getCredentialParam('googleApplicationCredential', credentialData, nodeData)
85+
const projectID = getCredentialParam('projectID', credentialData, nodeData)
86+
87+
if (!googleApplicationCredentialFilePath && !googleApplicationCredential)
88+
throw new Error('Please specify your Google Application Credential')
89+
if (googleApplicationCredentialFilePath && googleApplicationCredential)
90+
throw new Error('Please use either Google Application Credential File Path or Google Credential JSON Object')
91+
92+
const authOptions: GoogleAuthOptions = {}
93+
if (googleApplicationCredentialFilePath && !googleApplicationCredential) authOptions.keyFile = googleApplicationCredentialFilePath
94+
else if (!googleApplicationCredentialFilePath && googleApplicationCredential)
95+
authOptions.credentials = JSON.parse(googleApplicationCredential)
96+
if (projectID) authOptions.projectId = projectID
97+
98+
const temperature = nodeData.inputs?.temperature as string
99+
const modelName = nodeData.inputs?.modelName as string
100+
const maxOutputTokens = nodeData.inputs?.maxOutputTokens as string
101+
const topP = nodeData.inputs?.topP as string
102+
103+
const obj: Partial<GoogleVertexAITextInput> = {
104+
temperature: parseFloat(temperature),
105+
model: modelName,
106+
authOptions
107+
}
108+
109+
if (maxOutputTokens) obj.maxOutputTokens = parseInt(maxOutputTokens, 10)
110+
if (topP) obj.topP = parseFloat(topP)
111+
112+
const model = new GoogleVertexAI(obj)
113+
return model
114+
}
115+
}
116+
117+
module.exports = { nodeClass: GoogleVertexAI_LLMs }
Loading

0 commit comments

Comments
 (0)