Merge pull request #989 from vinodkiran/FEATURE/llm-cache

Feature/llm cache
This commit is contained in:
Henry Heng
2023-10-09 19:18:13 +01:00
committed by GitHub
31 changed files with 517 additions and 38 deletions
@@ -0,0 +1,36 @@
import { INodeParams, INodeCredential } from '../src/Interface'
class MomentoCacheApi implements INodeCredential {
label: string
name: string
version: number
description: string
inputs: INodeParams[]
constructor() {
this.label = 'Momento Cache API'
this.name = 'momentoCacheApi'
this.version = 1.0
this.description =
'Refer to <a target="_blank" href="https://docs.momentohq.com/cache/develop/authentication/api-keys">official guide</a> on how to get API key on Momento'
this.inputs = [
{
label: 'Cache',
name: 'momentoCache',
type: 'string'
},
{
label: 'API Key',
name: 'momentoApiKey',
type: 'password'
},
{
label: 'Endpoint',
name: 'momentoEndpoint',
type: 'string'
}
]
}
}
module.exports = { credClass: MomentoCacheApi }
@@ -0,0 +1,43 @@
import { INodeParams, INodeCredential } from '../src/Interface'
class RedisCacheApi implements INodeCredential {
label: string
name: string
version: number
description: string
inputs: INodeParams[]
constructor() {
this.label = 'Redis Cache API'
this.name = 'redisCacheApi'
this.version = 1.0
this.inputs = [
{
label: 'Redis Host',
name: 'redisCacheHost',
type: 'string',
default: '127.0.0.1'
},
{
label: 'Port',
name: 'redisCachePort',
type: 'number',
default: '6789'
},
{
label: 'User',
name: 'redisCacheUser',
type: 'string',
placeholder: '<REDIS_USERNAME>'
},
{
label: 'Password',
name: 'redisCachePwd',
type: 'password',
placeholder: '<REDIS_PASSWORD>'
}
]
}
}
module.exports = { credClass: RedisCacheApi }
@@ -0,0 +1,28 @@
import { INodeParams, INodeCredential } from '../src/Interface'
class UpstashRedisApi implements INodeCredential {
label: string
name: string
version: number
inputs: INodeParams[]
constructor() {
this.label = 'Upstash Redis API'
this.name = 'upstashRedisApi'
this.version = 1.0
this.inputs = [
{
label: 'Upstash Redis REST URL',
name: 'upstashConnectionUrl',
type: 'string'
},
{
label: 'Token',
name: 'upstashConnectionToken',
type: 'password'
}
]
}
}
module.exports = { credClass: UpstashRedisApi }
@@ -0,0 +1,57 @@
import { getBaseClasses, getCredentialData, getCredentialParam, ICommonObject, INode, INodeData, INodeParams } from '../../../src'
import { MomentoCache as LangchainMomentoCache } from 'langchain/cache/momento'
import { CacheClient, Configurations, CredentialProvider } from '@gomomento/sdk'
class MomentoCache implements INode {
label: string
name: string
version: number
description: string
type: string
icon: string
category: string
baseClasses: string[]
inputs: INodeParams[]
credential: INodeParams
constructor() {
this.label = 'Momento Cache'
this.name = 'momentoCache'
this.version = 1.0
this.type = 'MomentoCache'
this.icon = 'momento.png'
this.category = 'Cache'
this.baseClasses = [this.type, ...getBaseClasses(LangchainMomentoCache)]
this.credential = {
label: 'Connect Credential',
name: 'credential',
type: 'credential',
optional: true,
credentialNames: ['momentoCacheApi']
}
this.inputs = []
}
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const apiKey = getCredentialParam('momentoApiKey', credentialData, nodeData)
const cacheName = getCredentialParam('momentoCache', credentialData, nodeData)
// See https://github.com/momentohq/client-sdk-javascript for connection options
const client = new CacheClient({
configuration: Configurations.Laptop.v1(),
credentialProvider: CredentialProvider.fromString({
apiKey: apiKey
}),
defaultTtlSeconds: 60 * 60 * 24
})
let momentoCache = await LangchainMomentoCache.fromProps({
client,
cacheName: cacheName
})
return momentoCache
}
}
module.exports = { nodeClass: MomentoCache }
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

