Addition of Cache Option for Chat Models

This commit is contained in:
vinodkiran
2023-10-08 11:44:43 +05:30
parent dbd655580d
commit 679eac1d0b
10 changed files with 115 additions and 16 deletions
@@ -2,6 +2,8 @@ import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Inter
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
import { ChatBedrock } from 'langchain/chat_models/bedrock' import { ChatBedrock } from 'langchain/chat_models/bedrock'
import { BaseBedrockInput } from 'langchain/dist/util/bedrock' import { BaseBedrockInput } from 'langchain/dist/util/bedrock'
import { BaseCache } from 'langchain/schema'
import { BaseLLMParams } from 'langchain/llms/base'
/** /**
* I had to run the following to build the component * I had to run the following to build the component
@@ -25,7 +27,7 @@ class AWSChatBedrock_ChatModels implements INode {
constructor() { constructor() {
this.label = 'AWS Bedrock' this.label = 'AWS Bedrock'
this.name = 'awsChatBedrock' this.name = 'awsChatBedrock'
this.version = 1.1 this.version = 2.0
this.type = 'AWSChatBedrock' this.type = 'AWSChatBedrock'
this.icon = 'awsBedrock.png' this.icon = 'awsBedrock.png'
this.category = 'Chat Models' this.category = 'Chat Models'
@@ -39,6 +41,12 @@ class AWSChatBedrock_ChatModels implements INode {
optional: true optional: true
} }
this.inputs = [ this.inputs = [
{
label: 'Cache',
name: 'cache',
type: 'LLMCache',
optional: true
},
{ {
label: 'Region', label: 'Region',
name: 'region', name: 'region',
@@ -130,8 +138,9 @@ class AWSChatBedrock_ChatModels implements INode {
const iModel = nodeData.inputs?.model as string const iModel = nodeData.inputs?.model as string
const iTemperature = nodeData.inputs?.temperature as string const iTemperature = nodeData.inputs?.temperature as string
const iMax_tokens_to_sample = nodeData.inputs?.max_tokens_to_sample as string const iMax_tokens_to_sample = nodeData.inputs?.max_tokens_to_sample as string
const cache = nodeData.inputs?.llmCache as BaseCache
const obj: BaseBedrockInput = { const obj: BaseBedrockInput & BaseLLMParams = {
region: iRegion, region: iRegion,
model: iModel, model: iModel,
maxTokens: parseInt(iMax_tokens_to_sample, 10), maxTokens: parseInt(iMax_tokens_to_sample, 10),
@@ -157,6 +166,7 @@ class AWSChatBedrock_ChatModels implements INode {
sessionToken: credentialApiSession sessionToken: credentialApiSession
} }
} }
if (cache) obj.cache = cache
const amazonBedrock = new ChatBedrock(obj) const amazonBedrock = new ChatBedrock(obj)
return amazonBedrock return amazonBedrock
@@ -2,6 +2,8 @@ import { OpenAIBaseInput } from 'langchain/dist/types/openai-types'
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 { AzureOpenAIInput, ChatOpenAI } from 'langchain/chat_models/openai' import { AzureOpenAIInput, ChatOpenAI } from 'langchain/chat_models/openai'
import { BaseCache } from 'langchain/schema'
import { BaseLLMParams } from 'langchain/llms/base'
class AzureChatOpenAI_ChatModels implements INode { class AzureChatOpenAI_ChatModels implements INode {
label: string label: string
@@ -18,7 +20,7 @@ class AzureChatOpenAI_ChatModels implements INode {
constructor() { constructor() {
this.label = 'Azure ChatOpenAI' this.label = 'Azure ChatOpenAI'
this.name = 'azureChatOpenAI' this.name = 'azureChatOpenAI'
this.version = 1.0 this.version = 2.0
this.type = 'AzureChatOpenAI' this.type = 'AzureChatOpenAI'
this.icon = 'Azure.svg' this.icon = 'Azure.svg'
this.category = 'Chat Models' this.category = 'Chat Models'
@@ -31,6 +33,12 @@ class AzureChatOpenAI_ChatModels implements INode {
credentialNames: ['azureOpenAIApi'] credentialNames: ['azureOpenAIApi']
} }
this.inputs = [ this.inputs = [
{
label: 'Cache',
name: 'cache',
type: 'LLMCache',
optional: true
},
{ {
label: 'Model Name', label: 'Model Name',
name: 'modelName', name: 'modelName',
@@ -107,6 +115,7 @@ class AzureChatOpenAI_ChatModels implements INode {
const presencePenalty = nodeData.inputs?.presencePenalty as string const presencePenalty = nodeData.inputs?.presencePenalty as string
const timeout = nodeData.inputs?.timeout as string const timeout = nodeData.inputs?.timeout as string
const streaming = nodeData.inputs?.streaming as boolean const streaming = nodeData.inputs?.streaming as boolean
const cache = nodeData.inputs?.llmCache as BaseCache
const credentialData = await getCredentialData(nodeData.credential ?? '', options) const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const azureOpenAIApiKey = getCredentialParam('azureOpenAIApiKey', credentialData, nodeData) const azureOpenAIApiKey = getCredentialParam('azureOpenAIApiKey', credentialData, nodeData)
@@ -114,7 +123,7 @@ class AzureChatOpenAI_ChatModels implements INode {
const azureOpenAIApiDeploymentName = getCredentialParam('azureOpenAIApiDeploymentName', credentialData, nodeData) const azureOpenAIApiDeploymentName = getCredentialParam('azureOpenAIApiDeploymentName', credentialData, nodeData)
const azureOpenAIApiVersion = getCredentialParam('azureOpenAIApiVersion', credentialData, nodeData) const azureOpenAIApiVersion = getCredentialParam('azureOpenAIApiVersion', credentialData, nodeData)
const obj: Partial<AzureOpenAIInput> & Partial<OpenAIBaseInput> = { const obj: Partial<AzureOpenAIInput> & BaseLLMParams & Partial<OpenAIBaseInput> = {
temperature: parseFloat(temperature), temperature: parseFloat(temperature),
modelName, modelName,
azureOpenAIApiKey, azureOpenAIApiKey,
@@ -128,6 +137,7 @@ class AzureChatOpenAI_ChatModels implements INode {
if (frequencyPenalty) obj.frequencyPenalty = parseFloat(frequencyPenalty) if (frequencyPenalty) obj.frequencyPenalty = parseFloat(frequencyPenalty)
if (presencePenalty) obj.presencePenalty = parseFloat(presencePenalty) if (presencePenalty) obj.presencePenalty = parseFloat(presencePenalty)
if (timeout) obj.timeout = parseInt(timeout, 10) if (timeout) obj.timeout = parseInt(timeout, 10)
if (cache) obj.cache = cache
const model = new ChatOpenAI(obj) const model = new ChatOpenAI(obj)
return model return model
@@ -1,6 +1,7 @@
import { INode, INodeData, INodeParams } from '../../../src/Interface' import { INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses } from '../../../src/utils' import { getBaseClasses } from '../../../src/utils'
import { NIBittensorChatModel, BittensorInput } from 'langchain/experimental/chat_models/bittensor' import { NIBittensorChatModel, BittensorInput } from 'langchain/experimental/chat_models/bittensor'
import { BaseCache } from 'langchain/schema'
class Bittensor_ChatModels implements INode { class Bittensor_ChatModels implements INode {
label: string label: string
@@ -16,13 +17,19 @@ class Bittensor_ChatModels implements INode {
constructor() { constructor() {
this.label = 'NIBittensorChat' this.label = 'NIBittensorChat'
this.name = 'NIBittensorChatModel' this.name = 'NIBittensorChatModel'
this.version = 1.0 this.version = 2.0
this.type = 'BittensorChat' this.type = 'BittensorChat'
this.icon = 'logo.png' this.icon = 'logo.png'
this.category = 'Chat Models' this.category = 'Chat Models'
this.description = 'Wrapper around Bittensor subnet 1 large language models' this.description = 'Wrapper around Bittensor subnet 1 large language models'
this.baseClasses = [this.type, ...getBaseClasses(NIBittensorChatModel)] this.baseClasses = [this.type, ...getBaseClasses(NIBittensorChatModel)]
this.inputs = [ this.inputs = [
{
label: 'Cache',
name: 'cache',
type: 'LLMCache',
optional: true
},
{ {
label: 'System prompt', label: 'System prompt',
name: 'system_prompt', name: 'system_prompt',
@@ -35,9 +42,13 @@ class Bittensor_ChatModels implements INode {
async init(nodeData: INodeData, _: string): Promise<any> { async init(nodeData: INodeData, _: string): Promise<any> {
const system_prompt = nodeData.inputs?.system_prompt as string const system_prompt = nodeData.inputs?.system_prompt as string
const cache = nodeData.inputs?.llmCache as BaseCache
const obj: Partial<BittensorInput> = { const obj: Partial<BittensorInput> = {
systemPrompt: system_prompt systemPrompt: system_prompt
} }
if (cache) obj.cache = cache
const model = new NIBittensorChatModel(obj) const model = new NIBittensorChatModel(obj)
return model return model
} }
@@ -1,6 +1,8 @@
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 { AnthropicInput, ChatAnthropic } from 'langchain/chat_models/anthropic' import { AnthropicInput, ChatAnthropic } from 'langchain/chat_models/anthropic'
import { BaseCache } from 'langchain/schema'
import { BaseLLMParams } from 'langchain/llms/base'
class ChatAnthropic_ChatModels implements INode { class ChatAnthropic_ChatModels implements INode {
label: string label: string
@@ -17,7 +19,7 @@ class ChatAnthropic_ChatModels implements INode {
constructor() { constructor() {
this.label = 'ChatAnthropic' this.label = 'ChatAnthropic'
this.name = 'chatAnthropic' this.name = 'chatAnthropic'
this.version = 1.0 this.version = 2.0
this.type = 'ChatAnthropic' this.type = 'ChatAnthropic'
this.icon = 'chatAnthropic.png' this.icon = 'chatAnthropic.png'
this.category = 'Chat Models' this.category = 'Chat Models'
@@ -30,6 +32,12 @@ class ChatAnthropic_ChatModels implements INode {
credentialNames: ['anthropicApi'] credentialNames: ['anthropicApi']
} }
this.inputs = [ this.inputs = [
{
label: 'Cache',
name: 'cache',
type: 'LLMCache',
optional: true
},
{ {
label: 'Model Name', label: 'Model Name',
name: 'modelName', name: 'modelName',
@@ -135,11 +143,12 @@ class ChatAnthropic_ChatModels implements INode {
const topP = nodeData.inputs?.topP as string const topP = nodeData.inputs?.topP as string
const topK = nodeData.inputs?.topK as string const topK = nodeData.inputs?.topK as string
const streaming = nodeData.inputs?.streaming as boolean const streaming = nodeData.inputs?.streaming as boolean
const cache = nodeData.inputs?.llmCache as BaseCache
const credentialData = await getCredentialData(nodeData.credential ?? '', options) const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const anthropicApiKey = getCredentialParam('anthropicApiKey', credentialData, nodeData) const anthropicApiKey = getCredentialParam('anthropicApiKey', credentialData, nodeData)
const obj: Partial<AnthropicInput> & { anthropicApiKey?: string } = { const obj: Partial<AnthropicInput> & BaseLLMParams & { anthropicApiKey?: string } = {
temperature: parseFloat(temperature), temperature: parseFloat(temperature),
modelName, modelName,
anthropicApiKey, anthropicApiKey,
@@ -149,6 +158,7 @@ class ChatAnthropic_ChatModels implements INode {
if (maxTokensToSample) obj.maxTokensToSample = parseInt(maxTokensToSample, 10) if (maxTokensToSample) obj.maxTokensToSample = parseInt(maxTokensToSample, 10)
if (topP) obj.topP = parseFloat(topP) if (topP) obj.topP = parseFloat(topP)
if (topK) obj.topK = parseFloat(topK) if (topK) obj.topK = parseFloat(topK)
if (cache) obj.cache = cache
const model = new ChatAnthropic(obj) const model = new ChatAnthropic(obj)
return model return model
@@ -1,6 +1,7 @@
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 { ChatGooglePaLM, GooglePaLMChatInput } from 'langchain/chat_models/googlepalm' import { ChatGooglePaLM, GooglePaLMChatInput } from 'langchain/chat_models/googlepalm'
import { BaseCache } from 'langchain/schema'
class ChatGooglePaLM_ChatModels implements INode { class ChatGooglePaLM_ChatModels implements INode {
label: string label: string
@@ -17,7 +18,7 @@ class ChatGooglePaLM_ChatModels implements INode {
constructor() { constructor() {
this.label = 'ChatGooglePaLM' this.label = 'ChatGooglePaLM'
this.name = 'chatGooglePaLM' this.name = 'chatGooglePaLM'
this.version = 1.0 this.version = 2.0
this.type = 'ChatGooglePaLM' this.type = 'ChatGooglePaLM'
this.icon = 'Google_PaLM_Logo.svg' this.icon = 'Google_PaLM_Logo.svg'
this.category = 'Chat Models' this.category = 'Chat Models'
@@ -30,6 +31,12 @@ class ChatGooglePaLM_ChatModels implements INode {
credentialNames: ['googleMakerSuite'] credentialNames: ['googleMakerSuite']
} }
this.inputs = [ this.inputs = [
{
label: 'Cache',
name: 'cache',
type: 'LLMCache',
optional: true
},
{ {
label: 'Model Name', label: 'Model Name',
name: 'modelName', name: 'modelName',
@@ -96,6 +103,7 @@ class ChatGooglePaLM_ChatModels implements INode {
const temperature = nodeData.inputs?.temperature as string const temperature = nodeData.inputs?.temperature as string
const topP = nodeData.inputs?.topP as string const topP = nodeData.inputs?.topP as string
const topK = nodeData.inputs?.topK as string const topK = nodeData.inputs?.topK as string
const cache = nodeData.inputs?.llmCache as BaseCache
const credentialData = await getCredentialData(nodeData.credential ?? '', options) const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const googleMakerSuiteKey = getCredentialParam('googleMakerSuiteKey', credentialData, nodeData) const googleMakerSuiteKey = getCredentialParam('googleMakerSuiteKey', credentialData, nodeData)
@@ -108,6 +116,7 @@ class ChatGooglePaLM_ChatModels implements INode {
if (topP) obj.topP = parseFloat(topP) if (topP) obj.topP = parseFloat(topP)
if (topK) obj.topK = parseFloat(topK) if (topK) obj.topK = parseFloat(topK)
if (cache) obj.cache = cache
const model = new ChatGooglePaLM(obj) const model = new ChatGooglePaLM(obj)
return model return model
@@ -2,6 +2,7 @@ import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Inter
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
import { ChatGoogleVertexAI, GoogleVertexAIChatInput } from 'langchain/chat_models/googlevertexai' import { ChatGoogleVertexAI, GoogleVertexAIChatInput } from 'langchain/chat_models/googlevertexai'
import { GoogleAuthOptions } from 'google-auth-library' import { GoogleAuthOptions } from 'google-auth-library'
import { BaseCache } from 'langchain/schema'
class GoogleVertexAI_ChatModels implements INode { class GoogleVertexAI_ChatModels implements INode {
label: string label: string
@@ -18,7 +19,7 @@ class GoogleVertexAI_ChatModels implements INode {
constructor() { constructor() {
this.label = 'ChatGoogleVertexAI' this.label = 'ChatGoogleVertexAI'
this.name = 'chatGoogleVertexAI' this.name = 'chatGoogleVertexAI'
this.version = 1.0 this.version = 2.0
this.type = 'ChatGoogleVertexAI' this.type = 'ChatGoogleVertexAI'
this.icon = 'vertexai.svg' this.icon = 'vertexai.svg'
this.category = 'Chat Models' this.category = 'Chat Models'
@@ -34,6 +35,12 @@ class GoogleVertexAI_ChatModels 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.' '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 = [ this.inputs = [
{
label: 'Cache',
name: 'cache',
type: 'LLMCache',
optional: true
},
{ {
label: 'Model Name', label: 'Model Name',
name: 'modelName', name: 'modelName',
@@ -113,6 +120,7 @@ class GoogleVertexAI_ChatModels implements INode {
const modelName = nodeData.inputs?.modelName as string const modelName = nodeData.inputs?.modelName as string
const maxOutputTokens = nodeData.inputs?.maxOutputTokens as string const maxOutputTokens = nodeData.inputs?.maxOutputTokens as string
const topP = nodeData.inputs?.topP as string const topP = nodeData.inputs?.topP as string
const cache = nodeData.inputs?.llmCache as BaseCache
const obj: GoogleVertexAIChatInput<GoogleAuthOptions> = { const obj: GoogleVertexAIChatInput<GoogleAuthOptions> = {
temperature: parseFloat(temperature), temperature: parseFloat(temperature),
@@ -122,6 +130,7 @@ class GoogleVertexAI_ChatModels implements INode {
if (maxOutputTokens) obj.maxOutputTokens = parseInt(maxOutputTokens, 10) if (maxOutputTokens) obj.maxOutputTokens = parseInt(maxOutputTokens, 10)
if (topP) obj.topP = parseFloat(topP) if (topP) obj.topP = parseFloat(topP)
if (cache) obj.cache = cache
const model = new ChatGoogleVertexAI(obj) const model = new ChatGoogleVertexAI(obj)
return model return model
@@ -1,6 +1,7 @@
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 { HFInput, HuggingFaceInference } from './core' import { HFInput, HuggingFaceInference } from './core'
import { BaseCache } from 'langchain/schema'
class ChatHuggingFace_ChatModels implements INode { class ChatHuggingFace_ChatModels implements INode {
label: string label: string
@@ -17,7 +18,7 @@ class ChatHuggingFace_ChatModels implements INode {
constructor() { constructor() {
this.label = 'ChatHuggingFace' this.label = 'ChatHuggingFace'
this.name = 'chatHuggingFace' this.name = 'chatHuggingFace'
this.version = 1.0 this.version = 2.0
this.type = 'ChatHuggingFace' this.type = 'ChatHuggingFace'
this.icon = 'huggingface.png' this.icon = 'huggingface.png'
this.category = 'Chat Models' this.category = 'Chat Models'
@@ -30,6 +31,12 @@ class ChatHuggingFace_ChatModels implements INode {
credentialNames: ['huggingFaceApi'] credentialNames: ['huggingFaceApi']
} }
this.inputs = [ this.inputs = [
{
label: 'Cache',
name: 'cache',
type: 'LLMCache',
optional: true
},
{ {
label: 'Model', label: 'Model',
name: 'model', name: 'model',
@@ -102,6 +109,7 @@ class ChatHuggingFace_ChatModels implements INode {
const hfTopK = nodeData.inputs?.hfTopK as string const hfTopK = nodeData.inputs?.hfTopK as string
const frequencyPenalty = nodeData.inputs?.frequencyPenalty as string const frequencyPenalty = nodeData.inputs?.frequencyPenalty as string
const endpoint = nodeData.inputs?.endpoint as string const endpoint = nodeData.inputs?.endpoint as string
const cache = nodeData.inputs?.llmCache as BaseCache
const credentialData = await getCredentialData(nodeData.credential ?? '', options) const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const huggingFaceApiKey = getCredentialParam('huggingFaceApiKey', credentialData, nodeData) const huggingFaceApiKey = getCredentialParam('huggingFaceApiKey', credentialData, nodeData)
@@ -119,6 +127,7 @@ class ChatHuggingFace_ChatModels implements INode {
if (endpoint) obj.endpoint = endpoint if (endpoint) obj.endpoint = endpoint
const huggingFace = new HuggingFaceInference(obj) const huggingFace = new HuggingFaceInference(obj)
if (cache) huggingFace.cache = cache
return huggingFace return huggingFace
} }
} }
@@ -2,6 +2,8 @@ import { INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses } from '../../../src/utils' import { getBaseClasses } from '../../../src/utils'
import { OpenAIChat } from 'langchain/llms/openai' import { OpenAIChat } from 'langchain/llms/openai'
import { OpenAIChatInput } from 'langchain/chat_models/openai' import { OpenAIChatInput } from 'langchain/chat_models/openai'
import { BaseCache } from 'langchain/schema'
import { BaseLLMParams } from 'langchain/llms/base'
class ChatLocalAI_ChatModels implements INode { class ChatLocalAI_ChatModels implements INode {
label: string label: string
@@ -17,13 +19,19 @@ class ChatLocalAI_ChatModels implements INode {
constructor() { constructor() {
this.label = 'ChatLocalAI' this.label = 'ChatLocalAI'
this.name = 'chatLocalAI' this.name = 'chatLocalAI'
this.version = 1.0 this.version = 2.0
this.type = 'ChatLocalAI' this.type = 'ChatLocalAI'
this.icon = 'localai.png' this.icon = 'localai.png'
this.category = 'Chat Models' this.category = 'Chat Models'
this.description = 'Use local LLMs like llama.cpp, gpt4all using LocalAI' this.description = 'Use local LLMs like llama.cpp, gpt4all using LocalAI'
this.baseClasses = [this.type, 'BaseChatModel', ...getBaseClasses(OpenAIChat)] this.baseClasses = [this.type, 'BaseChatModel', ...getBaseClasses(OpenAIChat)]
this.inputs = [ this.inputs = [
{
label: 'Cache',
name: 'cache',
type: 'LLMCache',
optional: true
},
{ {
label: 'Base Path', label: 'Base Path',
name: 'basePath', name: 'basePath',
@@ -78,8 +86,9 @@ class ChatLocalAI_ChatModels implements INode {
const topP = nodeData.inputs?.topP as string const topP = nodeData.inputs?.topP as string
const timeout = nodeData.inputs?.timeout as string const timeout = nodeData.inputs?.timeout as string
const basePath = nodeData.inputs?.basePath as string const basePath = nodeData.inputs?.basePath as string
const cache = nodeData.inputs?.llmCache as BaseCache
const obj: Partial<OpenAIChatInput> & { openAIApiKey?: string } = { const obj: Partial<OpenAIChatInput> & BaseLLMParams & { openAIApiKey?: string } = {
temperature: parseFloat(temperature), temperature: parseFloat(temperature),
modelName, modelName,
openAIApiKey: 'sk-' openAIApiKey: 'sk-'
@@ -88,6 +97,7 @@ class ChatLocalAI_ChatModels implements INode {
if (maxTokens) obj.maxTokens = parseInt(maxTokens, 10) if (maxTokens) obj.maxTokens = parseInt(maxTokens, 10)
if (topP) obj.topP = parseFloat(topP) if (topP) obj.topP = parseFloat(topP)
if (timeout) obj.timeout = parseInt(timeout, 10) if (timeout) obj.timeout = parseInt(timeout, 10)
if (cache) obj.cache = cache
const model = new OpenAIChat(obj, { basePath }) const model = new OpenAIChat(obj, { basePath })
@@ -1,6 +1,8 @@
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 { ChatOpenAI, OpenAIChatInput } from 'langchain/chat_models/openai' import { ChatOpenAI, OpenAIChatInput } from 'langchain/chat_models/openai'
import { BaseCache } from 'langchain/schema'
import { BaseLLMParams } from 'langchain/llms/base'
class ChatOpenAI_ChatModels implements INode { class ChatOpenAI_ChatModels implements INode {
label: string label: string
@@ -17,7 +19,7 @@ class ChatOpenAI_ChatModels implements INode {
constructor() { constructor() {
this.label = 'ChatOpenAI' this.label = 'ChatOpenAI'
this.name = 'chatOpenAI' this.name = 'chatOpenAI'
this.version = 1.0 this.version = 2.0
this.type = 'ChatOpenAI' this.type = 'ChatOpenAI'
this.icon = 'openai.png' this.icon = 'openai.png'
this.category = 'Chat Models' this.category = 'Chat Models'
@@ -30,6 +32,12 @@ class ChatOpenAI_ChatModels implements INode {
credentialNames: ['openAIApi'] credentialNames: ['openAIApi']
} }
this.inputs = [ this.inputs = [
{
label: 'Cache',
name: 'cache',
type: 'LLMCache',
optional: true
},
{ {
label: 'Model Name', label: 'Model Name',
name: 'modelName', name: 'modelName',
@@ -151,7 +159,9 @@ class ChatOpenAI_ChatModels implements INode {
const credentialData = await getCredentialData(nodeData.credential ?? '', options) const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const openAIApiKey = getCredentialParam('openAIApiKey', credentialData, nodeData) const openAIApiKey = getCredentialParam('openAIApiKey', credentialData, nodeData)
const obj: Partial<OpenAIChatInput> & { openAIApiKey?: string } = { const cache = nodeData.inputs?.llmCache as BaseCache
const obj: Partial<OpenAIChatInput> & BaseLLMParams & { openAIApiKey?: string } = {
temperature: parseFloat(temperature), temperature: parseFloat(temperature),
modelName, modelName,
openAIApiKey, openAIApiKey,
@@ -163,6 +173,7 @@ class ChatOpenAI_ChatModels implements INode {
if (frequencyPenalty) obj.frequencyPenalty = parseFloat(frequencyPenalty) if (frequencyPenalty) obj.frequencyPenalty = parseFloat(frequencyPenalty)
if (presencePenalty) obj.presencePenalty = parseFloat(presencePenalty) if (presencePenalty) obj.presencePenalty = parseFloat(presencePenalty)
if (timeout) obj.timeout = parseInt(timeout, 10) if (timeout) obj.timeout = parseInt(timeout, 10)
if (cache) obj.cache = cache
let parsedBaseOptions: any | undefined = undefined let parsedBaseOptions: any | undefined = undefined
@@ -1,6 +1,8 @@
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 { ChatOpenAI, OpenAIChatInput } from 'langchain/chat_models/openai' import { ChatOpenAI, OpenAIChatInput } from 'langchain/chat_models/openai'
import { BaseCache } from 'langchain/schema'
import { BaseLLMParams } from 'langchain/llms/base'
class ChatOpenAICustom_ChatModels implements INode { class ChatOpenAICustom_ChatModels implements INode {
label: string label: string
@@ -17,7 +19,7 @@ class ChatOpenAICustom_ChatModels implements INode {
constructor() { constructor() {
this.label = 'ChatOpenAI Custom' this.label = 'ChatOpenAI Custom'
this.name = 'chatOpenAICustom' this.name = 'chatOpenAICustom'
this.version = 1.0 this.version = 2.0
this.type = 'ChatOpenAI-Custom' this.type = 'ChatOpenAI-Custom'
this.icon = 'openai.png' this.icon = 'openai.png'
this.category = 'Chat Models' this.category = 'Chat Models'
@@ -31,6 +33,12 @@ class ChatOpenAICustom_ChatModels implements INode {
optional: true optional: true
} }
this.inputs = [ this.inputs = [
{
label: 'Cache',
name: 'cache',
type: 'LLMCache',
optional: true
},
{ {
label: 'Model Name', label: 'Model Name',
name: 'modelName', name: 'modelName',
@@ -113,11 +121,12 @@ class ChatOpenAICustom_ChatModels implements INode {
const streaming = nodeData.inputs?.streaming as boolean const streaming = nodeData.inputs?.streaming as boolean
const basePath = nodeData.inputs?.basepath as string const basePath = nodeData.inputs?.basepath as string
const baseOptions = nodeData.inputs?.baseOptions const baseOptions = nodeData.inputs?.baseOptions
const cache = nodeData.inputs?.llmCache as BaseCache
const credentialData = await getCredentialData(nodeData.credential ?? '', options) const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const openAIApiKey = getCredentialParam('openAIApiKey', credentialData, nodeData) const openAIApiKey = getCredentialParam('openAIApiKey', credentialData, nodeData)
const obj: Partial<OpenAIChatInput> & { openAIApiKey?: string } = { const obj: Partial<OpenAIChatInput> & BaseLLMParams & { openAIApiKey?: string } = {
temperature: parseFloat(temperature), temperature: parseFloat(temperature),
modelName, modelName,
openAIApiKey, openAIApiKey,
@@ -129,6 +138,7 @@ class ChatOpenAICustom_ChatModels implements INode {
if (frequencyPenalty) obj.frequencyPenalty = parseFloat(frequencyPenalty) if (frequencyPenalty) obj.frequencyPenalty = parseFloat(frequencyPenalty)
if (presencePenalty) obj.presencePenalty = parseFloat(presencePenalty) if (presencePenalty) obj.presencePenalty = parseFloat(presencePenalty)
if (timeout) obj.timeout = parseInt(timeout, 10) if (timeout) obj.timeout = parseInt(timeout, 10)
if (cache) obj.cache = cache
let parsedBaseOptions: any | undefined = undefined let parsedBaseOptions: any | undefined = undefined