Skip to content

Commit 3e3365a

Browse files
author
Hawra
committed
Made changes
1 parent 44ae9f1 commit 3e3365a

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

src/commands/ai/extract-structured.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ class AiExtractStructuredCommand extends BoxCommand {
3838
}
3939
}
4040

41-
AiExtractStructuredCommand.description = 'Sends an AI request to supported Large Language Models (LLMs) and returns extracted metadata as a set of key-value pairs. For this request, you either need a metadata template or a list of fields you want to extract. Input is either a metadata template or a list of fields to ensure the structure.';
41+
AiExtractStructuredCommand.description =
42+
'Sends an AI request to supported Large Language Models (LLMs) and returns extracted metadata as a set of key-value pairs. For this request, you either need a metadata template or a list of fields you want to extract. Input is either a metadata template or a list of fields to ensure the structure.';
4243
AiExtractStructuredCommand.examples = [
43-
'box ai:extract-structured --items="id=12345,type=file" --fields "key=hobby,type=multiSelect,description=Person hobby,prompt=What is your hobby?,displayName=Hobby,options=Guitar;Books"',
44-
'box ai:extract-structured --items="id=12345,type=file" --fields "key=firstName,type=string,description=Person first name,prompt=What is the first name?,displayName=First name" --fields "key=lastName,type=string,description=Person last name,prompt=What is the last name?,displayName=Last name"',
45-
'box ai:extract-structured --items="id=12345,type=file" --metadata-template="type=metadata_template,scope=enterprise,template_key=test" --ai-agent \'{"type":"ai_agent_extract_structured","basicText":{"llmEndpointParams":{"type":"openai_params","frequencyPenalty": 1.5,"presencePenalty": 1.5,"stop": "<|im_end|>","temperature": 0,"topP": 1},"model": "azure__openai__gpt_4o_mini","numTokensForCompletion": 8400,"promptTemplate": "It is, consider these travel options and answer the.","systemMessage": "You are a helpful travel assistant specialized in budget travel"},"longText":{"embeddings":{ "model": "azure__openai__text_embedding_ada_002","strategy":{"id": "basic","numTokensPerChunk": 64}},"llmEndpointParams":{"type":"openai_params","frequencyPenalty": 1.5,"presencePenalty": 1.5,"stop": "<|im_end|>","temperature": 0,"topP": 1},"model":"azure__openai__gpt_4o_mini","numTokensForCompletion":8400,"promptTemplate":"It is , consider these travel options and answer the.","systemMessage":"You are a helpful travel assistant specialized in budget travel"}}\'',
44+
'box ai:extract-structured --items="id=12345,type=file" --fields "key=hobby,type=multiSelect,description=Person hobby,prompt=What is your hobby?,displayName=Hobby,options=Guitar;Books"',
45+
'box ai:extract-structured --items="id=12345,type=file" --metadata-template="type=metadata_template,scope=enterprise,template_key=test" --ai-agent \'{"type":"ai_agent_extract_structured","basicText":{"llmEndpointParams":{"type":"openai_params","frequencyPenalty": 1.5,"presencePenalty": 1.5,"stop": "<|im_end|>","temperature": 0,"topP": 1},"model": "azure__openai__gpt_4o_mini","numTokensForCompletion": 8400,"promptTemplate": "It is, consider these travel options and answer the.","systemMessage": "You are a helpful travel assistant specialized in budget travel"}}}\'',
4646
];
4747
AiExtractStructuredCommand._endpoint = 'post_ai_extract_structured';
4848