@@ -0,0 +1,52 @@
import { getBaseClasses, getCredentialData, getCredentialParam, ICommonObject, INode, INodeData, INodeParams } from '../../../src'
import { RedisCache as LangchainRedisCache } from 'langchain/cache/ioredis'
import { Redis } from 'ioredis'
class RedisCache implements INode {
label: string
name: string
version: number
description: string
type: string
icon: string
category: string
baseClasses: string[]
inputs: INodeParams[]
credential: INodeParams
constructor() {
this.label = 'Redis Cache'
this.name = 'redisCache'
this.version = 1.0
this.type = 'RedisCache'
this.icon = 'redis.svg'
this.category = 'Cache'
this.baseClasses = [this.type, ...getBaseClasses(LangchainRedisCache)]
this.credential = {
label: 'Connect Credential',
name: 'credential',
type: 'credential',
optional: true,
credentialNames: ['redisCacheApi']
}
this.inputs = []
}
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const username = getCredentialParam('redisCacheUser', credentialData, nodeData)
const password = getCredentialParam('redisCachePwd', credentialData, nodeData)
const portStr = getCredentialParam('redisCachePort', credentialData, nodeData)
const host = getCredentialParam('redisCacheHost', credentialData, nodeData)
const client = new Redis({
port: portStr ? parseInt(portStr) : 6379,
host,
username,
password
})
return new LangchainRedisCache(client)
}
}
module.exports = { nodeClass: RedisCache }
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128" id="redis"><path fill="#A41E11" d="M121.8 93.1c-6.7 3.5-41.4 17.7-48.8 21.6-7.4 3.9-11.5 3.8-17.3 1s-42.7-17.6-49.4-20.8c-3.3-1.6-5-2.9-5-4.2v-12.7s48-10.5 55.8-13.2c7.8-2.8 10.4-2.9 17-.5s46.1 9.5 52.6 11.9v12.5c0 1.3-1.5 2.7-4.9 4.4z"></path><path fill="#D82C20" d="M121.8 80.5c-6.7 3.5-41.4 17.7-48.8 21.6-7.4 3.9-11.5 3.8-17.3 1-5.8-2.8-42.7-17.7-49.4-20.9-6.6-3.2-6.8-5.4-.3-7.9 6.5-2.6 43.2-17 51-19.7 7.8-2.8 10.4-2.9 17-.5s41.1 16.1 47.6 18.5c6.7 2.4 6.9 4.4.2 7.9z"></path><path fill="#A41E11" d="M121.8 72.5c-6.7 3.5-41.4 17.7-48.8 21.6-7.4 3.8-11.5 3.8-17.3 1-5.8-2.8-42.7-17.7-49.4-20.9-3.3-1.6-5-2.9-5-4.2v-12.7s48-10.5 55.8-13.2c7.8-2.8 10.4-2.9 17-.5s46.1 9.5 52.6 11.9v12.5c0 1.3-1.5 2.7-4.9 4.5z"></path><path fill="#D82C20" d="M121.8 59.8c-6.7 3.5-41.4 17.7-48.8 21.6-7.4 3.8-11.5 3.8-17.3 1-5.8-2.8-42.7-17.7-49.4-20.9s-6.8-5.4-.3-7.9c6.5-2.6 43.2-17 51-19.7 7.8-2.8 10.4-2.9 17-.5s41.1 16.1 47.6 18.5c6.7 2.4 6.9 4.4.2 7.9z"></path><path fill="#A41E11" d="M121.8 51c-6.7 3.5-41.4 17.7-48.8 21.6-7.4 3.8-11.5 3.8-17.3 1-5.8-2.7-42.7-17.6-49.4-20.8-3.3-1.6-5.1-2.9-5.1-4.2v-12.7s48-10.5 55.8-13.2c7.8-2.8 10.4-2.9 17-.5s46.1 9.5 52.6 11.9v12.5c.1 1.3-1.4 2.6-4.8 4.4z"></path><path fill="#D82C20" d="M121.8 38.3c-6.7 3.5-41.4 17.7-48.8 21.6-7.4 3.8-11.5 3.8-17.3 1s-42.7-17.6-49.4-20.8-6.8-5.4-.3-7.9c6.5-2.6 43.2-17 51-19.7 7.8-2.8 10.4-2.9 17-.5s41.1 16.1 47.6 18.5c6.7 2.4 6.9 4.4.2 7.8z"></path><path fill="#fff" d="M80.4 26.1l-10.8 1.2-2.5 5.8-3.9-6.5-12.5-1.1 9.3-3.4-2.8-5.2 8.8 3.4 8.2-2.7-2.2 5.4zM66.5 54.5l-20.3-8.4 29.1-4.4z"></path><ellipse cx="38.4" cy="35.4" fill="#fff" rx="15.5" ry="6"></ellipse><path fill="#7A0C00" d="M93.3 27.7l17.2 6.8-17.2 6.8z"></path><path fill="#AD2115" d="M74.3 35.3l19-7.6v13.6l-1.9.8z"></path></svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

