aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/views/nodes/chatbot/agentsystem/Agent.ts7
-rw-r--r--src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx32
-rw-r--r--src/client/views/nodes/chatbot/tools/BaseTool.ts4
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts59
-rw-r--r--src/client/views/nodes/chatbot/tools/SearchTool.ts3
-rw-r--r--src/client/views/nodes/chatbot/tools/ToolTypes.ts30
-rw-r--r--src/client/views/nodes/chatbot/tools/WikipediaTool.ts2
7 files changed, 90 insertions, 47 deletions
diff --git a/src/client/views/nodes/chatbot/agentsystem/Agent.ts b/src/client/views/nodes/chatbot/agentsystem/Agent.ts
index 34e7cf5ea..df307bc21 100644
--- a/src/client/views/nodes/chatbot/agentsystem/Agent.ts
+++ b/src/client/views/nodes/chatbot/agentsystem/Agent.ts
@@ -15,7 +15,8 @@ import { AgentMessage, AssistantMessage, Observation, PROCESSING_TYPE, Processin
import { Vectorstore } from '../vectorstore/Vectorstore';
import { getReactPrompt } from './prompts';
import { BaseTool } from '../tools/BaseTool';
-import { Parameter, ParametersType, Tool } from '../tools/ToolTypes';
+import { Parameter, ParametersType } from '../tools/ToolTypes';
+import { CreateTextDocTool } from '../tools/CreateTextDocumentTool';
dotenv.config();
@@ -54,6 +55,7 @@ export class Agent {
history: () => string,
csvData: () => { filename: string; id: string; text: string }[],
addLinkedUrlDoc: (url: string, id: string) => void,
+ addLinkedTextDoc: (text_content: string, options: {}, id: string) => void,
createCSVInDash: (url: string, title: string, id: string, data: string) => void
) {
// Initialize OpenAI client with API key from environment
@@ -71,7 +73,8 @@ export class Agent {
websiteInfoScraper: new WebsiteInfoScraperTool(addLinkedUrlDoc),
searchTool: new SearchTool(addLinkedUrlDoc),
createCSV: new CreateCSVTool(createCSVInDash),
- no_tool: new NoTool(),
+ noTool: new NoTool(),
+ createTextDoc: new CreateTextDocTool(addLinkedTextDoc),
};
}
diff --git a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
index 44c231c87..118d20153 100644
--- a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
+++ b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
@@ -20,7 +20,7 @@ import { CsvCast, DocCast, PDFCast, RTFCast, StrCast } from '../../../../../fiel
import { Networking } from '../../../../Network';
import { DocUtils } from '../../../../documents/DocUtils';
import { DocumentType } from '../../../../documents/DocumentTypes';
-import { Docs } from '../../../../documents/Documents';
+import { Docs, DocumentOptions } from '../../../../documents/Documents';
import { DocumentManager } from '../../../../util/DocumentManager';
import { LinkManager } from '../../../../util/LinkManager';
import { ViewBoxAnnotatableComponent } from '../../../DocComponent';
@@ -89,7 +89,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
this.vectorstore_id = StrCast(this.dataDoc.vectorstore_id);
}
this.vectorstore = new Vectorstore(this.vectorstore_id, this.retrieveDocIds);
- this.agent = new Agent(this.vectorstore, this.retrieveSummaries, this.retrieveFormattedHistory, this.retrieveCSVData, this.addLinkedUrlDoc, this.createCSVInDash);
+ this.agent = new Agent(this.vectorstore, this.retrieveSummaries, this.retrieveFormattedHistory, this.retrieveCSVData, this.addLinkedUrlDoc, this.createTextDocInDash, this.createCSVInDash);
this.messagesRef = React.createRef<HTMLDivElement>();
// Reaction to update dataDoc when chat history changes
@@ -411,6 +411,23 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
};
/**
+ * Creates a text document in the dashboard and adds it for analysis.
+ * @param title The title of the doc.
+ * @param text_content The text of the document.
+ * @param options Other optional document options (e.g. color)
+ * @param id The unique ID for the document.
+ */
+ @action
+ createTextDocInDash = async (text_content: string, options: DocumentOptions, id: string) => {
+ const doc = DocCast(Docs.Create.TextDocument(text_content, options));
+ const linkDoc = Docs.Create.LinkDocument(this.Document, doc);
+ LinkManager.Instance.addLink(linkDoc);
+
+ doc && this._props.addDocument?.(doc);
+ await DocumentManager.Instance.showDocument(doc, { willZoomCentered: true }, () => {});
+ };
+
+ /**
* Event handler to manage citations click in the message components.
* @param citation The citation object clicked by the user.
*/
@@ -709,17 +726,10 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
</div>
<div className="chat-messages" ref={this.messagesRef}>
{this.history.map((message, index) => (
- <MessageComponentBox key={index} message={message} index={index} onFollowUpClick={this.handleFollowUpClick} onCitationClick={this.handleCitationClick} updateMessageCitations={this.updateMessageCitations} />
+ <MessageComponentBox key={index} message={message} onFollowUpClick={this.handleFollowUpClick} onCitationClick={this.handleCitationClick} updateMessageCitations={this.updateMessageCitations} />
))}
{this.current_message && (
- <MessageComponentBox
- key={this.history.length}
- message={this.current_message}
- index={this.history.length}
- onFollowUpClick={this.handleFollowUpClick}
- onCitationClick={this.handleCitationClick}
- updateMessageCitations={this.updateMessageCitations}
- />
+ <MessageComponentBox key={this.history.length} message={this.current_message} onFollowUpClick={this.handleFollowUpClick} onCitationClick={this.handleCitationClick} updateMessageCitations={this.updateMessageCitations} />
)}
</div>
<form onSubmit={this.askGPT} className="chat-input">
diff --git a/src/client/views/nodes/chatbot/tools/BaseTool.ts b/src/client/views/nodes/chatbot/tools/BaseTool.ts
index 58cd514d9..b6091af6c 100644
--- a/src/client/views/nodes/chatbot/tools/BaseTool.ts
+++ b/src/client/views/nodes/chatbot/tools/BaseTool.ts
@@ -1,5 +1,5 @@
import { Observation } from '../types/types';
-import { Parameter, Tool, ParametersType } from './ToolTypes';
+import { Parameter, ParametersType } from './ToolTypes';
/**
* @file BaseTool.ts
@@ -14,7 +14,7 @@ import { Parameter, Tool, ParametersType } from './ToolTypes';
* It is generic over a type parameter `P`, which extends `ReadonlyArray<Parameter>`.
* This means `P` is a readonly array of `Parameter` objects that cannot be modified (immutable).
*/
-export abstract class BaseTool<P extends ReadonlyArray<Parameter>> implements Tool<P> {
+export abstract class BaseTool<P extends ReadonlyArray<Parameter>> {
// The name of the tool (e.g., "calculate", "searchTool")
name: string;
// A description of the tool's functionality
diff --git a/src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts b/src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts
new file mode 100644
index 000000000..fa978bdc3
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts
@@ -0,0 +1,59 @@
+import { v4 as uuidv4 } from 'uuid';
+import { Networking } from '../../../../Network';
+import { BaseTool } from './BaseTool';
+import { Observation } from '../types/types';
+import { ParametersType } from './ToolTypes';
+import { DocumentOptions } from '../../../../documents/Documents';
+
+const createTextDocToolParams = [
+ {
+ name: 'text_content',
+ type: 'string',
+ description: 'The text content that the document will display',
+ required: true,
+ },
+ {
+ name: 'title',
+ type: 'string',
+ description: 'The title of the document',
+ required: true,
+ },
+ {
+ name: 'background_color',
+ type: 'string',
+ description: 'The background color of the document as a hex string',
+ required: false,
+ },
+ {
+ name: 'font_color',
+ type: 'string',
+ description: 'The font color of the document as a hex string',
+ required: false,
+ },
+] as const;
+
+type CreateTextDocToolParamsType = typeof createTextDocToolParams;
+
+export class CreateTextDocTool extends BaseTool<CreateTextDocToolParamsType> {
+ private _addLinkedTextDoc: (text_content: string, options: DocumentOptions, id: string) => void;
+
+ constructor(addLinkedTextDoc: (text_content: string, options: DocumentOptions, id: string) => void) {
+ super(
+ 'createTextDoc',
+ 'Creates a text document with the provided content and title (and of specified other options if wanted)',
+ createTextDocToolParams,
+ 'Provide the text content and title (and optionally color) for the document.',
+ 'Creates a text document with the provided content and title (and of specified other options if wanted). Use if the user wants to create a textbox or text document of some sort. Can use after a search or other tool to save information.'
+ );
+ this._addLinkedTextDoc = addLinkedTextDoc;
+ }
+
+ async execute(args: ParametersType<CreateTextDocToolParamsType>): Promise<Observation[]> {
+ try {
+ this._addLinkedTextDoc(args.text_content, { title: args.title, backgroundColor: args.background_color, text_fontColor: args.font_color }, uuidv4());
+ return [{ type: 'text', text: 'Created text document.' }];
+ } catch (error) {
+ return [{ type: 'text', text: 'Error creating text document, ' + error }];
+ }
+ }
+}
diff --git a/src/client/views/nodes/chatbot/tools/SearchTool.ts b/src/client/views/nodes/chatbot/tools/SearchTool.ts
index fd5144dd6..267dab6ff 100644
--- a/src/client/views/nodes/chatbot/tools/SearchTool.ts
+++ b/src/client/views/nodes/chatbot/tools/SearchTool.ts
@@ -44,9 +44,10 @@ export class SearchTool extends BaseTool<SearchToolParamsType> {
});
const data = results.map((result: { url: string; snippet: string }) => {
const id = uuidv4();
+ this._addLinkedUrlDoc(result.url, id);
return {
type: 'text',
- text: `<chunk chunk_id="${id}" chunk_type="text"><url>${result.url}</url><overview>${result.snippet}</overview></chunk>`,
+ text: `<chunk chunk_id="${id}" chunk_type="url"><url>${result.url}</url><overview>${result.snippet}</overview></chunk>`,
};
});
return data;
diff --git a/src/client/views/nodes/chatbot/tools/ToolTypes.ts b/src/client/views/nodes/chatbot/tools/ToolTypes.ts
index d47a38952..cc29d70f1 100644
--- a/src/client/views/nodes/chatbot/tools/ToolTypes.ts
+++ b/src/client/views/nodes/chatbot/tools/ToolTypes.ts
@@ -1,34 +1,4 @@
import { Observation } from '../types/types';
-
-/**
- * The `Tool` interface represents a generic tool in the system.
- * It is generic over a type parameter `P`, which extends `ReadonlyArray<Parameter>`.
- * @template P - An array of `Parameter` objects defining the tool's parameters.
- */
-export interface Tool<P extends ReadonlyArray<Parameter>> {
- // The name of the tool (e.g., "calculate", "searchTool")
- name: string;
- // A description of the tool's functionality
- description: string;
- // An array of parameter definitions for the tool
- parameterRules: P;
- // Guidelines for how to handle citations when using the tool
- citationRules: string;
- // A brief summary of the tool's purpose
- briefSummary: string;
- /**
- * Executes the tool's main functionality.
- * @param args - The arguments for execution, with types inferred from `ParametersType<P>`.
- * @returns A promise that resolves to an array of `Observation` objects.
- */
- execute: (args: ParametersType<P>) => Promise<Observation[]>;
- /**
- * Generates an action rule object that describes the tool's usage.
- * @returns An object representing the tool's action rules.
- */
- getActionRule: () => Record<string, unknown>;
-}
-
/**
* The `Parameter` type defines the structure of a parameter configuration.
*/
diff --git a/src/client/views/nodes/chatbot/tools/WikipediaTool.ts b/src/client/views/nodes/chatbot/tools/WikipediaTool.ts
index 4fcffe2ed..966ca7708 100644
--- a/src/client/views/nodes/chatbot/tools/WikipediaTool.ts
+++ b/src/client/views/nodes/chatbot/tools/WikipediaTool.ts
@@ -38,7 +38,7 @@ export class WikipediaTool extends BaseTool<WikipediaToolParamsType> {
return [
{
type: 'text',
- text: `<chunk chunk_id="${id}" chunk_type="text"> ${text} </chunk>`,
+ text: `<chunk chunk_id="${id}" chunk_type="url"> ${text} </chunk>`,
},
];
} catch (error) {