Extending support for Caching to all LLM's.

This commit is contained in:
vinodkiran
2023-09-29 08:19:44 +05:30
parent d588ac0480
commit d81869fd59
8 changed files with 83 additions and 15 deletions
@@ -2,6 +2,7 @@ import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Inter
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
import { GoogleVertexAI, GoogleVertexAITextInput } from 'langchain/llms/googlevertexai'
import { GoogleAuthOptions } from 'google-auth-library'
import { BaseCache } from 'langchain/schema'
class GoogleVertexAI_LLMs implements INode {
label: string
@@ -18,7 +19,7 @@ class GoogleVertexAI_LLMs implements INode {
constructor() {
this.label = 'GoogleVertexAI'
this.name = 'googlevertexai'
this.version = 1.0
this.version = 2.0
this.type = 'GoogleVertexAI'
this.icon = 'vertexai.svg'
this.category = 'LLMs'
@@ -34,6 +35,12 @@ class GoogleVertexAI_LLMs implements INode {
'Google Vertex AI credential. If you are using a GCP service like Cloud Run, or if you have installed default credentials on your local machine, you do not need to set this credential.'
}
this.inputs = [
{
label: 'Cache',
name: 'llmCache',
type: 'LLMCache',
optional: true
},
{
label: 'Model Name',
name: 'modelName',
@@ -120,6 +127,7 @@ class GoogleVertexAI_LLMs implements INode {
const modelName = nodeData.inputs?.modelName as string
const maxOutputTokens = nodeData.inputs?.maxOutputTokens as string
const topP = nodeData.inputs?.topP as string
const llmCache = nodeData.inputs?.llmCache as BaseCache
const obj: Partial<GoogleVertexAITextInput> = {
temperature: parseFloat(temperature),
@@ -129,6 +137,7 @@ class GoogleVertexAI_LLMs implements INode {
if (maxOutputTokens) obj.maxOutputTokens = parseInt(maxOutputTokens, 10)
if (topP) obj.topP = parseFloat(topP)
if (llmCache) obj.cache = llmCache
const model = new GoogleVertexAI(obj)
return model