@@ -0,0 +1,49 @@
import { getBaseClasses, getCredentialData, getCredentialParam, ICommonObject, INode, INodeData, INodeParams } from '../../../src'
import { UpstashRedisCache as LangchainUpstashRedisCache } from 'langchain/cache/upstash_redis'
class UpstashRedisCache implements INode {
label: string
name: string
version: number
description: string
type: string
icon: string
category: string
baseClasses: string[]
inputs: INodeParams[]
credential: INodeParams
constructor() {
this.label = 'Upstash Redis Cache'
this.name = 'upstashRedisCache'
this.version = 1.0
this.type = 'UpstashRedisCache'
this.icon = 'upstash.png'
this.category = 'Cache'
this.baseClasses = [this.type, ...getBaseClasses(LangchainUpstashRedisCache)]
this.credential = {
label: 'Connect Credential',
name: 'credential',
type: 'credential',
optional: true,
credentialNames: ['upstashRedisApi']
}
this.inputs = []
}
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const upstashConnectionUrl = getCredentialParam('upstashConnectionUrl', credentialData, nodeData)
const upstashToken = getCredentialParam('upstashConnectionToken', credentialData, nodeData)
const cache = new LangchainUpstashRedisCache({
config: {
url: upstashConnectionUrl,
token: upstashToken
}
})
return cache
}
}
module.exports = { nodeClass: UpstashRedisCache }
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

