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
@@ -1,6 +1,8 @@
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
import { Replicate, ReplicateInput } from 'langchain/llms/replicate'
import { BaseCache } from 'langchain/schema'
import { BaseLLMParams } from 'langchain/llms/base'
class Replicate_LLMs implements INode {
label: string
@@ -17,7 +19,7 @@ class Replicate_LLMs implements INode {
constructor() {
this.label = 'Replicate'
this.name = 'replicate'
this.version = 1.0
this.version = 2.0
this.type = 'Replicate'
this.icon = 'replicate.svg'
this.category = 'LLMs'
@@ -30,6 +32,12 @@ class Replicate_LLMs implements INode {
credentialNames: ['replicateApi']
}
this.inputs = [
{
label: 'Cache',
name: 'llmCache',
type: 'LLMCache',
optional: true
},
{
label: 'Model',
name: 'model',
@@ -103,7 +111,9 @@ class Replicate_LLMs implements INode {
const name = modelName.split(':')[0].split('/').pop()
const org = modelName.split(':')[0].split('/')[0]
const obj: ReplicateInput = {
const llmCache = nodeData.inputs?.llmCache as BaseCache
const obj: ReplicateInput & BaseLLMParams = {
model: `${org}/${name}:${version}`,
apiKey
}
@@ -120,6 +130,8 @@ class Replicate_LLMs implements INode {
}
if (Object.keys(inputs).length) obj.input = inputs
if (llmCache) obj.cache = llmCache
const model = new Replicate(obj)
return model
}