update claude v2

This commit is contained in:
Henry 2023-07-12 01:11:02 +01:00
parent 2edb63175f
commit 4c47beabbc
2 changed files with 35 additions and 1 deletions

View File

@ -6,8 +6,10 @@ import { BufferMemory, ChatMessageHistory } from 'langchain/memory'
import { BaseChatModel } from 'langchain/chat_models/base' import { BaseChatModel } from 'langchain/chat_models/base'
import { AIMessage, HumanMessage } from 'langchain/schema' import { AIMessage, HumanMessage } from 'langchain/schema'
import { ConsoleCallbackHandler, CustomChainHandler } from '../../../src/handler' import { ConsoleCallbackHandler, CustomChainHandler } from '../../../src/handler'
import { flatten } from 'lodash'
import { Document } from 'langchain/document'
const systemMessage = `The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.` let systemMessage = `The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.`
class ConversationChain_Chains implements INode { class ConversationChain_Chains implements INode {
label: string label: string
@ -38,6 +40,14 @@ class ConversationChain_Chains implements INode {
name: 'memory', name: 'memory',
type: 'BaseMemory' type: 'BaseMemory'
}, },
{
label: 'Document',
name: 'document',
type: 'Document',
description: 'Include whole document into the context window',
optional: true,
list: true
},
{ {
label: 'System Message', label: 'System Message',
name: 'systemMessagePrompt', name: 'systemMessagePrompt',
@ -54,6 +64,20 @@ class ConversationChain_Chains implements INode {
const model = nodeData.inputs?.model as BaseChatModel const model = nodeData.inputs?.model as BaseChatModel
const memory = nodeData.inputs?.memory as BufferMemory const memory = nodeData.inputs?.memory as BufferMemory
const prompt = nodeData.inputs?.systemMessagePrompt as string const prompt = nodeData.inputs?.systemMessagePrompt as string
const docs = nodeData.inputs?.document as Document[]
const flattenDocs = docs && docs.length ? flatten(docs) : []
const finalDocs = []
for (let i = 0; i < flattenDocs.length; i += 1) {
finalDocs.push(new Document(flattenDocs[i]))
}
let finalText = ''
for (let i = 0; i < finalDocs.length; i += 1) {
finalText += finalDocs[i].pageContent
}
if (finalText) systemMessage = `${systemMessage}\nThe AI has the following context:\n${finalText}`
const obj: any = { const obj: any = {
llm: model, llm: model,

View File

@ -31,6 +31,16 @@ class ChatAnthropic_ChatModels implements INode {
name: 'modelName', name: 'modelName',
type: 'options', type: 'options',
options: [ options: [
{
label: 'claude-2',
name: 'claude-2',
description: 'Claude 2 latest major version, automatically get updates to the model as they are released'
},
{
label: 'claude-instant-1',
name: 'claude-instant-1',
description: 'Claude Instant latest major version, automatically get updates to the model as they are released'
},
{ {
label: 'claude-v1', label: 'claude-v1',
name: 'claude-v1' name: 'claude-v1'