diff options
author | A.J. Shulman <Shulman.aj@gmail.com> | 2024-08-07 13:08:41 -0400 |
---|---|---|
committer | A.J. Shulman <Shulman.aj@gmail.com> | 2024-08-07 13:08:41 -0400 |
commit | b7c024c8c5b85f91828d6cd20ffc3bfca229af21 (patch) | |
tree | 74536498c0301dbbc53b67f2eaac5fd40a7fa3d9 /src | |
parent | a4107cdf6d53654275a678a79eff9962bcd02beb (diff) |
trying to get rules to delete after using rool
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/nodes/ChatBox/Agent.ts | 3 | ||||
-rw-r--r-- | src/client/views/nodes/ChatBox/ChatBox.tsx | 1 | ||||
-rw-r--r-- | src/client/views/nodes/ChatBox/prompts.ts | 4 | ||||
-rw-r--r-- | src/client/views/nodes/ChatBox/tools/BaseTool.ts | 17 | ||||
-rw-r--r-- | src/client/views/nodes/ChatBox/types.ts | 2 | ||||
-rw-r--r-- | src/client/views/nodes/ChatBox/vectorstore/VectorstoreUpload.ts | 18 |
6 files changed, 27 insertions, 18 deletions
diff --git a/src/client/views/nodes/ChatBox/Agent.ts b/src/client/views/nodes/ChatBox/Agent.ts index fddfdfcb1..04729414a 100644 --- a/src/client/views/nodes/ChatBox/Agent.ts +++ b/src/client/views/nodes/ChatBox/Agent.ts @@ -22,6 +22,7 @@ export class Agent { private _summaries: () => string; constructor(_vectorstore: Vectorstore, summaries: () => string, history: () => string) { + console.log(process.env.OPENAI_KEY); this.client = new OpenAI({ apiKey: process.env.OPENAI_KEY, dangerouslyAllowBrowser: true }); this.vectorstore = _vectorstore; this._history = history; @@ -77,7 +78,7 @@ export class Agent { const nextPrompt = [ { type: 'text', - text: `<step${i} role="user">` + builder.build({ action_rules: this.tools[currentAction].getActionRule() }) + `<\step>`, + text: `<step${i} role="user">` + builder.build({ action_rules: this.tools[currentAction].getActionRule(true) }) + `<\step>`, }, ]; this.interMessages.push({ role: 'user', content: nextPrompt }); diff --git a/src/client/views/nodes/ChatBox/ChatBox.tsx b/src/client/views/nodes/ChatBox/ChatBox.tsx index 6269b8768..3de5c1da3 100644 --- a/src/client/views/nodes/ChatBox/ChatBox.tsx +++ b/src/client/views/nodes/ChatBox/ChatBox.tsx @@ -76,6 +76,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { }; initializeOpenAI() { + console.log(process.env.OPENAI_KEY); const configuration: ClientOptions = { apiKey: process.env.OPENAI_KEY, dangerouslyAllowBrowser: true, diff --git a/src/client/views/nodes/ChatBox/prompts.ts b/src/client/views/nodes/ChatBox/prompts.ts index b2883f71a..d520a7b7d 100644 --- a/src/client/views/nodes/ChatBox/prompts.ts +++ b/src/client/views/nodes/ChatBox/prompts.ts @@ -34,7 +34,7 @@ export function getReactPrompt(tools: Tool[], summaries: () => string, chatHisto e. !!!Use the retrieval (RAG) tool ANYTIME the question may potentially (even if you are not sure) relate to one of the user's documents. Here are the summaries of the user's documents: ${summaries()} f. Based on observations or your knowledge, formulate your answer. - g. Provide the final answer in the <answer> tag, including follow-up questions. + g. Provide the final answer in the <answer> tag, including user-perspective follow-up questions. 4. Available Tools: ${toolDescriptions} @@ -52,7 +52,7 @@ export function getReactPrompt(tools: Tool[], summaries: () => string, chatHisto 6. Answer Format: Your final <answer> tag must contain: - The complete answer to the user's query. - - An array of EXACTLY 3 follow-up questions within <follow_up_questions> tags. + - An array of EXACTLY 3 follow-up questions (WRITTEN IN THE PERSPECTIVE OF THE USER ASKING A FOLLOW-UP QUESTION) within <follow_up_questions> tags. 7. Example Interaction (YOU ONLY OUTPUT THE ASSISTANT STEPS): SYSTEM: diff --git a/src/client/views/nodes/ChatBox/tools/BaseTool.ts b/src/client/views/nodes/ChatBox/tools/BaseTool.ts index 903161bd5..c7942e359 100644 --- a/src/client/views/nodes/ChatBox/tools/BaseTool.ts +++ b/src/client/views/nodes/ChatBox/tools/BaseTool.ts @@ -11,13 +11,20 @@ export abstract class BaseTool<T extends Record<string, any> = Record<string, an abstract execute(args: T): Promise<any>; - getActionRule(): Record<string, any> { + getActionRule(isCurrentTool: boolean): Record<string, any> { + if (isCurrentTool) { + return { + [this.name]: { + name: this.name, + useRules: this.useRules, + description: this.description, + parameters: this.parameters, + }, + }; + } return { [this.name]: { - name: this.name, - useRules: this.useRules, - description: this.description, - parameters: this.parameters, + description: 'This tool is not currently selected.', }, }; } diff --git a/src/client/views/nodes/ChatBox/types.ts b/src/client/views/nodes/ChatBox/types.ts index c2fb095f0..bc3585a5b 100644 --- a/src/client/views/nodes/ChatBox/types.ts +++ b/src/client/views/nodes/ChatBox/types.ts @@ -85,7 +85,7 @@ export interface Tool<T extends Record<string, any> = Record<string, any>> { useRules: string; briefSummary: string; execute: (args: T) => Promise<any>; - getActionRule: () => Record<string, any>; + getActionRule: (isCurrentTool: boolean) => Record<string, any>; } export interface AgentMessage { diff --git a/src/client/views/nodes/ChatBox/vectorstore/VectorstoreUpload.ts b/src/client/views/nodes/ChatBox/vectorstore/VectorstoreUpload.ts index 0737e2392..787705bb6 100644 --- a/src/client/views/nodes/ChatBox/vectorstore/VectorstoreUpload.ts +++ b/src/client/views/nodes/ChatBox/vectorstore/VectorstoreUpload.ts @@ -16,8 +16,8 @@ export class Vectorstore { private index!: Index; private cohere: CohereClient; private indexName: string = 'pdf-chatbot'; - private id: string; - private file_ids: string[] = []; + private _id: string; + private _doc_ids: string[] = []; documents: AI_Document[] = []; constructor(id: string, doc_ids: () => string[]) { @@ -32,8 +32,8 @@ export class Vectorstore { this.cohere = new CohereClient({ token: process.env.COHERE_API_KEY, }); - this.id = id; - this.file_ids = doc_ids(); + this._id = id; + this._doc_ids = doc_ids(); this.initializeIndex(); } @@ -65,7 +65,7 @@ export class Vectorstore { console.log('Already in progress.'); return; } - if (!this.file_ids.includes(StrCast(doc.ai_doc_id))) this.file_ids.push(StrCast(doc.ai_doc_id)); + if (!this._doc_ids.includes(StrCast(doc.ai_doc_id))) this._doc_ids.push(StrCast(doc.ai_doc_id)); } else { doc.ai_document_status = 'PROGRESS'; console.log(doc); @@ -82,12 +82,12 @@ export class Vectorstore { console.log(`Document added: ${document_json.file_name}`); doc.summary = document_json.summary; doc.ai_doc_id = document_json.doc_id; - this.file_ids.push(document_json.doc_id); + this._doc_ids.push(document_json.doc_id); doc.ai_purpose = document_json.purpose; if (doc.vectorstore_id === undefined || doc.vectorstore_id === null || doc.vectorstore_id === '' || doc.vectorstore_id === '[]') { - doc.vectorstore_id = JSON.stringify([this.id]); + doc.vectorstore_id = JSON.stringify([this._id]); } else { - doc.vectorstore_id = JSON.stringify(JSON.parse(StrCast(doc.vectorstore_id)).concat([this.id])); + doc.vectorstore_id = JSON.stringify(JSON.parse(StrCast(doc.vectorstore_id)).concat([this._id])); } if (doc.chunk_simpl === undefined || doc.chunk_simpl === null || doc.chunk_simpl === '' || doc.chunk_simpl === '[]') { doc.chunk_simpl = JSON.stringify({ text_chunks: [], image_chunks: [] }); @@ -161,7 +161,7 @@ export class Vectorstore { const queryResponse: QueryResponse<RecordMetadata> = await this.index.query({ vector: queryEmbedding, filter: { - doc_id: { $in: this.file_ids }, + doc_id: { $in: this._doc_ids }, }, topK, includeValues: true, |