@@ -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: 'BaseCache',
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?.cache 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: 'BaseCache',
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?.cache 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: 'BaseCache',
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?.cache 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: 'BaseCache',
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?.cache 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: 'BaseCache',
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?.cache 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: 'BaseCache',
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?.cache 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: 'BaseCache',
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?.cache 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: 'BaseCache',
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?.cache 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: 'BaseCache',
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?.cache 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: 'BaseCache',
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?.cache 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
@@ -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 { Bedrock } from 'langchain/llms/bedrock' import { Bedrock } from 'langchain/llms/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
@@ -39,6 +41,12 @@ class AWSBedrock_LLMs implements INode {
optional: true optional: true
} }
this.inputs = [ this.inputs = [
{
label: 'Cache',
name: 'cache',
type: 'BaseCache',
optional: true
},
{ {
label: 'Region', label: 'Region',
name: 'region', name: 'region',
@@ -130,8 +138,8 @@ class AWSBedrock_LLMs 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?.cache as BaseCache
const obj: Partial<BaseBedrockInput> = { const obj: Partial<BaseBedrockInput> & BaseLLMParams = {
model: iModel, model: iModel,
region: iRegion, region: iRegion,
temperature: parseFloat(iTemperature), temperature: parseFloat(iTemperature),
@@ -157,6 +165,7 @@ class AWSBedrock_LLMs implements INode {
sessionToken: credentialApiSession sessionToken: credentialApiSession
} }
} }
if (cache) obj.cache = cache
const amazonBedrock = new Bedrock(obj) const amazonBedrock = new Bedrock(obj)
return amazonBedrock return amazonBedrock
@@ -1,7 +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 { AzureOpenAIInput, OpenAI, OpenAIInput } from 'langchain/llms/openai' import { AzureOpenAIInput, OpenAI, OpenAIInput } from 'langchain/llms/openai'
import { BaseCache } from 'langchain/schema'
import { BaseLLMParams } from 'langchain/llms/base'
class AzureOpenAI_LLMs implements INode { class AzureOpenAI_LLMs implements INode {
label: string label: string
name: string name: string
@@ -17,7 +18,7 @@ class AzureOpenAI_LLMs implements INode {
constructor() { constructor() {
this.label = 'Azure OpenAI' this.label = 'Azure OpenAI'
this.name = 'azureOpenAI' this.name = 'azureOpenAI'
this.version = 1.0 this.version = 2.0
this.type = 'AzureOpenAI' this.type = 'AzureOpenAI'
this.icon = 'Azure.svg' this.icon = 'Azure.svg'
this.category = 'LLMs' this.category = 'LLMs'
@@ -30,6 +31,12 @@ class AzureOpenAI_LLMs implements INode {
credentialNames: ['azureOpenAIApi'] credentialNames: ['azureOpenAIApi']
} }
this.inputs = [ this.inputs = [
{
label: 'Cache',
name: 'cache',
type: 'BaseCache',
optional: true
},
{ {
label: 'Model Name', label: 'Model Name',
name: 'modelName', name: 'modelName',
@@ -163,7 +170,9 @@ class AzureOpenAI_LLMs 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<OpenAIInput> = { const cache = nodeData.inputs?.cache as BaseCache
const obj: Partial<AzureOpenAIInput> & BaseLLMParams & Partial<OpenAIInput> = {
temperature: parseFloat(temperature), temperature: parseFloat(temperature),
modelName, modelName,
azureOpenAIApiKey, azureOpenAIApiKey,
@@ -179,6 +188,7 @@ class AzureOpenAI_LLMs implements INode {
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 (bestOf) obj.bestOf = parseInt(bestOf, 10) if (bestOf) obj.bestOf = parseInt(bestOf, 10)
if (cache) obj.cache = cache
const model = new OpenAI(obj) const model = new OpenAI(obj)
return model return model
@@ -1,6 +1,8 @@
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 { NIBittensorLLM, BittensorInput } from 'langchain/experimental/llms/bittensor' import { NIBittensorLLM, BittensorInput } from 'langchain/experimental/llms/bittensor'
import { BaseCache } from 'langchain/schema'
import { BaseLLMParams } from 'langchain/llms/base'
class Bittensor_LLMs implements INode { class Bittensor_LLMs implements INode {
label: string label: string
@@ -16,13 +18,19 @@ class Bittensor_LLMs implements INode {
constructor() { constructor() {
this.label = 'NIBittensorLLM' this.label = 'NIBittensorLLM'
this.name = 'NIBittensorLLM' this.name = 'NIBittensorLLM'
this.version = 1.0 this.version = 2.0
this.type = 'Bittensor' this.type = 'Bittensor'
this.icon = 'logo.png' this.icon = 'logo.png'
this.category = 'LLMs' this.category = 'LLMs'
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(NIBittensorLLM)] this.baseClasses = [this.type, ...getBaseClasses(NIBittensorLLM)]
this.inputs = [ this.inputs = [
{
label: 'Cache',
name: 'cache',
type: 'BaseCache',
optional: true
},
{ {
label: 'System prompt', label: 'System prompt',
name: 'system_prompt', name: 'system_prompt',
@@ -44,10 +52,13 @@ class Bittensor_LLMs 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 topResponses = Number(nodeData.inputs?.topResponses as number) const topResponses = Number(nodeData.inputs?.topResponses as number)
const obj: Partial<BittensorInput> = { const cache = nodeData.inputs?.cache as BaseCache
const obj: Partial<BittensorInput> & BaseLLMParams = {
systemPrompt: system_prompt, systemPrompt: system_prompt,
topResponses: topResponses topResponses: topResponses
} }
if (cache) obj.cache = cache
const model = new NIBittensorLLM(obj) const model = new NIBittensorLLM(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 { Cohere, CohereInput } from './core' import { Cohere, CohereInput } from './core'
import { BaseCache } from 'langchain/schema'
class Cohere_LLMs implements INode { class Cohere_LLMs implements INode {
label: string label: string
@@ -17,7 +18,7 @@ class Cohere_LLMs implements INode {
constructor() { constructor() {
this.label = 'Cohere' this.label = 'Cohere'
this.name = 'cohere' this.name = 'cohere'
this.version = 1.0 this.version = 2.0
this.type = 'Cohere' this.type = 'Cohere'
this.icon = 'cohere.png' this.icon = 'cohere.png'
this.category = 'LLMs' this.category = 'LLMs'
@@ -30,6 +31,12 @@ class Cohere_LLMs implements INode {
credentialNames: ['cohereApi'] credentialNames: ['cohereApi']
} }
this.inputs = [ this.inputs = [
{
label: 'Cache',
name: 'cache',
type: 'BaseCache',
optional: true
},
{ {
label: 'Model Name', label: 'Model Name',
name: 'modelName', name: 'modelName',
@@ -85,7 +92,7 @@ class Cohere_LLMs implements INode {
const temperature = nodeData.inputs?.temperature as string const temperature = nodeData.inputs?.temperature as string
const modelName = nodeData.inputs?.modelName as string const modelName = nodeData.inputs?.modelName as string
const maxTokens = nodeData.inputs?.maxTokens as string const maxTokens = nodeData.inputs?.maxTokens as string
const cache = nodeData.inputs?.cache as BaseCache
const credentialData = await getCredentialData(nodeData.credential ?? '', options) const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const cohereApiKey = getCredentialParam('cohereApiKey', credentialData, nodeData) const cohereApiKey = getCredentialParam('cohereApiKey', credentialData, nodeData)
@@ -96,7 +103,7 @@ class Cohere_LLMs implements INode {
if (maxTokens) obj.maxTokens = parseInt(maxTokens, 10) if (maxTokens) obj.maxTokens = parseInt(maxTokens, 10)
if (modelName) obj.model = modelName if (modelName) obj.model = modelName
if (temperature) obj.temperature = parseFloat(temperature) if (temperature) obj.temperature = parseFloat(temperature)
if (cache) obj.cache = cache
const model = new Cohere(obj) const model = new Cohere(obj)
return model return model
} }
@@ -1,7 +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 { GooglePaLM, GooglePaLMTextInput } from 'langchain/llms/googlepalm' import { GooglePaLM, GooglePaLMTextInput } from 'langchain/llms/googlepalm'
import { BaseCache } from 'langchain/schema'
class GooglePaLM_LLMs implements INode { class GooglePaLM_LLMs implements INode {
label: string label: string
name: string name: string
@@ -17,7 +17,7 @@ class GooglePaLM_LLMs implements INode {
constructor() { constructor() {
this.label = 'GooglePaLM' this.label = 'GooglePaLM'
this.name = 'GooglePaLM' this.name = 'GooglePaLM'
this.version = 1.0 this.version = 2.0
this.type = 'GooglePaLM' this.type = 'GooglePaLM'
this.icon = 'Google_PaLM_Logo.svg' this.icon = 'Google_PaLM_Logo.svg'
this.category = 'LLMs' this.category = 'LLMs'
@@ -30,6 +30,12 @@ class GooglePaLM_LLMs implements INode {
credentialNames: ['googleMakerSuite'] credentialNames: ['googleMakerSuite']
} }
this.inputs = [ this.inputs = [
{
label: 'Cache',
name: 'cache',
type: 'BaseCache',
optional: true
},
{ {
label: 'Model Name', label: 'Model Name',
name: 'modelName', name: 'modelName',
@@ -126,6 +132,7 @@ class GooglePaLM_LLMs 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 stopSequencesObj = nodeData.inputs?.stopSequencesObj const stopSequencesObj = nodeData.inputs?.stopSequencesObj
const cache = nodeData.inputs?.cache 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)
@@ -139,6 +146,7 @@ class GooglePaLM_LLMs 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 (topK) obj.topK = parseFloat(topK) if (topK) obj.topK = parseFloat(topK)
if (cache) obj.cache = cache
let parsedStopSequences: any | undefined = undefined let parsedStopSequences: any | undefined = undefined
if (stopSequencesObj) { if (stopSequencesObj) {
@@ -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 { GoogleVertexAI, GoogleVertexAITextInput } from 'langchain/llms/googlevertexai' import { GoogleVertexAI, GoogleVertexAITextInput } from 'langchain/llms/googlevertexai'
import { GoogleAuthOptions } from 'google-auth-library' import { GoogleAuthOptions } from 'google-auth-library'
import { BaseCache } from 'langchain/schema'
class GoogleVertexAI_LLMs implements INode { class GoogleVertexAI_LLMs implements INode {
label: string label: string
@@ -18,7 +19,7 @@ class GoogleVertexAI_LLMs implements INode {
constructor() { constructor() {
this.label = 'GoogleVertexAI' this.label = 'GoogleVertexAI'
this.name = 'googlevertexai' this.name = 'googlevertexai'
this.version = 1.0 this.version = 2.0
this.type = 'GoogleVertexAI' this.type = 'GoogleVertexAI'
this.icon = 'vertexai.svg' this.icon = 'vertexai.svg'
this.category = 'LLMs' 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.' '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: 'BaseCache',
optional: true
},
{ {
label: 'Model Name', label: 'Model Name',
name: 'modelName', name: 'modelName',
@@ -120,6 +127,7 @@ class GoogleVertexAI_LLMs 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?.cache as BaseCache
const obj: Partial<GoogleVertexAITextInput> = { const obj: Partial<GoogleVertexAITextInput> = {
temperature: parseFloat(temperature), temperature: parseFloat(temperature),
@@ -129,6 +137,7 @@ class GoogleVertexAI_LLMs 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 GoogleVertexAI(obj) const model = new GoogleVertexAI(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 HuggingFaceInference_LLMs implements INode { class HuggingFaceInference_LLMs implements INode {
label: string label: string
@@ -17,7 +18,7 @@ class HuggingFaceInference_LLMs implements INode {
constructor() { constructor() {
this.label = 'HuggingFace Inference' this.label = 'HuggingFace Inference'
this.name = 'huggingFaceInference_LLMs' this.name = 'huggingFaceInference_LLMs'
this.version = 1.0 this.version = 2.0
this.type = 'HuggingFaceInference' this.type = 'HuggingFaceInference'
this.icon = 'huggingface.png' this.icon = 'huggingface.png'
this.category = 'LLMs' this.category = 'LLMs'
@@ -30,6 +31,12 @@ class HuggingFaceInference_LLMs implements INode {
credentialNames: ['huggingFaceApi'] credentialNames: ['huggingFaceApi']
} }
this.inputs = [ this.inputs = [
{
label: 'Cache',
name: 'cache',
type: 'BaseCache',
optional: true
},
{ {
label: 'Model', label: 'Model',
name: 'model', name: 'model',
@@ -106,6 +113,8 @@ class HuggingFaceInference_LLMs implements INode {
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)
const cache = nodeData.inputs?.cache as BaseCache
const obj: Partial<HFInput> = { const obj: Partial<HFInput> = {
model, model,
apiKey: huggingFaceApiKey apiKey: huggingFaceApiKey
@@ -119,6 +128,8 @@ class HuggingFaceInference_LLMs 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
} }
} }
@@ -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 { OpenAI, OpenAIInput } from 'langchain/llms/openai' import { OpenAI, OpenAIInput } from 'langchain/llms/openai'
import { BaseLLMParams } from 'langchain/llms/base'
import { BaseCache } from 'langchain/schema'
class OpenAI_LLMs implements INode { class OpenAI_LLMs implements INode {
label: string label: string
@@ -17,7 +19,7 @@ class OpenAI_LLMs implements INode {
constructor() { constructor() {
this.label = 'OpenAI' this.label = 'OpenAI'
this.name = 'openAI' this.name = 'openAI'
this.version = 2.0 this.version = 3.0
this.type = 'OpenAI' this.type = 'OpenAI'
this.icon = 'openai.png' this.icon = 'openai.png'
this.category = 'LLMs' this.category = 'LLMs'
@@ -30,6 +32,12 @@ class OpenAI_LLMs implements INode {
credentialNames: ['openAIApi'] credentialNames: ['openAIApi']
} }
this.inputs = [ this.inputs = [
{
label: 'Cache',
name: 'cache',
type: 'BaseCache',
optional: true
},
{ {
label: 'Model Name', label: 'Model Name',
name: 'modelName', name: 'modelName',
@@ -149,7 +157,9 @@ class OpenAI_LLMs 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<OpenAIInput> & { openAIApiKey?: string } = { const cache = nodeData.inputs?.cache as BaseCache
const obj: Partial<OpenAIInput> & BaseLLMParams & { openAIApiKey?: string } = {
temperature: parseFloat(temperature), temperature: parseFloat(temperature),
modelName, modelName,
openAIApiKey, openAIApiKey,
@@ -164,8 +174,9 @@ class OpenAI_LLMs implements INode {
if (batchSize) obj.batchSize = parseInt(batchSize, 10) if (batchSize) obj.batchSize = parseInt(batchSize, 10)
if (bestOf) obj.bestOf = parseInt(bestOf, 10) if (bestOf) obj.bestOf = parseInt(bestOf, 10)
let parsedBaseOptions: any | undefined = undefined if (cache) obj.cache = cache
let parsedBaseOptions: any | undefined = undefined
if (baseOptions) { if (baseOptions) {
try { try {
parsedBaseOptions = typeof baseOptions === 'object' ? baseOptions : JSON.parse(baseOptions) parsedBaseOptions = typeof baseOptions === 'object' ? baseOptions : JSON.parse(baseOptions)
@@ -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 { Replicate, ReplicateInput } from 'langchain/llms/replicate' import { Replicate, ReplicateInput } from 'langchain/llms/replicate'
import { BaseCache } from 'langchain/schema'
import { BaseLLMParams } from 'langchain/llms/base'
class Replicate_LLMs implements INode { class Replicate_LLMs implements INode {
label: string label: string
@@ -17,7 +19,7 @@ class Replicate_LLMs implements INode {
constructor() { constructor() {
this.label = 'Replicate' this.label = 'Replicate'
this.name = 'replicate' this.name = 'replicate'
this.version = 1.0 this.version = 2.0
this.type = 'Replicate' this.type = 'Replicate'
this.icon = 'replicate.svg' this.icon = 'replicate.svg'
this.category = 'LLMs' this.category = 'LLMs'
@@ -30,6 +32,12 @@ class Replicate_LLMs implements INode {
credentialNames: ['replicateApi'] credentialNames: ['replicateApi']
} }
this.inputs = [ this.inputs = [
{
label: 'Cache',
name: 'cache',
type: 'BaseCache',
optional: true
},
{ {
label: 'Model', label: 'Model',
name: 'model', name: 'model',
@@ -103,7 +111,9 @@ class Replicate_LLMs implements INode {
const name = modelName.split(':')[0].split('/').pop() const name = modelName.split(':')[0].split('/').pop()
const org = modelName.split(':')[0].split('/')[0] const org = modelName.split(':')[0].split('/')[0]
const obj: ReplicateInput = { const cache = nodeData.inputs?.cache as BaseCache
const obj: ReplicateInput & BaseLLMParams = {
model: `${org}/${name}:${version}`, model: `${org}/${name}:${version}`,
apiKey apiKey
} }
@@ -120,6 +130,8 @@ class Replicate_LLMs implements INode {
} }
if (Object.keys(inputs).length) obj.input = inputs if (Object.keys(inputs).length) obj.input = inputs
if (cache) obj.cache = cache
const model = new Replicate(obj) const model = new Replicate(obj)
return model return model
} }
+2
View File
@@ -19,6 +19,7 @@
"@aws-sdk/client-dynamodb": "^3.360.0", "@aws-sdk/client-dynamodb": "^3.360.0",
"@dqbd/tiktoken": "^1.0.7", "@dqbd/tiktoken": "^1.0.7",
"@getzep/zep-js": "^0.6.3", "@getzep/zep-js": "^0.6.3",
"@gomomento/sdk": "^1.40.2",
"@google-ai/generativelanguage": "^0.2.1", "@google-ai/generativelanguage": "^0.2.1",
"@huggingface/inference": "^2.6.1", "@huggingface/inference": "^2.6.1",
"@notionhq/client": "^2.2.8", "@notionhq/client": "^2.2.8",
@@ -43,6 +44,7 @@
"google-auth-library": "^9.0.0", "google-auth-library": "^9.0.0",
"graphql": "^16.6.0", "graphql": "^16.6.0",
"html-to-text": "^9.0.5", "html-to-text": "^9.0.5",
"ioredis": "^5.3.2",
"langchain": "^0.0.157", "langchain": "^0.0.157",
"langfuse-langchain": "^1.0.14-alpha.0", "langfuse-langchain": "^1.0.14-alpha.0",
"langsmith": "^0.0.32", "langsmith": "^0.0.32",
+26 -3
View File
@@ -151,6 +151,7 @@ export class CustomChainHandler extends BaseCallbackHandler {
socketIOClientId = '' socketIOClientId = ''
skipK = 0 // Skip streaming for first K numbers of handleLLMStart skipK = 0 // Skip streaming for first K numbers of handleLLMStart
returnSourceDocuments = false returnSourceDocuments = false
cachedResponse = true
constructor(socketIO: Server, socketIOClientId: string, skipK?: number, returnSourceDocuments?: boolean) { constructor(socketIO: Server, socketIOClientId: string, skipK?: number, returnSourceDocuments?: boolean) {
super() super()
@@ -161,6 +162,7 @@ export class CustomChainHandler extends BaseCallbackHandler {
} }
handleLLMStart() { handleLLMStart() {
this.cachedResponse = false
if (this.skipK > 0) this.skipK -= 1 if (this.skipK > 0) this.skipK -= 1
} }
@@ -178,9 +180,30 @@ export class CustomChainHandler extends BaseCallbackHandler {
this.socketIO.to(this.socketIOClientId).emit('end') this.socketIO.to(this.socketIOClientId).emit('end')
} }
handleChainEnd(outputs: ChainValues): void | Promise<void> { handleChainEnd(outputs: ChainValues, _: string, parentRunId?: string): void | Promise<void> {
if (this.returnSourceDocuments) { /*
this.socketIO.to(this.socketIOClientId).emit('sourceDocuments', outputs?.sourceDocuments) Langchain does not call handleLLMStart, handleLLMEnd, handleLLMNewToken when the chain is cached.
Callback Order is "Chain Start -> LLM Start --> LLM Token --> LLM End -> Chain End" for normal responses.
Callback Order is "Chain Start -> Chain End" for cached responses.
*/
if (this.cachedResponse && parentRunId === undefined) {
const cachedValue = outputs.text ?? outputs.response ?? outputs.output ?? outputs.output_text
//split at whitespace, and keep the whitespace. This is to preserve the original formatting.
const result = cachedValue.split(/(\s+)/)
result.forEach((token: string, index: number) => {
if (index === 0) {
this.socketIO.to(this.socketIOClientId).emit('start', token)
}
this.socketIO.to(this.socketIOClientId).emit('token', token)
})
if (this.returnSourceDocuments) {
this.socketIO.to(this.socketIOClientId).emit('sourceDocuments', outputs?.sourceDocuments)
}
this.socketIO.to(this.socketIOClientId).emit('end')
} else {
if (this.returnSourceDocuments) {
this.socketIO.to(this.socketIOClientId).emit('sourceDocuments', outputs?.sourceDocuments)
}
} }
} }
} }
+1
View File
@@ -477,6 +477,7 @@ export const replaceInputsWithConfig = (flowNodeData: INodeData, overrideConfig:
*/ */
export const isStartNodeDependOnInput = (startingNodes: IReactFlowNode[], nodes: IReactFlowNode[]): boolean => { export const isStartNodeDependOnInput = (startingNodes: IReactFlowNode[], nodes: IReactFlowNode[]): boolean => {
for (const node of startingNodes) { for (const node of startingNodes) {
if (node.data.category === 'Cache') return true
for (const inputName in node.data.inputs) { for (const inputName in node.data.inputs) {
const inputVariables = getInputVariables(node.data.inputs[inputName]) const inputVariables = getInputVariables(node.data.inputs[inputName])
if (inputVariables.length > 0) return true if (inputVariables.length > 0) return true