Skip to content

Commit 095f411

Browse files
authored
feat: add agent support to ai:ask command (#589)
1 parent effb494 commit 095f411

File tree

8 files changed

+233
-144
lines changed

8 files changed

+233
-144
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"@oclif/plugin-version": "^2.2.16",
3131
"archiver": "^3.0.0",
3232
"box-node-sdk": "^3.7.0",
33-
"box-typescript-sdk-gen": "^1.15.1",
33+
"box-typescript-sdk-gen": "^1.17.1",
3434
"chalk": "^2.4.1",
3535
"cli-progress": "^2.1.0",
3636
"csv": "^6.3.3",

src/commands/ai/ask.js

Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,59 +8,74 @@ class AiAskCommand extends BoxCommand {
88
async run() {
99
const { flags } = await this.parse(AiAskCommand);
1010
let options = {};
11-
options.mode = flags.items.length > 1 ? 'multi_item_qa' : 'single_item_qa';
11+
options.mode = flags.items.length > 1 ? 'multi_item_qa' : 'single_item_qa';
1212

13-
if (flags.prompt) {
14-
options.prompt = flags.prompt;
15-
}
16-
if (flags.items) {
17-
options.items = flags.items;
18-
}
13+
if (flags.prompt) {
14+
options.prompt = flags.prompt;
15+
}
16+
if (flags.items) {
17+
options.items = flags.items;
18+
}
19+
if (flags['ai-agent']) {
20+
options.aiAgent = flags['ai-agent'];
21+
}
1922

20-
let answer = await this.client.ai.ask({
21-
prompt: options.prompt,
22-
items: options.items,
23-
mode: options.mode
24-
});
25-
await this.output(answer);
23+
let answer = await this.tsClient.ai.createAiAsk(options);
24+
delete answer.rawData;
25+
await this.output(answer);
2626
}
2727
}
2828

29-
AiAskCommand.description = 'Sends an AI request to supported LLMs and returns an answer';
30-
AiAskCommand.examples = ['box ai:ask --items=id=12345,type=file --prompt "What is the status of this document?"'];
29+
AiAskCommand.description =
30+
'Sends an AI request to supported LLMs and returns an answer';
31+
AiAskCommand.examples = [
32+
'box ai:ask --items=id=12345,type=file --prompt "What is the status of this document?"',
33+
];
3134
AiAskCommand._endpoint = 'post_ai_ask';
3235

3336
AiAskCommand.flags = {
3437
...BoxCommand.flags,
35-
prompt: Flags.string({
36-
required: true,
37-
description: 'The prompt for the AI request',
38-
}),
39-
items: Flags.string({
40-
required: true,
41-
description: 'The items for the AI request',
42-
multiple: true,
43-
parse(input) {
44-
const item = {
45-
id: '',
46-
type: 'file'
47-
};
48-
const obj = utils.parseStringToObject(input, ['id', 'type', 'content']);
49-
for (const key in obj) {
50-
if (key === 'id') {
51-
item.id = obj[key];
52-
} else if (key === 'type') {
53-
item.type = obj[key];
54-
} else if (key === 'content') {
55-
item.content = obj[key];
56-
} else {
57-
throw new Error(`Invalid item key ${key}`);
58-
}
59-
}
38+
prompt: Flags.string({
39+
required: true,
40+
description: 'The prompt for the AI request',
41+
}),
42+
items: Flags.string({
43+
required: true,
44+
description: 'The items for the AI request',
45+
multiple: true,
46+
parse(input) {
47+
const item = {
48+
id: '',
49+
type: 'file',
50+
};
51+
const obj = utils.parseStringToObject(input, ['id', 'type', 'content']);
52+
for (const key in obj) {
53+
if (key === 'id') {
54+
item.id = obj[key];
55+
} else if (key === 'type') {
56+
item.type = obj[key];
57+
} else if (key === 'content') {
58+
item.content = obj[key];
59+
} else {
60+
throw new Error(`Invalid item key ${key}`);
61+
}
62+
}
6063

61-
return item;
62-
}
63-
}),
64+
return item;
65+
},
66+
}),
67+
'ai-agent': Flags.string({
68+
required: false,
69+
description:
70+
'The AI agent to be used for the ask, provided as a JSON string. Example: {"type": "ai_agent_ask", "basicText": {"model": "openai__gpt_3_5_turbo"}}',
71+
parse(input) {
72+
try {
73+
return JSON.parse(input);
74+
} catch (error) {
75+
throw ('Error parsing AI agent ', error);
76+
}
77+
},
78+
}),
6479
};
6580

6681
module.exports = AiAskCommand;

src/commands/ai/extract-structured.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ AiExtractStructuredCommand.flags = {
150150
'ai-agent': Flags.string({
151151
required: false,
152152
description:
153-
'The AI agent to be used for the structured extraction, provided as a JSON string. Example: {"type": "ai_agent_extract_structured", "basic_text": {"model": "azure__openai__gpt_4o_mini", "prompt_template": "Answer the question based on {content}"}}',
153+
'The AI agent to be used for the structured extraction, provided as a JSON string. Example: {"type": "ai_agent_extract_structured", "basicText": {"model": "azure__openai__gpt_4o_mini", "promptTemplate": "Answer the question based on {content}"}}',
154154
parse(input) {
155155
try {
156156
return JSON.parse(input);

src/commands/ai/extract.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ AiExtractCommand.flags = {
7070
'ai-agent': Flags.string({
7171
required: false,
7272
description:
73-
'The AI agent to be used for the extraction, provided as a JSON string. Example: {"type": "ai_agent_extract", "basic_text": {"model": "azure__openai__gpt_4o_mini", "prompt_template": "Answer the question based on {content}"}}',
73+
'The AI agent to be used for the extraction, provided as a JSON string. Example: {"type": "ai_agent_extract", "basicText": {"model": "azure__openai__gpt_4o_mini", "promptTemplate": "Answer the question based on {content}"}}',
7474
parse(input) {
7575
try {
7676
return JSON.parse(input);

0 commit comments

Comments
 (0)