Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@oclif/plugin-version": "^2.2.16",
"archiver": "^3.0.0",
"box-node-sdk": "^3.7.0",
"box-typescript-sdk-gen": "^1.15.1",
"box-typescript-sdk-gen": "^1.17.1",
"chalk": "^2.4.1",
"cli-progress": "^2.1.0",
"csv": "^6.3.3",
Expand Down
101 changes: 58 additions & 43 deletions src/commands/ai/ask.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,74 @@ class AiAskCommand extends BoxCommand {
async run() {
const { flags } = await this.parse(AiAskCommand);
let options = {};
options.mode = flags.items.length > 1 ? 'multi_item_qa' : 'single_item_qa';
options.mode = flags.items.length > 1 ? 'multi_item_qa' : 'single_item_qa';

if (flags.prompt) {
options.prompt = flags.prompt;
}
if (flags.items) {
options.items = flags.items;
}
if (flags.prompt) {
options.prompt = flags.prompt;
}
if (flags.items) {
options.items = flags.items;
}
if (flags['ai-agent']) {
options.aiAgent = flags['ai-agent'];
}

let answer = await this.client.ai.ask({
prompt: options.prompt,
items: options.items,
mode: options.mode
});
await this.output(answer);
let answer = await this.tsClient.ai.createAiAsk(options);
delete answer.rawData;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why delete ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

response from our ts-sdk-gen includes also rawData field which is populated with raw json that was returned from the API. If we would return the response as is, it would contain redundant fields which could confuse cli users.

await this.output(answer);
}
}

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

AiAskCommand.flags = {
...BoxCommand.flags,
prompt: Flags.string({
required: true,
description: 'The prompt for the AI request',
}),
items: Flags.string({
required: true,
description: 'The items for the AI request',
multiple: true,
parse(input) {
const item = {
id: '',
type: 'file'
};
const obj = utils.parseStringToObject(input, ['id', 'type', 'content']);
for (const key in obj) {
if (key === 'id') {
item.id = obj[key];
} else if (key === 'type') {
item.type = obj[key];
} else if (key === 'content') {
item.content = obj[key];
} else {
throw new Error(`Invalid item key ${key}`);
}
}
prompt: Flags.string({
required: true,
description: 'The prompt for the AI request',
}),
items: Flags.string({
required: true,
description: 'The items for the AI request',
multiple: true,
parse(input) {
const item = {
id: '',
type: 'file',
};
const obj = utils.parseStringToObject(input, ['id', 'type', 'content']);
for (const key in obj) {
if (key === 'id') {
item.id = obj[key];
} else if (key === 'type') {
item.type = obj[key];
} else if (key === 'content') {
item.content = obj[key];
} else {
throw new Error(`Invalid item key ${key}`);
}
}

return item;
}
}),
return item;
},
}),
'ai-agent': Flags.string({
required: false,
description:
'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"}}',
parse(input) {
try {
return JSON.parse(input);
} catch (error) {
throw ('Error parsing AI agent ', error);
}
},
}),
};

module.exports = AiAskCommand;
2 changes: 1 addition & 1 deletion src/commands/ai/extract-structured.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ AiExtractStructuredCommand.flags = {
'ai-agent': Flags.string({
required: false,
description:
'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}"}}',
'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}"}}',
parse(input) {
try {
return JSON.parse(input);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/ai/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ AiExtractCommand.flags = {
'ai-agent': Flags.string({
required: false,
description:
'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}"}}',
'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}"}}',
parse(input) {
try {
return JSON.parse(input);
Expand Down
Loading
Loading