1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
import { parsedDoc } from '../chatboxcomponents/ChatBox';
import { ParametersType, ToolInfo } from '../types/tool_types';
import { Observation } from '../types/types';
import { BaseTool } from './BaseTool';
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;
const createTextDocToolInfo: ToolInfo<CreateTextDocToolParamsType> = {
name: 'createTextDoc',
description: 'Creates a text document with the provided content and title. 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.',
citationRules: 'No citation needed.',
parameterRules: createTextDocToolParams,
};
export class CreateTextDocTool extends BaseTool<CreateTextDocToolParamsType> {
private _addLinkedDoc: (doc: parsedDoc) => void;
constructor(addLinkedDoc: (doc: parsedDoc) => void) {
super(createTextDocToolInfo);
this._addLinkedDoc = addLinkedDoc;
}
async execute(args: ParametersType<CreateTextDocToolParamsType>): Promise<Observation[]> {
try {
this._addLinkedDoc({ doc_type: 'text', data: args.text_content, title: args.title });
return [{ type: 'text', text: 'Created text document.' }];
} catch (error) {
return [{ type: 'text', text: 'Error creating text document, ' + error }];
}
}
}
|