import { INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses } from '../../../src/utils'
import { VectorDBQAChain } from 'langchain/chains'
import { Document } from 'langchain/document'
import { VectaraStore } from 'langchain/vectorstores/vectara'
import fetch from 'node-fetch'
class VectaraChain_Chains implements INode {
label: string
name: string
version: number
type: string
icon: string
category: string
baseClasses: string[]
description: string
inputs: INodeParams[]
constructor() {
this.label = 'Vectara QA Chain'
this.name = 'vectaraQAChain'
this.version = 1.0
this.type = 'VectaraQAChain'
this.icon = 'vectara.png'
this.category = 'Chains'
this.description = 'QA chain for Vectara'
this.baseClasses = [this.type, ...getBaseClasses(VectorDBQAChain)]
this.inputs = [
{
label: 'Vectara Store',
name: 'vectaraStore',
type: 'VectorStore'
},
{
label: 'Summarizer Prompt Name',
name: 'summarizerPromptName',
description:
'Summarize the results fetched from Vectara. Read more',
type: 'options',
options: [
{
label: 'vectara-summary-ext-v1.2.0 (gpt-3.5-turbo)',
name: 'vectara-summary-ext-v1.2.0'
},
{
label: 'vectara-experimental-summary-ext-2023-10-23-small (gpt-3.5-turbo)',
name: 'vectara-experimental-summary-ext-2023-10-23-small',
description: 'In beta, available to both Growth and Scale Vectara users'
},
{
label: 'vectara-summary-ext-v1.3.0 (gpt-4.0)',
name: 'vectara-summary-ext-v1.3.0',
description: 'Only available to paying Scale Vectara users'
},
{
label: 'vectara-experimental-summary-ext-2023-10-23-med (gpt-4.0)',
name: 'vectara-experimental-summary-ext-2023-10-23-med',
description: 'In beta, only available to paying Scale Vectara users'
}
],
default: 'vectara-summary-ext-v1.2.0'
},
{
label: 'Response Language',
name: 'responseLang',
description:
'Return the response in specific language. If not selected, Vectara will automatically detects the language. Read more',
type: 'options',
options: [
{
label: 'English',
name: 'eng'
},
{
label: 'German',
name: 'deu'
},
{
label: 'French',
name: 'fra'
},
{
label: 'Chinese',
name: 'zho'
},
{
label: 'Korean',
name: 'kor'
},
{
label: 'Arabic',
name: 'ara'
},
{
label: 'Russian',
name: 'rus'
},
{
label: 'Thai',
name: 'tha'
},
{
label: 'Dutch',
name: 'nld'
},
{
label: 'Italian',
name: 'ita'
},
{
label: 'Portuguese',
name: 'por'
},
{
label: 'Spanish',
name: 'spa'
},
{
label: 'Japanese',
name: 'jpn'
},
{
label: 'Polish',
name: 'pol'
},
{
label: 'Turkish',
name: 'tur'
},
{
label: 'Vietnamese',
name: 'vie'
},
{
label: 'Indonesian',
name: 'ind'
},
{
label: 'Czech',
name: 'ces'
},
{
label: 'Ukrainian',
name: 'ukr'
},
{
label: 'Greek',
name: 'ell'
},
{
label: 'Hebrew',
name: 'heb'
},
{
label: 'Farsi/Persian',
name: 'fas'
},
{
label: 'Hindi',
name: 'hin'
},
{
label: 'Urdu',
name: 'urd'
},
{
label: 'Swedish',
name: 'swe'
},
{
label: 'Bengali',
name: 'ben'
},
{
label: 'Malay',
name: 'msa'
},
{
label: 'Romanian',
name: 'ron'
}
],
optional: true,
default: 'eng'
},
{
label: 'Max Summarized Results',
name: 'maxSummarizedResults',
description: 'Maximum results used to build the summarized response',
type: 'number',
default: 7
}
]
}
async init(): Promise {
return null
}
async run(nodeData: INodeData, input: string): Promise