@@ -76,7 +76,8 @@ AiExtractStructuredCommand.flags = {
7676
},
7777
}),
7878
'metadata-template': Flags.string({
79-
description: 'The metadata template containing the fields to extract. Example: {"type": "metadata_template", "scope": "enterprise", "template_key": "test"}',
79+
description:
80+
'The metadata template containing the fields to extract. Example: {"type": "metadata_template", "scope": "enterprise", "template_key": "test"}',
8081
parse(input) {
8182
const metadataTemplate = {
8283
type: 'metadata_template',
@@ -106,14 +107,7 @@ AiExtractStructuredCommand.flags = {
106107
multiple: true,
107108
description: 'The fields to be extracted from the provided items.',
108109
parse(input) {
109-
const fields = {
110-
key: '',
111-
type: '',
112-
description: '',
113-
prompt: '',
114-
displayName: '',
115-
options: [],
116-
};
110+
const fields = {};
117111

118112
const obj = utils.parseStringToObject(input, [
119113
'key',
@@ -163,7 +157,7 @@ AiExtractStructuredCommand.flags = {
163157
try {
164158
return JSON.parse(input);
165159
} catch (error) {
166-
throw ('Error parsing ai agent ', error);
160+
throw ('Error parsing AI agent ', error);
167161
}
168162
},
169163
}),

src/commands/ai/extract.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict';
22

33
const BoxCommand = require('../../box-command');
4-
const {Flags} = require('@oclif/core');
4+
const { Flags } = require('@oclif/core');
55
const utils = require('../../util');
66

77
class AiExtractCommand extends BoxCommand {
88
async run() {
9-
const {flags} = await this.parse(AiExtractCommand);
9+
const { flags } = await this.parse(AiExtractCommand);
1010
let options = {};
1111

1212
if (flags.prompt) {
@@ -30,7 +30,7 @@ AiExtractCommand.description =
3030
'Sends an AI request to supported Large Language Models (LLMs) and extracts metadata in form of key-value pairs';
3131
AiExtractCommand.examples = [
3232
'box ai:extract --items=id=12345,type=file --prompt "firstName, lastName, location, yearOfBirth, company"',
33-
'box ai:extract --prompt "firstName, lastName, location, yearOfBirth, company" --items "id=12345,type=file" --ai-agent \'{"type":"ai_agent_extract","basicText":{"llmEndpointParams":{"type":"openai_params","frequencyPenalty": 1.5,"presencePenalty": 1.5,"stop": "<|im_end|>","temperature": 0,"topP": 1},"model": "azure__openai__gpt_4o_mini","numTokensForCompletion": 8400,"promptTemplate": "It is, consider these travel options and answer the.","systemMessage": "You are a helpful travel assistant specialized in budget travel"},"longText":{"embeddings":{ "model": "azure__openai__text_embedding_ada_002","strategy":{"id": "basic","numTokensPerChunk": 64}},"llmEndpointParams":{"type":"openai_params","frequencyPenalty": 1.5,"presencePenalty": 1.5,"stop": "<|im_end|>","temperature": 0,"topP": 1},"model":"azure__openai__gpt_4o_mini","numTokensForCompletion":8400,"promptTemplate":"It is , consider these travel options and answer the.","systemMessage":"You are a helpful travel assistant specialized in budget travel"}}\'',
33+
'box ai:extract --prompt "firstName, lastName, location, yearOfBirth, company" --items "id=12345,type=file" --ai-agent \'{"type":"ai_agent_extract","basicText":{"llmEndpointParams":{"type":"openai_params","frequencyPenalty": 1.5,"presencePenalty": 1.5,"stop": "<|im_end|>","temperature": 0,"topP": 1},"model": "azure__openai__gpt_4o_mini","numTokensForCompletion": 8400,"promptTemplate": "It is, consider these travel options and answer the.","systemMessage": "You are a helpful travel assistant specialized in budget travel"}}}\'',
3434
];
3535
AiExtractCommand._endpoint = 'post_ai_extract';
3636

@@ -39,7 +39,8 @@ AiExtractCommand.flags = {
3939
...BoxCommand.flags,
4040
prompt: Flags.string({
4141
required: true,
42-
description: 'The prompt provided to a Large Language Model (LLM) in the request.',
42+
description:
43+
'The prompt provided to a Large Language Model (LLM) in the request.',
4344
}),
4445
items: Flags.string({
4546
required: true,
@@ -68,9 +69,14 @@ AiExtractCommand.flags = {
6869
}),
6970
'ai-agent': Flags.string({
7071
required: false,
71-
description: 'The AI agent to be used for the extraction.',
72+
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}"}}',
7274
parse(input) {
73-
return JSON.parse(input);
75+
try {
76+
return JSON.parse(input);
77+
} catch (error) {
78+
throw ('Error parsing AI agent ', error);
79+
}
7480
},
7581
}),
7682
};

test/commands/ai.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ describe('AI', () => {
230230
description: 'Person first name',
231231
prompt: 'What is the first name?',
232232
displayName: 'First name',
233-
options: [],
233+
options: [{key:'First Name'}],
234234
},
235235
],
236236
};
@@ -267,7 +267,7 @@ describe('AI', () => {
267267
.command([
268268
'ai:extract-structured',
269269
'--items=content=one,two,three,id=12345,type=file',
270-
'--fields=key=firstName,type=string,description=Person first name,prompt=What is the first name?,displayName=First name',
270+
'--fields=key=firstName,type=string,description=Person first name,prompt=What is the first name?,displayName=First name,options=First Name',
271271
'--json',
272272
'--token=test',
273273
])
@@ -289,7 +289,7 @@ describe('AI', () => {
289289
.command([
290290
'ai:extract-structured',
291291
'--items=content=one,two,three,id=12345,type=file',
292-
'--fields=key=firstName,type=string,description=Person first name,prompt=What is the first name?,displayName=First name',
292+
'--fields=key=firstName,type=string,description=Person first name,prompt=What is the first name?,displayName=First name,options=First Name',
293293
'--token=test',
294294
])
295295

@@ -317,7 +317,7 @@ describe('AI', () => {
317317
description: 'Person first name',
318318
prompt: 'What is the first name?',
319319
displayName: 'First name',
320-
options: [],
320+
options: [{key:'First Name'}],
321321
},
322322
],
323323
ai_agent: {
@@ -396,7 +396,7 @@ describe('AI', () => {
396396
.command([
397397
'ai:extract-structured',
398398
'--items=content=one,two,three,id=12345,type=file',
399-
'--fields=key=firstName,type=string,description=Person first name,prompt=What is the first name?,displayName=First name',
399+
'--fields=key=firstName,type=string,description=Person first name,prompt=What is the first name?,displayName=First name,options=First Name',
400400
'--ai-agent',
401401
'{"type":"ai_agent_extract_structured","basicText":{"llmEndpointParams":{"type":"openai_params","frequencyPenalty": 1.5,"presencePenalty": 1.5,"stop": "<|im_end|>","temperature": 0,"topP": 1},"model": "azure__openai__gpt_4o_mini","numTokensForCompletion": 8400,"promptTemplate": "It is, consider these travel options and answer the.","systemMessage": "You are a helpful travel assistant specialized in budget travel"},"longText":{"embeddings":{ "model": "azure__openai__text_embedding_ada_002","strategy":{"id": "basic","numTokensPerChunk": 64}},"llmEndpointParams":{"type":"openai_params","frequencyPenalty": 1.5,"presencePenalty": 1.5,"stop": "<|im_end|>","temperature": 0,"topP": 1},"model":"azure__openai__gpt_4o_mini","numTokensForCompletion":8400,"promptTemplate":"It is , consider these travel options and answer the.","systemMessage":"You are a helpful travel assistant specialized in budget travel"}}',
402402
'--json',
@@ -420,7 +420,7 @@ describe('AI', () => {
420420
.command([
421421
'ai:extract-structured',
422422
'--items=content=one,two,three,id=12345,type=file',
423-
'--fields=key=firstName,type=string,description=Person first name,prompt=What is the first name?,displayName=First name',
423+
'--fields=key=firstName,type=string,description=Person first name,prompt=What is the first name?,displayName=First name,options=First Name',
424424
'--ai-agent',
425425
'{"type":"ai_agent_extract_structured","basicText":{"llmEndpointParams":{"type":"openai_params","frequencyPenalty": 1.5,"presencePenalty": 1.5,"stop": "<|im_end|>","temperature": 0,"topP": 1},"model": "azure__openai__gpt_4o_mini","numTokensForCompletion": 8400,"promptTemplate": "It is, consider these travel options and answer the.","systemMessage": "You are a helpful travel assistant specialized in budget travel"},"longText":{"embeddings":{ "model": "azure__openai__text_embedding_ada_002","strategy":{"id": "basic","numTokensPerChunk": 64}},"llmEndpointParams":{"type":"openai_params","frequencyPenalty": 1.5,"presencePenalty": 1.5,"stop": "<|im_end|>","temperature": 0,"topP": 1},"model":"azure__openai__gpt_4o_mini","numTokensForCompletion":8400,"promptTemplate":"It is , consider these travel options and answer the.","systemMessage":"You are a helpful travel assistant specialized in budget travel"}}',
426426
'--token=test',

0 commit comments

Comments
 (0)