Skip to content

Commit 1d88ac4

Browse files
authored
Merge pull request #524 from FlowiseAI/feature/ChatAnthropic
Feature/Update claude v2
2 parents 2edb631 + f558c03 commit 1d88ac4

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

packages/components/nodes/chains/ConversationChain/ConversationChain.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import { BufferMemory, ChatMessageHistory } from 'langchain/memory'
66
import { BaseChatModel } from 'langchain/chat_models/base'
77
import { AIMessage, HumanMessage } from 'langchain/schema'
88
import { ConsoleCallbackHandler, CustomChainHandler } from '../../../src/handler'
9+
import { flatten } from 'lodash'
10+
import { Document } from 'langchain/document'
911

10-
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.`
12+
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.`
1113

1214
class ConversationChain_Chains implements INode {
1315
label: string
@@ -38,6 +40,14 @@ class ConversationChain_Chains implements INode {
3840
name: 'memory',
3941
type: 'BaseMemory'
4042
},
43+
{
44+
label: 'Document',
45+
name: 'document',
46+
type: 'Document',
47+
description: 'Include whole document into the context window',
48+
optional: true,
49+
list: true
50+
},
4151
{
4252
label: 'System Message',
4353
name: 'systemMessagePrompt',
@@ -54,6 +64,20 @@ class ConversationChain_Chains implements INode {
5464
const model = nodeData.inputs?.model as BaseChatModel
5565
const memory = nodeData.inputs?.memory as BufferMemory
5666
const prompt = nodeData.inputs?.systemMessagePrompt as string
67+
const docs = nodeData.inputs?.document as Document[]
68+
69+
const flattenDocs = docs && docs.length ? flatten(docs) : []
70+
const finalDocs = []
71+
for (let i = 0; i < flattenDocs.length; i += 1) {
72+
finalDocs.push(new Document(flattenDocs[i]))
73+
}
74+
75+
let finalText = ''
76+
for (let i = 0; i < finalDocs.length; i += 1) {
77+
finalText += finalDocs[i].pageContent
78+
}
79+
80+
if (finalText) systemMessage = `${systemMessage}\nThe AI has the following context:\n${finalText}`
5781

5882
const obj: any = {
5983
llm: model,

packages/components/nodes/chatmodels/ChatAnthropic/ChatAnthropic.ts

+10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ class ChatAnthropic_ChatModels implements INode {
3131
name: 'modelName',
3232
type: 'options',
3333
options: [
34+
{
35+
label: 'claude-2',
36+
name: 'claude-2',
37+
description: 'Claude 2 latest major version, automatically get updates to the model as they are released'
38+
},
39+
{
40+
label: 'claude-instant-1',
41+
name: 'claude-instant-1',
42+
description: 'Claude Instant latest major version, automatically get updates to the model as they are released'
43+
},
3444
{
3545
label: 'claude-v1',
3646
name: 'claude-v1'

packages/server/marketplaces/chatflows/Simple Conversation Chain.json

+9
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,15 @@
249249
"name": "memory",
250250
"type": "BaseMemory",
251251
"id": "conversationChain_0-input-memory-BaseMemory"
252+
},
253+
{
254+
"label": "Document",
255+
"name": "document",
256+
"type": "Document",
257+
"description": "Include whole document into the context window",
258+
"optional": true,
259+
"list": true,
260+
"id": "conversationChain_0-input-document-Document"
252261
}
253262
],
254263
"inputs": {

0 commit comments

Comments
 (0)