Addition of Google Gemini Chat Model, Credential and Associated Embeddings
This commit is contained in:
parent
6a17cdc315
commit
e7f13c87d8
|
|
@ -0,0 +1,25 @@
|
|||
import { INodeParams, INodeCredential } from '../src/Interface'
|
||||
|
||||
class GoogleGenerativeAICredential implements INodeCredential {
|
||||
label: string
|
||||
name: string
|
||||
version: number
|
||||
description: string
|
||||
inputs: INodeParams[]
|
||||
|
||||
constructor() {
|
||||
this.label = 'Google Generative AI'
|
||||
this.name = 'googleGenerativeAI'
|
||||
this.version = 1.0
|
||||
this.description = 'Get your <a target="_blank" href="https://ai.google.dev/tutorials/setup">API Key</a> here.'
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'Google AI API Key',
|
||||
name: 'googleGenerativeAPIKey',
|
||||
type: 'password'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { credClass: GoogleGenerativeAICredential }
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
||||
import { BaseCache } from 'langchain/schema'
|
||||
import { ChatGoogleGenerativeAI } from '@langchain/google-genai'
|
||||
|
||||
class GoogleGenerativeAI_ChatModels implements INode {
|
||||
label: string
|
||||
name: string
|
||||
version: number
|
||||
type: string
|
||||
icon: string
|
||||
category: string
|
||||
description: string
|
||||
baseClasses: string[]
|
||||
credential: INodeParams
|
||||
inputs: INodeParams[]
|
||||
|
||||
constructor() {
|
||||
this.label = 'ChatGoogleGenerativeAI'
|
||||
this.name = 'chatGoogleGenerativeAI'
|
||||
this.version = 2.0
|
||||
this.type = 'ChatGoogleGenerativeAI'
|
||||
this.icon = 'gemini.png'
|
||||
this.category = 'Chat Models'
|
||||
this.description = 'Wrapper around Google Gemini large language models that use the Chat endpoint'
|
||||
this.baseClasses = [this.type, ...getBaseClasses(ChatGoogleGenerativeAI)]
|
||||
this.credential = {
|
||||
label: 'Connect Credential',
|
||||
name: 'credential',
|
||||
type: 'credential',
|
||||
credentialNames: ['googleGenerativeAI'],
|
||||
optional: true,
|
||||
description: 'Google Generative AI credential.'
|
||||
}
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'Cache',
|
||||
name: 'cache',
|
||||
type: 'BaseCache',
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Model Name',
|
||||
name: 'modelName',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
label: 'gemini-pro',
|
||||
name: 'gemini-pro'
|
||||
}
|
||||
],
|
||||
default: 'gemini-pro',
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Temperature',
|
||||
name: 'temperature',
|
||||
type: 'number',
|
||||
step: 0.1,
|
||||
default: 0.9,
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Max Output Tokens',
|
||||
name: 'maxOutputTokens',
|
||||
type: 'number',
|
||||
step: 1,
|
||||
optional: true,
|
||||
additionalParams: true
|
||||
},
|
||||
{
|
||||
label: 'Top Probability',
|
||||
name: 'topP',
|
||||
type: 'number',
|
||||
step: 0.1,
|
||||
optional: true,
|
||||
additionalParams: true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||
const apiKey = getCredentialParam('googleGenerativeAPIKey', credentialData, nodeData)
|
||||
|
||||
const temperature = nodeData.inputs?.temperature as string
|
||||
const modelName = nodeData.inputs?.modelName as string
|
||||
const maxOutputTokens = nodeData.inputs?.maxOutputTokens as string
|
||||
const topP = nodeData.inputs?.topP as string
|
||||
const cache = nodeData.inputs?.cache as BaseCache
|
||||
|
||||
const obj = {
|
||||
apiKey: apiKey,
|
||||
modelName: modelName,
|
||||
maxOutputTokens: 2048
|
||||
}
|
||||
|
||||
if (maxOutputTokens) obj.maxOutputTokens = parseInt(maxOutputTokens, 10)
|
||||
|
||||
const model = new ChatGoogleGenerativeAI(obj)
|
||||
if (topP) model.topP = parseFloat(topP)
|
||||
if (cache) model.cache = cache
|
||||
if (temperature) model.temperature = parseInt(temperature)
|
||||
return model
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: GoogleGenerativeAI_ChatModels }
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 56 KiB |
|
|
@ -0,0 +1,105 @@
|
|||
import { GoogleVertexAIEmbeddings } from 'langchain/embeddings/googlevertexai'
|
||||
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
||||
import { GoogleGenerativeAIEmbeddings, GoogleGenerativeAIEmbeddingsParams } from '@langchain/google-genai'
|
||||
import { TaskType } from '@google/generative-ai'
|
||||
|
||||
class GoogleGenerativeAIEmbedding_Embeddings implements INode {
|
||||
label: string
|
||||
name: string
|
||||
version: number
|
||||
type: string
|
||||
icon: string
|
||||
category: string
|
||||
description: string
|
||||
baseClasses: string[]
|
||||
inputs: INodeParams[]
|
||||
credential: INodeParams
|
||||
|
||||
constructor() {
|
||||
this.label = 'GoogleGenerativeAI Embeddings'
|
||||
this.name = 'googleGenerativeAiEmbeddings'
|
||||
this.version = 1.0
|
||||
this.type = 'GoogleGenerativeAiEmbeddings'
|
||||
this.icon = 'gemini.png'
|
||||
this.category = 'Embeddings'
|
||||
this.description = 'Google Generative API to generate embeddings for a given text'
|
||||
this.baseClasses = [this.type, ...getBaseClasses(GoogleVertexAIEmbeddings)]
|
||||
this.credential = {
|
||||
label: 'Connect Credential',
|
||||
name: 'credential',
|
||||
type: 'credential',
|
||||
credentialNames: ['googleGenerativeAI'],
|
||||
optional: true,
|
||||
description: 'Google Generative AI credential.'
|
||||
}
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'Model Name',
|
||||
name: 'modelName',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
label: 'embedding-001',
|
||||
name: 'embedding-001'
|
||||
}
|
||||
],
|
||||
default: 'embedding-001'
|
||||
},
|
||||
{
|
||||
label: 'Task Type',
|
||||
name: 'tasktype',
|
||||
type: 'options',
|
||||
description: 'Type of task for which the embedding will be used',
|
||||
options: [
|
||||
{ label: 'TASK_TYPE_UNSPECIFIED', name: 'TASK_TYPE_UNSPECIFIED' },
|
||||
{ label: 'RETRIEVAL_QUERY', name: 'RETRIEVAL_QUERY' },
|
||||
{ label: 'RETRIEVAL_DOCUMENT', name: 'RETRIEVAL_DOCUMENT' },
|
||||
{ label: 'SEMANTIC_SIMILARITY', name: 'SEMANTIC_SIMILARITY' },
|
||||
{ label: 'CLASSIFICATION', name: 'CLASSIFICATION' },
|
||||
{ label: 'CLUSTERING', name: 'CLUSTERING' }
|
||||
],
|
||||
default: 'TASK_TYPE_UNSPECIFIED'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
// eslint-disable-next-line unused-imports/no-unused-vars
|
||||
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||
const modelName = nodeData.inputs?.modelName as string
|
||||
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||
const apiKey = getCredentialParam('googleGenerativeAPIKey', credentialData, nodeData)
|
||||
|
||||
let taskType: TaskType
|
||||
switch (nodeData.inputs?.tasktype as string) {
|
||||
case 'RETRIEVAL_QUERY':
|
||||
taskType = TaskType.RETRIEVAL_QUERY
|
||||
break
|
||||
case 'RETRIEVAL_DOCUMENT':
|
||||
taskType = TaskType.RETRIEVAL_DOCUMENT
|
||||
break
|
||||
case 'SEMANTIC_SIMILARITY':
|
||||
taskType = TaskType.SEMANTIC_SIMILARITY
|
||||
break
|
||||
case 'CLASSIFICATION':
|
||||
taskType = TaskType.CLASSIFICATION
|
||||
break
|
||||
case 'CLUSTERING':
|
||||
taskType = TaskType.CLUSTERING
|
||||
break
|
||||
default:
|
||||
taskType = TaskType.TASK_TYPE_UNSPECIFIED
|
||||
break
|
||||
}
|
||||
const obj: GoogleGenerativeAIEmbeddingsParams = {
|
||||
apiKey: apiKey,
|
||||
modelName: modelName,
|
||||
taskType: taskType
|
||||
}
|
||||
|
||||
const model = new GoogleGenerativeAIEmbeddings(obj)
|
||||
return model
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: GoogleGenerativeAIEmbedding_Embeddings }
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 56 KiB |
|
|
@ -26,6 +26,7 @@
|
|||
"@gomomento/sdk-core": "^1.51.1",
|
||||
"@google-ai/generativelanguage": "^0.2.1",
|
||||
"@huggingface/inference": "^2.6.1",
|
||||
"@langchain/google-genai": "^0.0.3",
|
||||
"@notionhq/client": "^2.2.8",
|
||||
"@opensearch-project/opensearch": "^1.2.0",
|
||||
"@pinecone-database/pinecone": "^1.1.1",
|
||||
|
|
|
|||
Loading…
Reference in New Issue