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 { INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses } from '../../../src/utils'
import { NIBittensorLLM, BittensorInput } from 'langchain/experimental/llms/bittensor'
import { BaseCache } from 'langchain/schema'
import { BaseLLMParams } from 'langchain/llms/base'
class Bittensor_LLMs implements INode {
label: string
@@ -16,13 +18,19 @@ class Bittensor_LLMs implements INode {
constructor() {
this.label = 'NIBittensorLLM'
this.name = 'NIBittensorLLM'
this.version = 1.0
this.version = 2.0
this.type = 'Bittensor'
this.icon = 'logo.png'
this.category = 'LLMs'
this.description = 'Wrapper around Bittensor subnet 1 large language models'
this.baseClasses = [this.type, ...getBaseClasses(NIBittensorLLM)]
this.inputs = [
{
label: 'Cache',
name: 'llmCache',
type: 'LLMCache',
optional: true
},
{
label: 'System prompt',
name: 'system_prompt',
@@ -44,10 +52,13 @@ class Bittensor_LLMs implements INode {
async init(nodeData: INodeData, _: string): Promise<any> {
const system_prompt = nodeData.inputs?.system_prompt as string
const topResponses = Number(nodeData.inputs?.topResponses as number)
const obj: Partial<BittensorInput> = {
const llmCache = nodeData.inputs?.llmCache as BaseCache
const obj: Partial<BittensorInput> & BaseLLMParams = {
systemPrompt: system_prompt,
topResponses: topResponses
}
if (llmCache) obj.cache = llmCache
const model = new NIBittensorLLM(obj)
return model