From df50c0499d6572aaa6c4c321260330ba98f5315c Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 12 Apr 2023 17:54:20 +0100 Subject: [PATCH 1/7] Add BabyAGI node --- .../nodes/agents/BabyAGI/BabyAGI.ts | 376 ++++++++++++++++++ .../nodes/agents/BabyAGI/babyagi.svg | 9 + .../nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts | 12 + packages/components/package.json | 2 + packages/server/marketplaces/BabyAGI.json | 104 +++++ packages/server/src/utils/index.ts | 4 +- .../ui/src/views/chatmessage/ChatMessage.css | 10 +- .../ui/src/views/chatmessage/ChatMessage.js | 6 +- 8 files changed, 511 insertions(+), 12 deletions(-) create mode 100644 packages/components/nodes/agents/BabyAGI/BabyAGI.ts create mode 100644 packages/components/nodes/agents/BabyAGI/babyagi.svg create mode 100644 packages/server/marketplaces/BabyAGI.json diff --git a/packages/components/nodes/agents/BabyAGI/BabyAGI.ts b/packages/components/nodes/agents/BabyAGI/BabyAGI.ts new file mode 100644 index 00000000..8b297215 --- /dev/null +++ b/packages/components/nodes/agents/BabyAGI/BabyAGI.ts @@ -0,0 +1,376 @@ +import { INode, INodeData, INodeParams } from '../../../src/Interface' +import { Configuration, CreateChatCompletionRequest, CreateCompletionRequest, OpenAIApi } from 'openai' +import { PineconeClient } from '@pinecone-database/pinecone' +import { CreateIndexRequest } from '@pinecone-database/pinecone/dist/pinecone-generated-ts-fetch' +import { VectorOperationsApi } from '@pinecone-database/pinecone/dist/pinecone-generated-ts-fetch' +import { v4 as uuidv4 } from 'uuid' + +interface Task { + id: string + name: string + priority: number // 1 is highest priority +} + +class BabyAGI_Agents implements INode { + label: string + name: string + description: string + type: string + icon: string + category: string + baseClasses: string[] + inputs: INodeParams[] + + constructor() { + this.label = 'BabyAGI' + this.name = 'babyAGI' + this.type = 'BabyAGI' + this.category = 'Agents' + this.icon = 'babyagi.svg' + this.description = 'Task Driven Autonomous Agent which creates new task and reprioritizes task list based on objective' + this.inputs = [ + { + label: 'Task Loop', + name: 'taskLoop', + type: 'number', + default: 3 + }, + { + label: 'OpenAI Api Key', + name: 'openAIApiKey', + type: 'password' + }, + { + label: 'Pinecone Api Key', + name: 'pineconeApiKey', + type: 'password' + }, + { + label: 'Pinecone Environment', + name: 'pineconeEnv', + type: 'string' + }, + { + label: 'Pinecone Index', + name: 'pineconeIndex', + type: 'string' + }, + { + label: 'Model Name', + name: 'modelName', + type: 'options', + options: [ + { + label: 'gpt-4', + name: 'gpt-4' + }, + { + label: 'gpt-4-0314', + name: 'gpt-4-0314' + }, + { + label: 'gpt-4-32k-0314', + name: 'gpt-4-32k-0314' + }, + { + label: 'gpt-3.5-turbo', + name: 'gpt-3.5-turbo' + }, + { + label: 'gpt-3.5-turbo-0301', + name: 'gpt-3.5-turbo-0301' + } + ], + default: 'gpt-3.5-turbo', + optional: true + } + ] + } + + async getBaseClasses(): Promise { + return ['BabyAGI'] + } + + async init(): Promise { + return null + } + + async run(nodeData: INodeData, input: string): Promise { + const openAIApiKey = nodeData.inputs?.openAIApiKey as string + const pineconeApiKey = nodeData.inputs?.pineconeApiKey as string + const pineconeEnv = nodeData.inputs?.pineconeEnv as string + const index = nodeData.inputs?.pineconeIndex as string + const modelName = nodeData.inputs?.modelName as string + const taskLoop = nodeData.inputs?.taskLoop as string + const objective = input + + const configuration = new Configuration({ + apiKey: openAIApiKey + }) + const openai = new OpenAIApi(configuration) + + const pinecone = new PineconeClient() + await pinecone.init({ + apiKey: pineconeApiKey, + environment: pineconeEnv + }) + + const dimension = 1536 + const metric = 'cosine' + const podType = 'p1' + + const indexList = await pinecone.listIndexes() + if (!indexList.includes(index)) { + const createIndexOptions: CreateIndexRequest = { + createRequest: { + name: index, + dimension, + metric, + podType + } + } + await pinecone.createIndex(createIndexOptions) + } + + let vectorIndex: VectorOperationsApi = pinecone.Index(index) + + let taskList: Task[] = [] + let embeddingList = new Map() + + taskList = [ + { + id: uuidv4(), + name: 'Develop a task list', + priority: 1 + } + ] + + return await mainLoop(openai, pinecone, index, embeddingList, vectorIndex, taskList, objective, modelName, taskLoop) + } +} + +export const getADAEmbedding = async (openai: OpenAIApi, text: string, embeddingList: Map): Promise => { + //console.log('\nGetting ADA embedding for: ', text) + + if (embeddingList.has(text)) { + //console.log('Embedding already exists for: ', text) + const numbers = embeddingList.get(text) + return numbers ?? [] + } + + const embedding = ( + await openai.createEmbedding({ + input: [text], + model: 'text-embedding-ada-002' + }) + ).data?.data[0].embedding + + embeddingList.set(text, embedding) + + return embedding +} + +export const openAICall = async (openai: OpenAIApi, prompt: string, gptVersion: string, temperature = 0.5, max_tokens = 100) => { + if (gptVersion === 'gpt-3.5-turbo' || gptVersion === 'gpt-4' || gptVersion === 'gpt-4-32k') { + // Chat completion + const options: CreateChatCompletionRequest = { + model: gptVersion, + messages: [{ role: 'user', content: prompt }], + temperature, + max_tokens, + n: 1 + } + const data = (await openai.createChatCompletion(options)).data + + return data?.choices[0]?.message?.content.trim() ?? '' + } else { + // Prompt completion + const options: CreateCompletionRequest = { + model: gptVersion, + prompt, + temperature, + max_tokens, + top_p: 1, + frequency_penalty: 0, + presence_penalty: 0 + } + const data = (await openai.createCompletion(options)).data + + return data?.choices[0]?.text?.trim() ?? '' + } +} + +export const taskCreationAgent = async ( + openai: OpenAIApi, + taskList: Task[], + objective: string, + result: string, + taskDescription: string, + gptVersion = 'gpt-3.5-turbo' +): Promise => { + const prompt = `You are an task creation AI that uses the result of an execution agent to create new tasks with the following objective: ${objective}, The last completed task has the result: ${result}. This result was based on this task description: ${taskDescription}. These are incomplete tasks: ${taskList.join( + ', ' + )}. Based on the result, create new tasks to be completed by the AI system that do not overlap with incomplete tasks. Return the tasks as an array.` + const response = await openAICall(openai, prompt, gptVersion) + const newTaskNames = response.split('\n') + + return newTaskNames.map((name) => ({ + id: uuidv4(), + name, + priority: taskList.length + 1 + })) +} + +export const prioritizationAgent = async ( + openai: OpenAIApi, + taskList: Task[], + taskPriority: number, + objective: string, + gptVersion = 'gpt-3.5-turbo' +): Promise => { + const taskNames = taskList.map((t) => t.name) + const startPriority = taskPriority + 1 + + const prompt = `You are an task prioritization AI tasked with cleaning the formatting of and reprioritizing the following tasks: ${taskNames}. Consider the ultimate objective of your team: ${objective}. Do not remove any tasks. Return the result as a list, like: + #. First task + #. Second task + Start the task list with number ${startPriority}.` + const response = await openAICall(openai, prompt, gptVersion) + const newTasks = response.split('\n') + + // Parse and add new tasks + return ( + newTasks + .map((taskString) => { + const taskParts = taskString.trim().split('.', 2) + + if (taskParts.length === 2) { + const id = uuidv4() + const name = taskParts[1].trim() + const priority = parseInt(taskParts[0]) + return { + id, + name, + priority + } as Task + } + }) + // Remove lines that don't have a task + .filter((t) => t !== undefined) + // Sort by priority + .sort((a, b) => a!.priority - b!.priority) as Task[] + ) +} + +export const contextAgent = async ( + openai: OpenAIApi, + pinecone: PineconeClient, + indexName: string, + embeddingList: Map, + objective: string, + topK: number +) => { + const index = pinecone.Index(indexName) + const queryEmbedding = await getADAEmbedding(openai, objective, embeddingList) + + const results = await index.query({ + queryRequest: { + vector: queryEmbedding, + includeMetadata: true, + topK + } + }) + const sortedResults = results.matches?.sort((a, b) => (b?.score ?? 0) - (a?.score ?? 0)) ?? [] + + return sortedResults.map((item) => (item.metadata as any)?.task ?? '') +} + +export const executionAgent = async ( + openai: OpenAIApi, + pinecone: PineconeClient, + indexName: string, + embeddingList: Map, + objective: string, + task: Task, + gptVersion = 'gpt-3.5-turbo' +) => { + const context = await contextAgent(openai, pinecone, indexName, embeddingList, objective, 5) + const prompt = `You are an AI who performs one task based on the following objective: ${objective}.\nTake into account these previously completed tasks: ${context}\nYour task: ${task.name}\nResponse:` + + //console.log('\nexecution prompt: ', prompt, '\n') + + return openAICall(openai, prompt, gptVersion, 0.7, 2000) +} + +export const mainLoop = async ( + openai: OpenAIApi, + pinecone: PineconeClient, + indexName: string, + embeddingList: Map, + index: VectorOperationsApi, + taskList: Task[], + objective: string, + modelName: string, + taskLoop: string +): Promise => { + const RUN_LIMIT = parseInt(taskLoop, 10) || 3 + let finalResult = '' + + for (let run = 0; run < RUN_LIMIT; run++) { + let enrichedResult: any + let task: Task | undefined + + if (taskList.length > 0) { + // Step 1: Pull the task + task = taskList.shift() + + if (!task) { + //console.log('No tasks left to complete. Exiting.') + break + } + + console.log(`\x1b[95m\x1b[1m\n*****TASK LIST*****\n\x1b[0m\x1b[0m + ${taskList.map((t) => ` ${t?.priority}. ${t?.name}`).join('\n')} + \x1b[92m\x1b[1m\n*****NEXT TASK*****\n\x1b[0m\x1b[0m + ${task.name}`) + + // Step 2: Execute the task + const result = await executionAgent(openai, pinecone, indexName, embeddingList, objective, task) + console.log('\x1b[93m\x1b[1m\n*****TASK RESULT*****\n\x1b[0m\x1b[0m') + console.log(result) + finalResult = result + + // Step 3: Enrich result and store in Pinecone + enrichedResult = { data: result } + const vector = enrichedResult.data // extract the actual result from the dictionary + const embeddingResult = await getADAEmbedding(openai, vector, embeddingList) + await index.upsert({ + upsertRequest: { + vectors: [ + { + id: task.id, + values: embeddingResult, + metadata: { task: task.name, result } + } + ] + } + }) + } + + // Step 4: Create new tasks and reprioritize task list + if (enrichedResult) { + const newTasks = await taskCreationAgent(openai, taskList, objective, enrichedResult.data, task!.name) + //console.log('newTasks', newTasks) + taskList = [...taskList, ...newTasks] + + taskList = await prioritizationAgent(openai, taskList, task!.priority, objective, modelName) + //console.log(`Reprioritized task list: ${taskList.map((t) => `[${t?.priority}] ${t?.id}: ${t?.name}`).join(', ')}`) + } else { + break + } + } + + return finalResult +} + +module.exports = { nodeClass: BabyAGI_Agents } diff --git a/packages/components/nodes/agents/BabyAGI/babyagi.svg b/packages/components/nodes/agents/BabyAGI/babyagi.svg new file mode 100644 index 00000000..c87861e5 --- /dev/null +++ b/packages/components/nodes/agents/BabyAGI/babyagi.svg @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts b/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts index 9cb12592..9701ce8b 100644 --- a/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts +++ b/packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts @@ -29,6 +29,18 @@ class ChatOpenAI_ChatModels implements INode { name: 'modelName', type: 'options', options: [ + { + label: 'gpt-4', + name: 'gpt-4' + }, + { + label: 'gpt-4-0314', + name: 'gpt-4-0314' + }, + { + label: 'gpt-4-32k-0314', + name: 'gpt-4-32k-0314' + }, { label: 'gpt-3.5-turbo', name: 'gpt-3.5-turbo' diff --git a/packages/components/package.json b/packages/components/package.json index 0a211553..9e8f8e67 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -28,10 +28,12 @@ "moment": "^2.29.3", "node-fetch": "2", "pdfjs-dist": "^3.5.141", + "uuid": "^9.0.0", "ws": "^8.9.0" }, "devDependencies": { "@types/gulp": "4.0.9", + "@types/uuid": "^9.0.1", "@types/ws": "^8.5.3", "gulp": "^4.0.2", "typescript": "^4.8.4" diff --git a/packages/server/marketplaces/BabyAGI.json b/packages/server/marketplaces/BabyAGI.json new file mode 100644 index 00000000..8091ef03 --- /dev/null +++ b/packages/server/marketplaces/BabyAGI.json @@ -0,0 +1,104 @@ +{ + "description": "Given an objective, tasks will be created, stored into Pinecone and reprioritized", + "nodes": [ + { + "width": 300, + "height": 769, + "id": "babyAGI_0", + "position": { + "x": 542.130412774738, + "y": 154.52145148106695 + }, + "type": "customNode", + "data": { + "id": "babyAGI_0", + "label": "BabyAGI", + "name": "babyAGI", + "type": "BabyAGI", + "baseClasses": ["AgentExecutor"], + "category": "Agents", + "description": "Conversational agent for a chat model. It will utilize chat specific prompts", + "inputParams": [ + { + "label": "Task Loop", + "name": "taskLoop", + "type": "number", + "default": 3 + }, + { + "label": "OpenAI Api Key", + "name": "openAIApiKey", + "type": "password" + }, + { + "label": "Pinecone Api Key", + "name": "pineconeApiKey", + "type": "password" + }, + { + "label": "Pinecone Environment", + "name": "pineconeEnv", + "type": "string" + }, + { + "label": "Pinecone Index", + "name": "pineconeIndex", + "type": "string" + }, + { + "label": "Model Name", + "name": "modelName", + "type": "options", + "options": [ + { + "label": "gpt-4", + "name": "gpt-4" + }, + { + "label": "gpt-4-0314", + "name": "gpt-4-0314" + }, + { + "label": "gpt-4-32k-0314", + "name": "gpt-4-32k-0314" + }, + { + "label": "gpt-3.5-turbo", + "name": "gpt-3.5-turbo" + }, + { + "label": "gpt-3.5-turbo-0301", + "name": "gpt-3.5-turbo-0301" + } + ], + "default": "gpt-3.5-turbo", + "optional": true + } + ], + "inputAnchors": [], + "inputs": { + "taskLoop": "3", + "pineconeEnv": "us-west4-gcp", + "pineconeIndex": "test", + "modelName": "gpt-3.5-turbo" + }, + "outputAnchors": [ + { + "id": "babyAGI_0-output-babyAGI-AgentExecutor", + "name": "babyAGI", + "label": "BabyAGI", + "type": "AgentExecutor" + } + ], + "selected": false + }, + "selected": false, + "dragging": false, + "positionAbsolute": { + "x": 542.130412774738, + "y": 154.52145148106695 + } + } + ], + "edges": [] +} diff --git a/packages/server/src/utils/index.ts b/packages/server/src/utils/index.ts index bc50aff2..e8ac8a3a 100644 --- a/packages/server/src/utils/index.ts +++ b/packages/server/src/utils/index.ts @@ -107,7 +107,9 @@ export const getEndingNode = (nodeDependencies: INodeDependencies, graph: INodeD // Find ending node let endingNodeId = '' Object.keys(graph).forEach((nodeId) => { - if (!graph[nodeId].length && nodeDependencies[nodeId] > 0) { + if (Object.keys(nodeDependencies).length === 1) { + endingNodeId = nodeId + } else if (!graph[nodeId].length && nodeDependencies[nodeId] > 0) { endingNodeId = nodeId } }) diff --git a/packages/ui/src/views/chatmessage/ChatMessage.css b/packages/ui/src/views/chatmessage/ChatMessage.css index 4aa651b1..a29e49ff 100644 --- a/packages/ui/src/views/chatmessage/ChatMessage.css +++ b/packages/ui/src/views/chatmessage/ChatMessage.css @@ -1,7 +1,3 @@ -.cloudform { - position: relative; -} - .messagelist { width: 100%; height: 100%; @@ -113,13 +109,11 @@ position: relative; flex-direction: column; padding: 10px; - max-width: 500px; } .cloud { - width: '100%'; - max-width: 500px; - height: 73vh; + width: 400px; + height: calc(100vh - 260px); border-radius: 0.5rem; display: flex; justify-content: center; diff --git a/packages/ui/src/views/chatmessage/ChatMessage.js b/packages/ui/src/views/chatmessage/ChatMessage.js index 45cd3873..4fbb54e6 100644 --- a/packages/ui/src/views/chatmessage/ChatMessage.js +++ b/packages/ui/src/views/chatmessage/ChatMessage.js @@ -336,13 +336,13 @@ export const ChatMessage = ({ chatflowid }) => {
-
-
+
+ Date: Wed, 19 Apr 2023 22:16:20 +0100 Subject: [PATCH 2/7] add babyagi --- .../nodes/agents/BabyAGI/BabyAGI.ts | 362 ++---------------- .../nodes/agents/BabyAGI/babyagi.jpg | Bin 0 -> 20548 bytes .../nodes/agents/BabyAGI/babyagi.svg | 9 - .../components/nodes/agents/BabyAGI/core.ts | 262 +++++++++++++ 4 files changed, 286 insertions(+), 347 deletions(-) create mode 100644 packages/components/nodes/agents/BabyAGI/babyagi.jpg delete mode 100644 packages/components/nodes/agents/BabyAGI/babyagi.svg create mode 100644 packages/components/nodes/agents/BabyAGI/core.ts diff --git a/packages/components/nodes/agents/BabyAGI/BabyAGI.ts b/packages/components/nodes/agents/BabyAGI/BabyAGI.ts index 8b297215..e8f56aa2 100644 --- a/packages/components/nodes/agents/BabyAGI/BabyAGI.ts +++ b/packages/components/nodes/agents/BabyAGI/BabyAGI.ts @@ -1,15 +1,7 @@ import { INode, INodeData, INodeParams } from '../../../src/Interface' -import { Configuration, CreateChatCompletionRequest, CreateCompletionRequest, OpenAIApi } from 'openai' -import { PineconeClient } from '@pinecone-database/pinecone' -import { CreateIndexRequest } from '@pinecone-database/pinecone/dist/pinecone-generated-ts-fetch' -import { VectorOperationsApi } from '@pinecone-database/pinecone/dist/pinecone-generated-ts-fetch' -import { v4 as uuidv4 } from 'uuid' - -interface Task { - id: string - name: string - priority: number // 1 is highest priority -} +import { BabyAGI } from './core' +import { BaseChatModel } from 'langchain/chat_models' +import { VectorStore } from 'langchain/vectorstores' class BabyAGI_Agents implements INode { label: string @@ -26,351 +18,45 @@ class BabyAGI_Agents implements INode { this.name = 'babyAGI' this.type = 'BabyAGI' this.category = 'Agents' - this.icon = 'babyagi.svg' + this.icon = 'babyagi.jpg' this.description = 'Task Driven Autonomous Agent which creates new task and reprioritizes task list based on objective' + this.baseClasses = ['BabyAGI'] this.inputs = [ + { + label: 'Chat Model', + name: 'model', + type: 'BaseChatModel' + }, + { + label: 'Vector Store', + name: 'vectorStore', + type: 'VectorStore' + }, { label: 'Task Loop', name: 'taskLoop', type: 'number', default: 3 - }, - { - label: 'OpenAI Api Key', - name: 'openAIApiKey', - type: 'password' - }, - { - label: 'Pinecone Api Key', - name: 'pineconeApiKey', - type: 'password' - }, - { - label: 'Pinecone Environment', - name: 'pineconeEnv', - type: 'string' - }, - { - label: 'Pinecone Index', - name: 'pineconeIndex', - type: 'string' - }, - { - label: 'Model Name', - name: 'modelName', - type: 'options', - options: [ - { - label: 'gpt-4', - name: 'gpt-4' - }, - { - label: 'gpt-4-0314', - name: 'gpt-4-0314' - }, - { - label: 'gpt-4-32k-0314', - name: 'gpt-4-32k-0314' - }, - { - label: 'gpt-3.5-turbo', - name: 'gpt-3.5-turbo' - }, - { - label: 'gpt-3.5-turbo-0301', - name: 'gpt-3.5-turbo-0301' - } - ], - default: 'gpt-3.5-turbo', - optional: true } ] } - async getBaseClasses(): Promise { - return ['BabyAGI'] - } + async init(nodeData: INodeData): Promise { + const model = nodeData.inputs?.model as BaseChatModel + const vectorStore = nodeData.inputs?.vectorStore as VectorStore + const taskLoop = nodeData.inputs?.taskLoop as string - async init(): Promise { - return null + const babyAgi = BabyAGI.fromLLM(model, vectorStore, parseInt(taskLoop, 10)) + return babyAgi } async run(nodeData: INodeData, input: string): Promise { - const openAIApiKey = nodeData.inputs?.openAIApiKey as string - const pineconeApiKey = nodeData.inputs?.pineconeApiKey as string - const pineconeEnv = nodeData.inputs?.pineconeEnv as string - const index = nodeData.inputs?.pineconeIndex as string - const modelName = nodeData.inputs?.modelName as string - const taskLoop = nodeData.inputs?.taskLoop as string + const executor = nodeData.instance as BabyAGI const objective = input - const configuration = new Configuration({ - apiKey: openAIApiKey - }) - const openai = new OpenAIApi(configuration) - - const pinecone = new PineconeClient() - await pinecone.init({ - apiKey: pineconeApiKey, - environment: pineconeEnv - }) - - const dimension = 1536 - const metric = 'cosine' - const podType = 'p1' - - const indexList = await pinecone.listIndexes() - if (!indexList.includes(index)) { - const createIndexOptions: CreateIndexRequest = { - createRequest: { - name: index, - dimension, - metric, - podType - } - } - await pinecone.createIndex(createIndexOptions) - } - - let vectorIndex: VectorOperationsApi = pinecone.Index(index) - - let taskList: Task[] = [] - let embeddingList = new Map() - - taskList = [ - { - id: uuidv4(), - name: 'Develop a task list', - priority: 1 - } - ] - - return await mainLoop(openai, pinecone, index, embeddingList, vectorIndex, taskList, objective, modelName, taskLoop) + const res = await executor.call({ objective }) + return res } } -export const getADAEmbedding = async (openai: OpenAIApi, text: string, embeddingList: Map): Promise => { - //console.log('\nGetting ADA embedding for: ', text) - - if (embeddingList.has(text)) { - //console.log('Embedding already exists for: ', text) - const numbers = embeddingList.get(text) - return numbers ?? [] - } - - const embedding = ( - await openai.createEmbedding({ - input: [text], - model: 'text-embedding-ada-002' - }) - ).data?.data[0].embedding - - embeddingList.set(text, embedding) - - return embedding -} - -export const openAICall = async (openai: OpenAIApi, prompt: string, gptVersion: string, temperature = 0.5, max_tokens = 100) => { - if (gptVersion === 'gpt-3.5-turbo' || gptVersion === 'gpt-4' || gptVersion === 'gpt-4-32k') { - // Chat completion - const options: CreateChatCompletionRequest = { - model: gptVersion, - messages: [{ role: 'user', content: prompt }], - temperature, - max_tokens, - n: 1 - } - const data = (await openai.createChatCompletion(options)).data - - return data?.choices[0]?.message?.content.trim() ?? '' - } else { - // Prompt completion - const options: CreateCompletionRequest = { - model: gptVersion, - prompt, - temperature, - max_tokens, - top_p: 1, - frequency_penalty: 0, - presence_penalty: 0 - } - const data = (await openai.createCompletion(options)).data - - return data?.choices[0]?.text?.trim() ?? '' - } -} - -export const taskCreationAgent = async ( - openai: OpenAIApi, - taskList: Task[], - objective: string, - result: string, - taskDescription: string, - gptVersion = 'gpt-3.5-turbo' -): Promise => { - const prompt = `You are an task creation AI that uses the result of an execution agent to create new tasks with the following objective: ${objective}, The last completed task has the result: ${result}. This result was based on this task description: ${taskDescription}. These are incomplete tasks: ${taskList.join( - ', ' - )}. Based on the result, create new tasks to be completed by the AI system that do not overlap with incomplete tasks. Return the tasks as an array.` - const response = await openAICall(openai, prompt, gptVersion) - const newTaskNames = response.split('\n') - - return newTaskNames.map((name) => ({ - id: uuidv4(), - name, - priority: taskList.length + 1 - })) -} - -export const prioritizationAgent = async ( - openai: OpenAIApi, - taskList: Task[], - taskPriority: number, - objective: string, - gptVersion = 'gpt-3.5-turbo' -): Promise => { - const taskNames = taskList.map((t) => t.name) - const startPriority = taskPriority + 1 - - const prompt = `You are an task prioritization AI tasked with cleaning the formatting of and reprioritizing the following tasks: ${taskNames}. Consider the ultimate objective of your team: ${objective}. Do not remove any tasks. Return the result as a list, like: - #. First task - #. Second task - Start the task list with number ${startPriority}.` - const response = await openAICall(openai, prompt, gptVersion) - const newTasks = response.split('\n') - - // Parse and add new tasks - return ( - newTasks - .map((taskString) => { - const taskParts = taskString.trim().split('.', 2) - - if (taskParts.length === 2) { - const id = uuidv4() - const name = taskParts[1].trim() - const priority = parseInt(taskParts[0]) - return { - id, - name, - priority - } as Task - } - }) - // Remove lines that don't have a task - .filter((t) => t !== undefined) - // Sort by priority - .sort((a, b) => a!.priority - b!.priority) as Task[] - ) -} - -export const contextAgent = async ( - openai: OpenAIApi, - pinecone: PineconeClient, - indexName: string, - embeddingList: Map, - objective: string, - topK: number -) => { - const index = pinecone.Index(indexName) - const queryEmbedding = await getADAEmbedding(openai, objective, embeddingList) - - const results = await index.query({ - queryRequest: { - vector: queryEmbedding, - includeMetadata: true, - topK - } - }) - const sortedResults = results.matches?.sort((a, b) => (b?.score ?? 0) - (a?.score ?? 0)) ?? [] - - return sortedResults.map((item) => (item.metadata as any)?.task ?? '') -} - -export const executionAgent = async ( - openai: OpenAIApi, - pinecone: PineconeClient, - indexName: string, - embeddingList: Map, - objective: string, - task: Task, - gptVersion = 'gpt-3.5-turbo' -) => { - const context = await contextAgent(openai, pinecone, indexName, embeddingList, objective, 5) - const prompt = `You are an AI who performs one task based on the following objective: ${objective}.\nTake into account these previously completed tasks: ${context}\nYour task: ${task.name}\nResponse:` - - //console.log('\nexecution prompt: ', prompt, '\n') - - return openAICall(openai, prompt, gptVersion, 0.7, 2000) -} - -export const mainLoop = async ( - openai: OpenAIApi, - pinecone: PineconeClient, - indexName: string, - embeddingList: Map, - index: VectorOperationsApi, - taskList: Task[], - objective: string, - modelName: string, - taskLoop: string -): Promise => { - const RUN_LIMIT = parseInt(taskLoop, 10) || 3 - let finalResult = '' - - for (let run = 0; run < RUN_LIMIT; run++) { - let enrichedResult: any - let task: Task | undefined - - if (taskList.length > 0) { - // Step 1: Pull the task - task = taskList.shift() - - if (!task) { - //console.log('No tasks left to complete. Exiting.') - break - } - - console.log(`\x1b[95m\x1b[1m\n*****TASK LIST*****\n\x1b[0m\x1b[0m - ${taskList.map((t) => ` ${t?.priority}. ${t?.name}`).join('\n')} - \x1b[92m\x1b[1m\n*****NEXT TASK*****\n\x1b[0m\x1b[0m - ${task.name}`) - - // Step 2: Execute the task - const result = await executionAgent(openai, pinecone, indexName, embeddingList, objective, task) - console.log('\x1b[93m\x1b[1m\n*****TASK RESULT*****\n\x1b[0m\x1b[0m') - console.log(result) - finalResult = result - - // Step 3: Enrich result and store in Pinecone - enrichedResult = { data: result } - const vector = enrichedResult.data // extract the actual result from the dictionary - const embeddingResult = await getADAEmbedding(openai, vector, embeddingList) - await index.upsert({ - upsertRequest: { - vectors: [ - { - id: task.id, - values: embeddingResult, - metadata: { task: task.name, result } - } - ] - } - }) - } - - // Step 4: Create new tasks and reprioritize task list - if (enrichedResult) { - const newTasks = await taskCreationAgent(openai, taskList, objective, enrichedResult.data, task!.name) - //console.log('newTasks', newTasks) - taskList = [...taskList, ...newTasks] - - taskList = await prioritizationAgent(openai, taskList, task!.priority, objective, modelName) - //console.log(`Reprioritized task list: ${taskList.map((t) => `[${t?.priority}] ${t?.id}: ${t?.name}`).join(', ')}`) - } else { - break - } - } - - return finalResult -} - module.exports = { nodeClass: BabyAGI_Agents } diff --git a/packages/components/nodes/agents/BabyAGI/babyagi.jpg b/packages/components/nodes/agents/BabyAGI/babyagi.jpg new file mode 100644 index 0000000000000000000000000000000000000000..cd5851391776f214998bd85cc2a1a1eb0203c68a GIT binary patch literal 20548 zcmbrl1#ld_vM{=4h#jw)Ic8>N#+aEMGc&~uiJ6%>W@bpt%*^bVnepG`JNKMZxBhys zUcKHOsi!6NNSc<^-O{`-zHb76(&AF$05C8B01Wg4yl;c&NQsE(D=2*ymy#9xn*bhT zZEWKN$p`@0*g88ZNeB~ZXlfAw{tFC^o$Q4a6lDL4^uN%%`9ItNfEl_!y#80>|J&_{ zFD6dLpbEl*GIAQ*J351KK@cwQ=4}55j{)Im#^#1!KzIQNr*#BX5QIlEYasns;BmlwyB7hOV1z-WN1~>!gK(Q^T&;IY_nE#fO2iSqi7=uE4fCs=4RKg5k z4k}9vqPhT_04AW=6ht=x{j5PbK=7Zw|4*MfnX>%h2Wm2cGynj#^ZtHK4FJHT0|2kz z-rt||-rryI0RV_a0N_``f6Ch>fV%SxM34Co?NcTIfD{M-Gg3OG=cgUYu(<^ z(eUqcAV49wsVM+(RSW&@c$FFd#ts@Bt1183_di83`E~6$1|w6%7X+85xTh z3kM&ckdP1+ljIW#!6!TdLV`a`z(7S|pkY43!hR$`Lq;R`{|xWl0AyIO7_b-!FcJVb zG8hCh*n2NXAV32N>d%1sH-LddK!R!s3rfWSB|w1vUsB(f0SFLa0B|4#5cC@F1pi(5 zeMj z6DS)H6o99Fh&7G7F`kSFbJ(`>VcMSZp(SscC%`qc%0f)4yaaVQ)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c-~NQM^np7$S2Mn7qg4H!-=36PS^OeGD+dqDLU09dCWkq_BfRX!4uI zl}f>|>(T`vtzzu0`@xGPr1Npa3pMi=Y4?B?KJl`w!VJwElANlcqq-|vTGm;cJ)~1l zZdd&?V2zQQk?}USw9)b6UV^brPOwRc9O^qv$!xDn=KOT#2V{H9GiP}FcQK*fEwi<% z{-%OKH*HK0S7-MgD$2J<;#esR07aywCR27sHH*Ypkzz%RMk5j@p;3zdF-lVtl% zaO`6oKQY?(qYAXK+EmAq8mGpcI@Gi3@5Ky$3;s)CUOWuOq3)Dx@gOCN=_zRYLom%K z!9aL`;s=RH4j^IM2z?7m=_}Csj@b12UWkq&c$DCj;#Y}IB{-DgcFOT7#O$4toJ#R4 z#IF!MK=JVd#19ZWKyd*H?VXVH2(PBHvYbPr5lp63sZzdx4%yr3tgq7Gc6vx4>6MlK QP^71+;pnMSrAnXw*-qa!#{d8T literal 0 HcmV?d00001 diff --git a/packages/components/nodes/agents/BabyAGI/babyagi.svg b/packages/components/nodes/agents/BabyAGI/babyagi.svg deleted file mode 100644 index c87861e5..00000000 --- a/packages/components/nodes/agents/BabyAGI/babyagi.svg +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/packages/components/nodes/agents/BabyAGI/core.ts b/packages/components/nodes/agents/BabyAGI/core.ts new file mode 100644 index 00000000..95423fff --- /dev/null +++ b/packages/components/nodes/agents/BabyAGI/core.ts @@ -0,0 +1,262 @@ +import { LLMChain } from 'langchain/chains' +import { BaseChatModel } from 'langchain/chat_models' +import { VectorStore } from 'langchain/dist/vectorstores/base' +import { Document } from 'langchain/document' +import { PromptTemplate } from 'langchain/prompts' + +class TaskCreationChain extends LLMChain { + constructor(prompt: PromptTemplate, llm: BaseChatModel) { + super({ prompt, llm }) + } + + static from_llm(llm: BaseChatModel): LLMChain { + const taskCreationTemplate: string = + 'You are a task creation AI that uses the result of an execution agent' + + ' to create new tasks with the following objective: {objective},' + + ' The last completed task has the result: {result}.' + + ' This result was based on this task description: {task_description}.' + + ' These are incomplete tasks list: {incomplete_tasks}.' + + ' Based on the result, create new tasks to be completed' + + ' by the AI system that do not overlap with incomplete tasks.' + + ' Return the tasks as an array.' + + const prompt = new PromptTemplate({ + template: taskCreationTemplate, + inputVariables: ['result', 'task_description', 'incomplete_tasks', 'objective'] + }) + + return new TaskCreationChain(prompt, llm) + } +} + +class TaskPrioritizationChain extends LLMChain { + constructor(prompt: PromptTemplate, llm: BaseChatModel) { + super({ prompt, llm }) + } + + static from_llm(llm: BaseChatModel): TaskPrioritizationChain { + const taskPrioritizationTemplate: string = + 'You are a task prioritization AI tasked with cleaning the formatting of and reprioritizing' + + ' the following task list: {task_names}.' + + ' Consider the ultimate objective of your team: {objective}.' + + ' Do not remove any tasks. Return the result as a numbered list, like:' + + ' #. First task' + + ' #. Second task' + + ' Start the task list with number {next_task_id}.' + const prompt = new PromptTemplate({ + template: taskPrioritizationTemplate, + inputVariables: ['task_names', 'next_task_id', 'objective'] + }) + return new TaskPrioritizationChain(prompt, llm) + } +} + +class ExecutionChain extends LLMChain { + constructor(prompt: PromptTemplate, llm: BaseChatModel) { + super({ prompt, llm }) + } + + static from_llm(llm: BaseChatModel): LLMChain { + const executionTemplate: string = + 'You are an AI who performs one task based on the following objective: {objective}.' + + ' Take into account these previously completed tasks: {context}.' + + ' Your task: {task}.' + + ' Response:' + + const prompt = new PromptTemplate({ + template: executionTemplate, + inputVariables: ['objective', 'context', 'task'] + }) + + return new ExecutionChain(prompt, llm) + } +} + +async function getNextTask( + taskCreationChain: LLMChain, + result: string, + taskDescription: string, + taskList: string[], + objective: string +): Promise { + const incompleteTasks: string = taskList.join(', ') + const response: string = await taskCreationChain.predict({ + result, + task_description: taskDescription, + incomplete_tasks: incompleteTasks, + objective + }) + + const newTasks: string[] = response.split('\n') + + return newTasks.filter((taskName) => taskName.trim()).map((taskName) => ({ task_name: taskName })) +} + +interface Task { + task_id: number + task_name: string +} + +async function prioritizeTasks( + taskPrioritizationChain: LLMChain, + thisTaskId: number, + taskList: Task[], + objective: string +): Promise { + const next_task_id = thisTaskId + 1 + const task_names = taskList.map((t) => t.task_name).join(', ') + const response = await taskPrioritizationChain.predict({ task_names, next_task_id, objective }) + const newTasks = response.split('\n') + const prioritizedTaskList: Task[] = [] + + for (const taskString of newTasks) { + if (!taskString.trim()) { + // eslint-disable-next-line no-continue + continue + } + const taskParts = taskString.trim().split('. ', 2) + if (taskParts.length === 2) { + const task_id = parseInt(taskParts[0].trim(), 10) + const task_name = taskParts[1].trim() + prioritizedTaskList.push({ task_id, task_name }) + } + } + + return prioritizedTaskList +} + +export async function get_top_tasks(vectorStore: VectorStore, query: string, k: number): Promise { + const docs = await vectorStore.similaritySearch(query, k) + let returnDocs: string[] = [] + for (const doc of docs) { + returnDocs.push(doc.metadata.task) + } + return returnDocs +} + +async function executeTask(vectorStore: VectorStore, executionChain: LLMChain, objective: string, task: string, k = 5): Promise { + const context = await get_top_tasks(vectorStore, objective, k) + //const docContent = await retrieve_embeddings(table, task, 0.5); + //console.log(docContent); + return executionChain.predict({ objective, context, task }) +} + +export class BabyAGI { + taskList: Array = [] + + taskCreationChain: TaskCreationChain + + taskPrioritizationChain: TaskPrioritizationChain + + executionChain: ExecutionChain + + taskIdCounter = 1 + + vectorStore: VectorStore + + maxIterations = 3 + + constructor( + taskCreationChain: TaskCreationChain, + taskPrioritizationChain: TaskPrioritizationChain, + executionChain: ExecutionChain, + vectorStore: VectorStore, + maxIterations: number + ) { + this.taskCreationChain = taskCreationChain + this.taskPrioritizationChain = taskPrioritizationChain + this.executionChain = executionChain + this.vectorStore = vectorStore + this.maxIterations = maxIterations + } + + addTask(task: Task) { + this.taskList.push(task) + } + + printTaskList() { + console.log('\x1b[95m\x1b[1m\n*****TASK LIST*****\n\x1b[0m\x1b[0m') + this.taskList.forEach((t) => console.log(`${t.task_id}: ${t.task_name}`)) + } + + printNextTask(task: Task) { + console.log('\x1b[92m\x1b[1m\n*****NEXT TASK*****\n\x1b[0m\x1b[0m') + console.log(`${task.task_id}: ${task.task_name}`) + } + + printTaskResult(result: string) { + console.log('\x1b[93m\x1b[1m\n*****TASK RESULT*****\n\x1b[0m\x1b[0m') + console.log(result) + } + + getInputKeys(): string[] { + return ['objective'] + } + + getOutputKeys(): string[] { + return [] + } + + async call(inputs: Record): Promise { + const { objective } = inputs + const firstTask = inputs.first_task || 'Make a todo list' + this.addTask({ task_id: 1, task_name: firstTask }) + let numIters = 0 + let loop = true + let finalResult = '' + + while (loop) { + if (this.taskList.length) { + this.printTaskList() + + // Step 1: Pull the first task + const task = this.taskList.shift() + if (!task) break + this.printNextTask(task) + + // Step 2: Execute the task + const result = await executeTask(this.vectorStore, this.executionChain, objective, task.task_name) + const thisTaskId = task.task_id + finalResult = result + this.printTaskResult(result) + + // Step 3: Store the result in Pinecone + const docs = new Document({ pageContent: result, metadata: { task: task.task_name } }) + this.vectorStore.addDocuments([docs]) + + // Step 4: Create new tasks and reprioritize task list + const newTasks = await getNextTask( + this.taskCreationChain, + result, + task.task_name, + this.taskList.map((t) => t.task_name), + objective + ) + newTasks.forEach((newTask) => { + this.taskIdCounter += 1 + // eslint-disable-next-line no-param-reassign + newTask.task_id = this.taskIdCounter + this.addTask(newTask) + }) + this.taskList = await prioritizeTasks(this.taskPrioritizationChain, thisTaskId, this.taskList, objective) + } + + numIters += 1 + if (this.maxIterations !== null && numIters === this.maxIterations) { + console.log('\x1b[91m\x1b[1m\n*****TASK ENDING*****\n\x1b[0m\x1b[0m') + console.log(this.maxIterations) + loop = false + this.taskList = [] + } + } + + return finalResult + } + + static fromLLM(llm: BaseChatModel, vectorstore: VectorStore, maxIterations = 3): BabyAGI { + const taskCreationChain = TaskCreationChain.from_llm(llm) + const taskPrioritizationChain = TaskPrioritizationChain.from_llm(llm) + const executionChain = ExecutionChain.from_llm(llm) + return new BabyAGI(taskCreationChain, taskPrioritizationChain, executionChain, vectorstore, maxIterations) + } +} From d189ff6be8ece7996dd6966e95b1f0e49b404e9f Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 19 Apr 2023 22:22:14 +0100 Subject: [PATCH 3/7] yarn lint fix --- packages/components/nodes/agents/BabyAGI/core.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/components/nodes/agents/BabyAGI/core.ts b/packages/components/nodes/agents/BabyAGI/core.ts index 95423fff..bd6f61f8 100644 --- a/packages/components/nodes/agents/BabyAGI/core.ts +++ b/packages/components/nodes/agents/BabyAGI/core.ts @@ -136,8 +136,6 @@ export async function get_top_tasks(vectorStore: VectorStore, query: string, k: async function executeTask(vectorStore: VectorStore, executionChain: LLMChain, objective: string, task: string, k = 5): Promise { const context = await get_top_tasks(vectorStore, objective, k) - //const docContent = await retrieve_embeddings(table, task, 0.5); - //console.log(docContent); return executionChain.predict({ objective, context, task }) } @@ -175,17 +173,23 @@ export class BabyAGI { } printTaskList() { + // eslint-disable-next-line no-console console.log('\x1b[95m\x1b[1m\n*****TASK LIST*****\n\x1b[0m\x1b[0m') + // eslint-disable-next-line no-console this.taskList.forEach((t) => console.log(`${t.task_id}: ${t.task_name}`)) } printNextTask(task: Task) { + // eslint-disable-next-line no-console console.log('\x1b[92m\x1b[1m\n*****NEXT TASK*****\n\x1b[0m\x1b[0m') + // eslint-disable-next-line no-console console.log(`${task.task_id}: ${task.task_name}`) } printTaskResult(result: string) { + // eslint-disable-next-line no-console console.log('\x1b[93m\x1b[1m\n*****TASK RESULT*****\n\x1b[0m\x1b[0m') + // eslint-disable-next-line no-console console.log(result) } @@ -243,7 +247,9 @@ export class BabyAGI { numIters += 1 if (this.maxIterations !== null && numIters === this.maxIterations) { + // eslint-disable-next-line no-console console.log('\x1b[91m\x1b[1m\n*****TASK ENDING*****\n\x1b[0m\x1b[0m') + // eslint-disable-next-line no-console console.log(this.maxIterations) loop = false this.taskList = [] From d9cbaf8a28a718e1e46aca2526a4c97d34b1d929 Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 19 Apr 2023 22:24:18 +0100 Subject: [PATCH 4/7] remove unwanted console.log --- packages/components/nodes/agents/BabyAGI/core.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/components/nodes/agents/BabyAGI/core.ts b/packages/components/nodes/agents/BabyAGI/core.ts index bd6f61f8..a6179ed8 100644 --- a/packages/components/nodes/agents/BabyAGI/core.ts +++ b/packages/components/nodes/agents/BabyAGI/core.ts @@ -249,8 +249,6 @@ export class BabyAGI { if (this.maxIterations !== null && numIters === this.maxIterations) { // eslint-disable-next-line no-console console.log('\x1b[91m\x1b[1m\n*****TASK ENDING*****\n\x1b[0m\x1b[0m') - // eslint-disable-next-line no-console - console.log(this.maxIterations) loop = false this.taskList = [] } From b06d220ceb0488acff3c528f4c4a43a463c79d79 Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 20 Apr 2023 23:02:55 +0100 Subject: [PATCH 5/7] add babyagi template --- packages/server/marketplaces/BabyAGI.json | 299 ++++++++++++++++++---- 1 file changed, 253 insertions(+), 46 deletions(-) diff --git a/packages/server/marketplaces/BabyAGI.json b/packages/server/marketplaces/BabyAGI.json index 8091ef03..9a24df49 100644 --- a/packages/server/marketplaces/BabyAGI.json +++ b/packages/server/marketplaces/BabyAGI.json @@ -1,50 +1,29 @@ { - "description": "Given an objective, tasks will be created, stored into Pinecone and reprioritized", + "description": "Use BabyAGI to create tasks and reprioritize for a given objective", "nodes": [ { "width": 300, - "height": 769, - "id": "babyAGI_0", + "height": 472, + "id": "chatOpenAI_0", "position": { - "x": 542.130412774738, - "y": 154.52145148106695 + "x": 623.4625717728469, + "y": -384.9179263816219 }, "type": "customNode", "data": { - "id": "babyAGI_0", - "label": "BabyAGI", - "name": "babyAGI", - "type": "BabyAGI", - "baseClasses": ["AgentExecutor"], - "category": "Agents", - "description": "Conversational agent for a chat model. It will utilize chat specific prompts", + "id": "chatOpenAI_0", + "label": "ChatOpenAI", + "name": "chatOpenAI", + "type": "ChatOpenAI", + "baseClasses": ["ChatOpenAI", "BaseChatModel", "BaseLanguageModel"], + "category": "Chat Models", + "description": "Wrapper around OpenAI large language models that use the Chat endpoint", "inputParams": [ - { - "label": "Task Loop", - "name": "taskLoop", - "type": "number", - "default": 3 - }, { "label": "OpenAI Api Key", "name": "openAIApiKey", "type": "password" }, - { - "label": "Pinecone Api Key", - "name": "pineconeApiKey", - "type": "password" - }, - { - "label": "Pinecone Environment", - "name": "pineconeEnv", - "type": "string" - }, - { - "label": "Pinecone Index", - "name": "pineconeIndex", - "type": "string" - }, { "label": "Model Name", "name": "modelName", @@ -73,32 +52,260 @@ ], "default": "gpt-3.5-turbo", "optional": true + }, + { + "label": "Temperature", + "name": "temperature", + "type": "number", + "default": 0.9, + "optional": true } ], "inputAnchors": [], "inputs": { - "taskLoop": "3", - "pineconeEnv": "us-west4-gcp", - "pineconeIndex": "test", - "modelName": "gpt-3.5-turbo" + "modelName": "gpt-3.5-turbo", + "temperature": "0" }, "outputAnchors": [ { - "id": "babyAGI_0-output-babyAGI-AgentExecutor", - "name": "babyAGI", - "label": "BabyAGI", - "type": "AgentExecutor" + "id": "chatOpenAI_0-output-chatOpenAI-ChatOpenAI|BaseChatModel|BaseLanguageModel", + "name": "chatOpenAI", + "label": "ChatOpenAI", + "type": "ChatOpenAI | BaseChatModel | BaseLanguageModel" } ], "selected": false }, "selected": false, - "dragging": false, "positionAbsolute": { - "x": 542.130412774738, - "y": 154.52145148106695 - } + "x": 623.4625717728469, + "y": -384.9179263816219 + }, + "dragging": false + }, + { + "width": 300, + "height": 278, + "id": "openAIEmbeddings_0", + "position": { + "x": -85.14926831129219, + "y": -175.8984338500009 + }, + "type": "customNode", + "data": { + "id": "openAIEmbeddings_0", + "label": "OpenAI Embeddings", + "name": "openAIEmbeddings", + "type": "OpenAIEmbeddings", + "baseClasses": ["OpenAIEmbeddings", "Embeddings"], + "category": "Embeddings", + "description": "OpenAI API to generate embeddings for a given text", + "inputParams": [ + { + "label": "OpenAI Api Key", + "name": "openAIApiKey", + "type": "password" + } + ], + "inputAnchors": [], + "inputs": {}, + "outputAnchors": [ + { + "id": "openAIEmbeddings_0-output-openAIEmbeddings-OpenAIEmbeddings|Embeddings", + "name": "openAIEmbeddings", + "label": "OpenAIEmbeddings", + "type": "OpenAIEmbeddings | Embeddings" + } + ], + "selected": false + }, + "selected": false, + "positionAbsolute": { + "x": -85.14926831129219, + "y": -175.8984338500009 + }, + "dragging": false + }, + { + "width": 300, + "height": 552, + "id": "pineconeExistingIndex_0", + "position": { + "x": 264.86118448732543, + "y": -305.52350050145094 + }, + "type": "customNode", + "data": { + "id": "pineconeExistingIndex_0", + "label": "Pinecone Load Existing Index", + "name": "pineconeExistingIndex", + "type": "Pinecone", + "baseClasses": ["Pinecone", "BaseRetriever"], + "category": "Vector Stores", + "description": "Load existing index from Pinecone (i.e: Document has been upserted)", + "inputParams": [ + { + "label": "Pinecone Api Key", + "name": "pineconeApiKey", + "type": "password", + "id": "pineconeExistingIndex_0-input-pineconeApiKey-password" + }, + { + "label": "Pinecone Environment", + "name": "pineconeEnv", + "type": "string", + "id": "pineconeExistingIndex_0-input-pineconeEnv-string" + }, + { + "label": "Pinecone Index", + "name": "pineconeIndex", + "type": "string", + "id": "pineconeExistingIndex_0-input-pineconeIndex-string" + } + ], + "inputAnchors": [ + { + "label": "Embeddings", + "name": "embeddings", + "type": "Embeddings", + "id": "pineconeExistingIndex_0-input-embeddings-Embeddings" + } + ], + "inputs": { + "embeddings": "{{openAIEmbeddings_0.data.instance}}", + "pineconeEnv": "us-west4-gcp", + "pineconeIndex": "test" + }, + "outputAnchors": [ + { + "name": "output", + "label": "Output", + "type": "options", + "options": [ + { + "id": "pineconeExistingIndex_0-output-retriever-Pinecone|BaseRetriever", + "name": "retriever", + "label": "Pinecone Retriever", + "type": "Pinecone | BaseRetriever" + }, + { + "id": "pineconeExistingIndex_0-output-vectorStore-Pinecone|VectorStore", + "name": "vectorStore", + "label": "Pinecone Vector Store", + "type": "Pinecone | VectorStore" + } + ], + "default": "retriever" + } + ], + "outputs": { + "output": "vectorStore" + }, + "selected": false + }, + "selected": false, + "positionAbsolute": { + "x": 264.86118448732543, + "y": -305.52350050145094 + }, + "dragging": false + }, + { + "width": 300, + "height": 379, + "id": "babyAGI_0", + "position": { + "x": 982.9913269506158, + "y": -53.95939754784533 + }, + "type": "customNode", + "data": { + "id": "babyAGI_0", + "label": "BabyAGI", + "name": "babyAGI", + "type": "BabyAGI", + "baseClasses": ["BabyAGI"], + "category": "Agents", + "description": "Task Driven Autonomous Agent which creates new task and reprioritizes task list based on objective", + "inputParams": [ + { + "label": "Task Loop", + "name": "taskLoop", + "type": "number", + "default": 3, + "id": "babyAGI_0-input-taskLoop-number" + } + ], + "inputAnchors": [ + { + "label": "Chat Model", + "name": "model", + "type": "BaseChatModel", + "id": "babyAGI_0-input-model-BaseChatModel" + }, + { + "label": "Vector Store", + "name": "vectorStore", + "type": "VectorStore", + "id": "babyAGI_0-input-vectorStore-VectorStore" + } + ], + "inputs": { + "model": "{{chatOpenAI_0.data.instance}}", + "vectorStore": "{{pineconeExistingIndex_0.data.instance}}", + "taskLoop": 3 + }, + "outputAnchors": [ + { + "id": "babyAGI_0-output-babyAGI-BabyAGI", + "name": "babyAGI", + "label": "BabyAGI", + "type": "BabyAGI" + } + ], + "outputs": {}, + "selected": false + }, + "positionAbsolute": { + "x": 982.9913269506158, + "y": -53.95939754784533 + }, + "selected": false } ], - "edges": [] + "edges": [ + { + "source": "openAIEmbeddings_0", + "sourceHandle": "openAIEmbeddings_0-output-openAIEmbeddings-OpenAIEmbeddings|Embeddings", + "target": "pineconeExistingIndex_0", + "targetHandle": "pineconeExistingIndex_0-input-embeddings-Embeddings", + "type": "buttonedge", + "id": "openAIEmbeddings_0-openAIEmbeddings_0-output-openAIEmbeddings-OpenAIEmbeddings|Embeddings-pineconeExistingIndex_0-pineconeExistingIndex_0-input-embeddings-Embeddings", + "data": { + "label": "" + } + }, + { + "source": "chatOpenAI_0", + "sourceHandle": "chatOpenAI_0-output-chatOpenAI-ChatOpenAI|BaseChatModel|BaseLanguageModel", + "target": "babyAGI_0", + "targetHandle": "babyAGI_0-input-model-BaseChatModel", + "type": "buttonedge", + "id": "chatOpenAI_0-chatOpenAI_0-output-chatOpenAI-ChatOpenAI|BaseChatModel|BaseLanguageModel-babyAGI_0-babyAGI_0-input-model-BaseChatModel", + "data": { + "label": "" + } + }, + { + "source": "pineconeExistingIndex_0", + "sourceHandle": "pineconeExistingIndex_0-output-vectorStore-Pinecone|VectorStore", + "target": "babyAGI_0", + "targetHandle": "babyAGI_0-input-vectorStore-VectorStore", + "type": "buttonedge", + "id": "pineconeExistingIndex_0-pineconeExistingIndex_0-output-vectorStore-Pinecone|VectorStore-babyAGI_0-babyAGI_0-input-vectorStore-VectorStore", + "data": { + "label": "" + } + } + ] } From bf0c10d0bccb8fd56437be9ebd60164bc855919e Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 20 Apr 2023 23:14:41 +0100 Subject: [PATCH 6/7] remove unused types uuid --- packages/components/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/components/package.json b/packages/components/package.json index 214ec332..412b505c 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -35,7 +35,6 @@ }, "devDependencies": { "@types/gulp": "4.0.9", - "@types/uuid": "^9.0.1", "@types/ws": "^8.5.3", "gulp": "^4.0.2", "typescript": "^4.8.4" From 4ce8e55316aab302acd29fea69db6c8bc9f50362 Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 20 Apr 2023 23:32:49 +0100 Subject: [PATCH 7/7] update marketplace templates --- .../Conversational Retrieval QA Chain.json | 206 ++++++++++-------- .../server/marketplaces/Github Repo QnA.json | 182 +++++++++------- 2 files changed, 214 insertions(+), 174 deletions(-) diff --git a/packages/server/marketplaces/Conversational Retrieval QA Chain.json b/packages/server/marketplaces/Conversational Retrieval QA Chain.json index 082c53f6..9da2f6a4 100644 --- a/packages/server/marketplaces/Conversational Retrieval QA Chain.json +++ b/packages/server/marketplaces/Conversational Retrieval QA Chain.json @@ -230,77 +230,6 @@ }, "dragging": false }, - { - "width": 300, - "height": 577, - "id": "pineconeUpsert_0", - "position": { - "x": 1212.220130988712, - "y": 526.8130243230098 - }, - "type": "customNode", - "data": { - "id": "pineconeUpsert_0", - "label": "Pinecone Upsert Document", - "name": "pineconeUpsert", - "type": "Pinecone", - "baseClasses": ["BaseRetriever"], - "category": "Vector Stores", - "description": "Upsert documents to Pinecone", - "inputParams": [ - { - "label": "Pinecone Api Key", - "name": "pineconeApiKey", - "type": "password" - }, - { - "label": "Pinecone Environment", - "name": "pineconeEnv", - "type": "string" - }, - { - "label": "Pinecone Index", - "name": "pineconeIndex", - "type": "string" - } - ], - "inputAnchors": [ - { - "label": "Document", - "name": "document", - "type": "Document", - "id": "pineconeUpsert_0-input-document-Document" - }, - { - "label": "Embeddings", - "name": "embeddings", - "type": "Embeddings", - "id": "pineconeUpsert_0-input-embeddings-Embeddings" - } - ], - "inputs": { - "document": "{{textFile_0.data.instance}}", - "embeddings": "{{openAIEmbeddings_0.data.instance}}", - "pineconeEnv": "us-west4-gcp", - "pineconeIndex": "test" - }, - "outputAnchors": [ - { - "id": "pineconeUpsert_0-output-pineconeUpsert-BaseRetriever", - "name": "pineconeUpsert", - "label": "Pinecone", - "type": "BaseRetriever" - } - ], - "selected": false - }, - "selected": false, - "positionAbsolute": { - "x": 1212.220130988712, - "y": 526.8130243230098 - }, - "dragging": false - }, { "width": 300, "height": 280, @@ -353,6 +282,97 @@ "y": 410.3973881655837 }, "dragging": false + }, + { + "width": 300, + "height": 603, + "id": "pineconeUpsert_0", + "position": { + "x": 1207.9646568749058, + "y": 531.8684248168081 + }, + "type": "customNode", + "data": { + "id": "pineconeUpsert_0", + "label": "Pinecone Upsert Document", + "name": "pineconeUpsert", + "type": "Pinecone", + "baseClasses": ["Pinecone", "BaseRetriever"], + "category": "Vector Stores", + "description": "Upsert documents to Pinecone", + "inputParams": [ + { + "label": "Pinecone Api Key", + "name": "pineconeApiKey", + "type": "password", + "id": "pineconeUpsert_0-input-pineconeApiKey-password" + }, + { + "label": "Pinecone Environment", + "name": "pineconeEnv", + "type": "string", + "id": "pineconeUpsert_0-input-pineconeEnv-string" + }, + { + "label": "Pinecone Index", + "name": "pineconeIndex", + "type": "string", + "id": "pineconeUpsert_0-input-pineconeIndex-string" + } + ], + "inputAnchors": [ + { + "label": "Document", + "name": "document", + "type": "Document", + "id": "pineconeUpsert_0-input-document-Document" + }, + { + "label": "Embeddings", + "name": "embeddings", + "type": "Embeddings", + "id": "pineconeUpsert_0-input-embeddings-Embeddings" + } + ], + "inputs": { + "document": "{{textFile_0.data.instance}}", + "embeddings": "{{openAIEmbeddings_0.data.instance}}", + "pineconeEnv": "us-west4-gcp", + "pineconeIndex": "test" + }, + "outputAnchors": [ + { + "name": "output", + "label": "Output", + "type": "options", + "options": [ + { + "id": "pineconeUpsert_0-output-retriever-Pinecone|BaseRetriever", + "name": "retriever", + "label": "Pinecone Retriever", + "type": "Pinecone | BaseRetriever" + }, + { + "id": "pineconeUpsert_0-output-vectorStore-Pinecone|VectorStore", + "name": "vectorStore", + "label": "Pinecone Vector Store", + "type": "Pinecone | VectorStore" + } + ], + "default": "retriever" + } + ], + "outputs": { + "output": "retriever" + }, + "selected": false + }, + "selected": false, + "positionAbsolute": { + "x": 1207.9646568749058, + "y": 531.8684248168081 + }, + "dragging": false } ], "edges": [ @@ -367,6 +387,28 @@ "label": "" } }, + { + "source": "openAI_0", + "sourceHandle": "openAI_0-output-openAI-OpenAI|BaseLLM|BaseLanguageModel", + "target": "conversationalRetrievalQAChain_0", + "targetHandle": "conversationalRetrievalQAChain_0-input-llm-BaseLLM", + "type": "buttonedge", + "id": "openAI_0-openAI_0-output-openAI-OpenAI|BaseLLM|BaseLanguageModel-conversationalRetrievalQAChain_0-conversationalRetrievalQAChain_0-input-llm-BaseLLM", + "data": { + "label": "" + } + }, + { + "source": "pineconeUpsert_0", + "sourceHandle": "pineconeUpsert_0-output-retriever-Pinecone|BaseRetriever", + "target": "conversationalRetrievalQAChain_0", + "targetHandle": "conversationalRetrievalQAChain_0-input-vectorStoreRetriever-BaseRetriever", + "type": "buttonedge", + "id": "pineconeUpsert_0-pineconeUpsert_0-output-retriever-Pinecone|BaseRetriever-conversationalRetrievalQAChain_0-conversationalRetrievalQAChain_0-input-vectorStoreRetriever-BaseRetriever", + "data": { + "label": "" + } + }, { "source": "textFile_0", "sourceHandle": "textFile_0-output-textFile-Document", @@ -388,28 +430,6 @@ "data": { "label": "" } - }, - { - "source": "openAI_0", - "sourceHandle": "openAI_0-output-openAI-OpenAI|BaseLLM|BaseLanguageModel", - "target": "conversationalRetrievalQAChain_0", - "targetHandle": "conversationalRetrievalQAChain_0-input-llm-BaseLLM", - "type": "buttonedge", - "id": "openAI_0-openAI_0-output-openAI-OpenAI|BaseLLM|BaseLanguageModel-conversationalRetrievalQAChain_0-conversationalRetrievalQAChain_0-input-llm-BaseLLM", - "data": { - "label": "" - } - }, - { - "source": "pineconeUpsert_0", - "sourceHandle": "pineconeUpsert_0-output-pineconeUpsert-BaseRetriever", - "target": "conversationalRetrievalQAChain_0", - "targetHandle": "conversationalRetrievalQAChain_0-input-vectorStoreRetriever-BaseRetriever", - "type": "buttonedge", - "id": "pineconeUpsert_0-pineconeUpsert_0-output-pineconeUpsert-BaseRetriever-conversationalRetrievalQAChain_0-conversationalRetrievalQAChain_0-input-vectorStoreRetriever-BaseRetriever", - "data": { - "label": "" - } } ] } diff --git a/packages/server/marketplaces/Github Repo QnA.json b/packages/server/marketplaces/Github Repo QnA.json index 124a1f9f..33914928 100644 --- a/packages/server/marketplaces/Github Repo QnA.json +++ b/packages/server/marketplaces/Github Repo QnA.json @@ -245,77 +245,6 @@ }, "dragging": false }, - { - "width": 300, - "height": 577, - "id": "pineconeUpsert_0", - "position": { - "x": 1265.1304547629002, - "y": 376.13121569675315 - }, - "type": "customNode", - "data": { - "id": "pineconeUpsert_0", - "label": "Pinecone Upsert Document", - "name": "pineconeUpsert", - "type": "Pinecone", - "baseClasses": ["BaseRetriever"], - "category": "Vector Stores", - "description": "Upsert documents to Pinecone", - "inputParams": [ - { - "label": "Pinecone Api Key", - "name": "pineconeApiKey", - "type": "password" - }, - { - "label": "Pinecone Environment", - "name": "pineconeEnv", - "type": "string" - }, - { - "label": "Pinecone Index", - "name": "pineconeIndex", - "type": "string" - } - ], - "inputAnchors": [ - { - "label": "Document", - "name": "document", - "type": "Document", - "id": "pineconeUpsert_0-input-document-Document" - }, - { - "label": "Embeddings", - "name": "embeddings", - "type": "Embeddings", - "id": "pineconeUpsert_0-input-embeddings-Embeddings" - } - ], - "inputs": { - "document": "{{github_0.data.instance}}", - "embeddings": "{{openAIEmbeddings_0.data.instance}}", - "pineconeEnv": "us-west4-gcp", - "pineconeIndex": "test" - }, - "outputAnchors": [ - { - "id": "pineconeUpsert_0-output-pineconeUpsert-BaseRetriever", - "name": "pineconeUpsert", - "label": "Pinecone", - "type": "BaseRetriever" - } - ], - "selected": false - }, - "selected": false, - "positionAbsolute": { - "x": 1265.1304547629002, - "y": 376.13121569675315 - }, - "dragging": false - }, { "width": 300, "height": 280, @@ -368,6 +297,97 @@ "y": 197.0636463189023 }, "dragging": false + }, + { + "width": 300, + "height": 603, + "id": "pineconeUpsert_0", + "position": { + "x": 1275.7940479898277, + "y": 379.2784546164221 + }, + "type": "customNode", + "data": { + "id": "pineconeUpsert_0", + "label": "Pinecone Upsert Document", + "name": "pineconeUpsert", + "type": "Pinecone", + "baseClasses": ["Pinecone", "BaseRetriever"], + "category": "Vector Stores", + "description": "Upsert documents to Pinecone", + "inputParams": [ + { + "label": "Pinecone Api Key", + "name": "pineconeApiKey", + "type": "password", + "id": "pineconeUpsert_0-input-pineconeApiKey-password" + }, + { + "label": "Pinecone Environment", + "name": "pineconeEnv", + "type": "string", + "id": "pineconeUpsert_0-input-pineconeEnv-string" + }, + { + "label": "Pinecone Index", + "name": "pineconeIndex", + "type": "string", + "id": "pineconeUpsert_0-input-pineconeIndex-string" + } + ], + "inputAnchors": [ + { + "label": "Document", + "name": "document", + "type": "Document", + "id": "pineconeUpsert_0-input-document-Document" + }, + { + "label": "Embeddings", + "name": "embeddings", + "type": "Embeddings", + "id": "pineconeUpsert_0-input-embeddings-Embeddings" + } + ], + "inputs": { + "document": "{{github_0.data.instance}}", + "embeddings": "{{openAIEmbeddings_0.data.instance}}", + "pineconeEnv": "us-west4-gcp", + "pineconeIndex": "test" + }, + "outputAnchors": [ + { + "name": "output", + "label": "Output", + "type": "options", + "options": [ + { + "id": "pineconeUpsert_0-output-retriever-Pinecone|BaseRetriever", + "name": "retriever", + "label": "Pinecone Retriever", + "type": "Pinecone | BaseRetriever" + }, + { + "id": "pineconeUpsert_0-output-vectorStore-Pinecone|VectorStore", + "name": "vectorStore", + "label": "Pinecone Vector Store", + "type": "Pinecone | VectorStore" + } + ], + "default": "retriever" + } + ], + "outputs": { + "output": "retriever" + }, + "selected": false + }, + "selected": false, + "positionAbsolute": { + "x": 1275.7940479898277, + "y": 379.2784546164221 + }, + "dragging": false } ], "edges": [ @@ -383,12 +403,12 @@ } }, { - "source": "pineconeUpsert_0", - "sourceHandle": "pineconeUpsert_0-output-pineconeUpsert-BaseRetriever", - "target": "conversationalRetrievalQAChain_0", - "targetHandle": "conversationalRetrievalQAChain_0-input-vectorStoreRetriever-BaseRetriever", + "source": "recursiveCharacterTextSplitter_0", + "sourceHandle": "recursiveCharacterTextSplitter_0-output-recursiveCharacterTextSplitter-RecursiveCharacterTextSplitter|TextSplitter", + "target": "github_0", + "targetHandle": "github_0-input-textSplitter-TextSplitter", "type": "buttonedge", - "id": "pineconeUpsert_0-pineconeUpsert_0-output-pineconeUpsert-BaseRetriever-conversationalRetrievalQAChain_0-conversationalRetrievalQAChain_0-input-vectorStoreRetriever-BaseRetriever", + "id": "recursiveCharacterTextSplitter_0-recursiveCharacterTextSplitter_0-output-recursiveCharacterTextSplitter-RecursiveCharacterTextSplitter|TextSplitter-github_0-github_0-input-textSplitter-TextSplitter", "data": { "label": "" } @@ -416,12 +436,12 @@ } }, { - "source": "recursiveCharacterTextSplitter_0", - "sourceHandle": "recursiveCharacterTextSplitter_0-output-recursiveCharacterTextSplitter-RecursiveCharacterTextSplitter|TextSplitter", - "target": "github_0", - "targetHandle": "github_0-input-textSplitter-TextSplitter", + "source": "pineconeUpsert_0", + "sourceHandle": "pineconeUpsert_0-output-retriever-Pinecone|BaseRetriever", + "target": "conversationalRetrievalQAChain_0", + "targetHandle": "conversationalRetrievalQAChain_0-input-vectorStoreRetriever-BaseRetriever", "type": "buttonedge", - "id": "recursiveCharacterTextSplitter_0-recursiveCharacterTextSplitter_0-output-recursiveCharacterTextSplitter-RecursiveCharacterTextSplitter|TextSplitter-github_0-github_0-input-textSplitter-TextSplitter", + "id": "pineconeUpsert_0-pineconeUpsert_0-output-retriever-Pinecone|BaseRetriever-conversationalRetrievalQAChain_0-conversationalRetrievalQAChain_0-input-vectorStoreRetriever-BaseRetriever", "data": { "label": "" }