Skip to content

Commit

Permalink
feat: add parameters to box ai ask and text gen (box/box-openapi#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
box-sdk-build committed Aug 12, 2024
1 parent f8ceac0 commit 1df04ed
Show file tree
Hide file tree
Showing 11 changed files with 465 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "ab2fc63", "specHash": "9919482", "version": "1.3.0" }
{ "engineHash": "ab2fc63", "specHash": "871a814", "version": "1.3.0" }
6 changes: 3 additions & 3 deletions docs/ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ await client.ai.createAiAsk({

### Returns

This function returns a value of type `AiResponse`.
This function returns a value of type `AiAskResponse`.

A successful response including the answer from the LLM.

Expand Down Expand Up @@ -74,12 +74,12 @@ await client.ai.createAiTextGen({
prompt: 'What does the earth go around?',
answer: 'The sun',
createdAt: dateTimeFromString('2021-01-01T00:00:00Z'),
} satisfies AiTextGenDialogueHistoryField,
} satisfies AiDialogueHistory,
{
prompt: 'On Earth, where does the sun rise?',
answer: 'East',
createdAt: dateTimeFromString('2021-01-01T00:00:00Z'),
} satisfies AiTextGenDialogueHistoryField,
} satisfies AiDialogueHistory,
],
} satisfies AiTextGen);
```
Expand Down
15 changes: 9 additions & 6 deletions src/managers/ai.generated.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { serializeAiResponse } from '../schemas/aiResponse.generated.js';
import { deserializeAiResponse } from '../schemas/aiResponse.generated.js';
import { serializeAiAskResponse } from '../schemas/aiAskResponse.generated.js';
import { deserializeAiAskResponse } from '../schemas/aiAskResponse.generated.js';
import { serializeClientError } from '../schemas/clientError.generated.js';
import { deserializeClientError } from '../schemas/clientError.generated.js';
import { serializeAiAsk } from '../schemas/aiAsk.generated.js';
import { deserializeAiAsk } from '../schemas/aiAsk.generated.js';
import { serializeAiResponse } from '../schemas/aiResponse.generated.js';
import { deserializeAiResponse } from '../schemas/aiResponse.generated.js';
import { serializeAiTextGen } from '../schemas/aiTextGen.generated.js';
import { deserializeAiTextGen } from '../schemas/aiTextGen.generated.js';
import { serializeAiAgentAskOrAiAgentTextGen } from '../schemas/aiAgentAskOrAiAgentTextGen.generated.js';
import { deserializeAiAgentAskOrAiAgentTextGen } from '../schemas/aiAgentAskOrAiAgentTextGen.generated.js';
import { AiResponse } from '../schemas/aiResponse.generated.js';
import { AiAskResponse } from '../schemas/aiAskResponse.generated.js';
import { ClientError } from '../schemas/clientError.generated.js';
import { AiAsk } from '../schemas/aiAsk.generated.js';
import { AiResponse } from '../schemas/aiResponse.generated.js';
import { AiTextGen } from '../schemas/aiTextGen.generated.js';
import { AiAgentAskOrAiAgentTextGen } from '../schemas/aiAgentAskOrAiAgentTextGen.generated.js';
import { Authentication } from '../networking/auth.generated.js';
Expand Down Expand Up @@ -203,12 +206,12 @@ export class AiManager {
* Sends an AI request to supported LLMs and returns an answer specifically focused on the user's question given the provided context.
* @param {AiAsk} requestBody Request body of createAiAsk method
* @param {CreateAiAskOptionalsInput} optionalsInput
* @returns {Promise<AiResponse>}
* @returns {Promise<AiAskResponse>}
*/
async createAiAsk(
requestBody: AiAsk,
optionalsInput: CreateAiAskOptionalsInput = {}
): Promise<AiResponse> {
): Promise<AiAskResponse> {
const optionals: CreateAiAskOptionals = new CreateAiAskOptionals({
headers: optionalsInput.headers,
cancellationToken: optionalsInput.cancellationToken,
Expand All @@ -231,7 +234,7 @@ export class AiManager {
cancellationToken: cancellationToken,
} satisfies FetchOptions
)) as FetchResponse;
return deserializeAiResponse(response.data);
return deserializeAiAskResponse(response.data);
}
/**
* Sends an AI request to supported LLMs and returns an answer specifically focused on the creation of new text.
Expand Down
93 changes: 89 additions & 4 deletions src/schemas/aiAgentAsk.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,35 @@ import { sdIsString } from '../serialization/json.js';
import { sdIsList } from '../serialization/json.js';
import { sdIsMap } from '../serialization/json.js';
export type AiAgentAskTypeField = 'ai_agent_ask';
export interface AiAgentAsk {
export class AiAgentAsk {
/**
* The type of AI agent used to handle queries. */
readonly type: AiAgentAskTypeField = 'ai_agent_ask' as AiAgentAskTypeField;
readonly longText?: AiAgentLongTextTool;
readonly basicText?: AiAgentBasicTextToolAsk;
readonly longTextMulti?: AiAgentLongTextTool;
readonly basicTextMulti?: AiAgentBasicTextToolAsk;
constructor(
fields: Omit<AiAgentAsk, 'type'> & Partial<Pick<AiAgentAsk, 'type'>>
) {
if (fields.type) {
this.type = fields.type;
}
if (fields.longText) {
this.longText = fields.longText;
}
if (fields.basicText) {
this.basicText = fields.basicText;
}
if (fields.longTextMulti) {
this.longTextMulti = fields.longTextMulti;
}
if (fields.basicTextMulti) {
this.basicTextMulti = fields.basicTextMulti;
}
}
}
export interface AiAgentAskInput {
/**
* The type of AI agent used to handle queries. */
readonly type?: AiAgentAskTypeField;
Expand All @@ -37,8 +65,7 @@ export function deserializeAiAgentAskTypeField(
}
export function serializeAiAgentAsk(val: AiAgentAsk): SerializedData {
return {
['type']:
val.type == void 0 ? void 0 : serializeAiAgentAskTypeField(val.type),
['type']: serializeAiAgentAskTypeField(val.type),
['long_text']:
val.longText == void 0
? void 0
Expand All @@ -61,6 +88,64 @@ export function deserializeAiAgentAsk(val: SerializedData): AiAgentAsk {
if (!sdIsMap(val)) {
throw new BoxSdkError({ message: 'Expecting a map for "AiAgentAsk"' });
}
if (val.type == void 0) {
throw new BoxSdkError({
message: 'Expecting "type" of type "AiAgentAsk" to be defined',
});
}
const type: AiAgentAskTypeField = deserializeAiAgentAskTypeField(val.type);
const longText: undefined | AiAgentLongTextTool =
val.long_text == void 0
? void 0
: deserializeAiAgentLongTextTool(val.long_text);
const basicText: undefined | AiAgentBasicTextToolAsk =
val.basic_text == void 0
? void 0
: deserializeAiAgentBasicTextToolAsk(val.basic_text);
const longTextMulti: undefined | AiAgentLongTextTool =
val.long_text_multi == void 0
? void 0
: deserializeAiAgentLongTextTool(val.long_text_multi);
const basicTextMulti: undefined | AiAgentBasicTextToolAsk =
val.basic_text_multi == void 0
? void 0
: deserializeAiAgentBasicTextToolAsk(val.basic_text_multi);
return {
type: type,
longText: longText,
basicText: basicText,
longTextMulti: longTextMulti,
basicTextMulti: basicTextMulti,
} satisfies AiAgentAsk;
}
export function serializeAiAgentAskInput(val: AiAgentAskInput): SerializedData {
return {
['type']:
val.type == void 0 ? void 0 : serializeAiAgentAskTypeField(val.type),
['long_text']:
val.longText == void 0
? void 0
: serializeAiAgentLongTextTool(val.longText),
['basic_text']:
val.basicText == void 0
? void 0
: serializeAiAgentBasicTextToolAsk(val.basicText),
['long_text_multi']:
val.longTextMulti == void 0
? void 0
: serializeAiAgentLongTextTool(val.longTextMulti),
['basic_text_multi']:
val.basicTextMulti == void 0
? void 0
: serializeAiAgentBasicTextToolAsk(val.basicTextMulti),
};
}
export function deserializeAiAgentAskInput(
val: SerializedData
): AiAgentAskInput {
if (!sdIsMap(val)) {
throw new BoxSdkError({ message: 'Expecting a map for "AiAgentAskInput"' });
}
const type: undefined | AiAgentAskTypeField =
val.type == void 0 ? void 0 : deserializeAiAgentAskTypeField(val.type);
const longText: undefined | AiAgentLongTextTool =
Expand All @@ -85,5 +170,5 @@ export function deserializeAiAgentAsk(val: SerializedData): AiAgentAsk {
basicText: basicText,
longTextMulti: longTextMulti,
basicTextMulti: basicTextMulti,
} satisfies AiAgentAsk;
} satisfies AiAgentAskInput;
}
58 changes: 54 additions & 4 deletions src/schemas/aiAgentTextGen.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,24 @@ import { sdIsString } from '../serialization/json.js';
import { sdIsList } from '../serialization/json.js';
import { sdIsMap } from '../serialization/json.js';
export type AiAgentTextGenTypeField = 'ai_agent_text_gen';
export interface AiAgentTextGen {
export class AiAgentTextGen {
/**
* The type of AI agent used for generating text. */
readonly type: AiAgentTextGenTypeField =
'ai_agent_text_gen' as AiAgentTextGenTypeField;
readonly basicGen?: AiAgentBasicGenTool;
constructor(
fields: Omit<AiAgentTextGen, 'type'> & Partial<Pick<AiAgentTextGen, 'type'>>
) {
if (fields.type) {
this.type = fields.type;
}
if (fields.basicGen) {
this.basicGen = fields.basicGen;
}
}
}
export interface AiAgentTextGenInput {
/**
* The type of AI agent used for generating text. */
readonly type?: AiAgentTextGenTypeField;
Expand All @@ -33,8 +50,7 @@ export function deserializeAiAgentTextGenTypeField(
}
export function serializeAiAgentTextGen(val: AiAgentTextGen): SerializedData {
return {
['type']:
val.type == void 0 ? void 0 : serializeAiAgentTextGenTypeField(val.type),
['type']: serializeAiAgentTextGenTypeField(val.type),
['basic_gen']:
val.basicGen == void 0
? void 0
Expand All @@ -45,11 +61,45 @@ export function deserializeAiAgentTextGen(val: SerializedData): AiAgentTextGen {
if (!sdIsMap(val)) {
throw new BoxSdkError({ message: 'Expecting a map for "AiAgentTextGen"' });
}
if (val.type == void 0) {
throw new BoxSdkError({
message: 'Expecting "type" of type "AiAgentTextGen" to be defined',
});
}
const type: AiAgentTextGenTypeField = deserializeAiAgentTextGenTypeField(
val.type
);
const basicGen: undefined | AiAgentBasicGenTool =
val.basic_gen == void 0
? void 0
: deserializeAiAgentBasicGenTool(val.basic_gen);
return { type: type, basicGen: basicGen } satisfies AiAgentTextGen;
}
export function serializeAiAgentTextGenInput(
val: AiAgentTextGenInput
): SerializedData {
return {
['type']:
val.type == void 0 ? void 0 : serializeAiAgentTextGenTypeField(val.type),
['basic_gen']:
val.basicGen == void 0
? void 0
: serializeAiAgentBasicGenTool(val.basicGen),
};
}
export function deserializeAiAgentTextGenInput(
val: SerializedData
): AiAgentTextGenInput {
if (!sdIsMap(val)) {
throw new BoxSdkError({
message: 'Expecting a map for "AiAgentTextGenInput"',
});
}
const type: undefined | AiAgentTextGenTypeField =
val.type == void 0 ? void 0 : deserializeAiAgentTextGenTypeField(val.type);
const basicGen: undefined | AiAgentBasicGenTool =
val.basic_gen == void 0
? void 0
: deserializeAiAgentBasicGenTool(val.basic_gen);
return { type: type, basicGen: basicGen } satisfies AiAgentTextGen;
return { type: type, basicGen: basicGen } satisfies AiAgentTextGenInput;
}
46 changes: 46 additions & 0 deletions src/schemas/aiAsk.generated.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { serializeAiDialogueHistory } from './aiDialogueHistory.generated.js';
import { deserializeAiDialogueHistory } from './aiDialogueHistory.generated.js';
import { serializeAiAgentAsk } from './aiAgentAsk.generated.js';
import { deserializeAiAgentAsk } from './aiAgentAsk.generated.js';
import { AiDialogueHistory } from './aiDialogueHistory.generated.js';
import { AiAgentAsk } from './aiAgentAsk.generated.js';
import { BoxSdkError } from '../box/errors.js';
import { SerializedData } from '../serialization/json.js';
Expand Down Expand Up @@ -61,6 +64,12 @@ export interface AiAsk {
* If the file size exceeds 1MB, the first 1MB of text representation will be processed.
* If you set `mode` parameter to `single_item_qa`, the `items` array can have one element only. */
readonly items: readonly AiAskItemsField[];
/**
* The history of prompts and answers previously passed to the LLM. This provides additional context to the LLM in generating the response. */
readonly dialogueHistory?: readonly AiDialogueHistory[];
/**
* A flag to indicate whether citations should be returned. */
readonly includeCitations?: boolean;
readonly aiAgent?: AiAgentAsk;
}
export function serializeAiAskModeField(val: AiAskModeField): SerializedData {
Expand Down Expand Up @@ -178,6 +187,16 @@ export function serializeAiAsk(val: AiAsk): SerializedData {
['items']: val.items.map(function (item: AiAskItemsField): SerializedData {
return serializeAiAskItemsField(item);
}) as readonly any[],
['dialogue_history']:
val.dialogueHistory == void 0
? void 0
: (val.dialogueHistory.map(function (
item: AiDialogueHistory
): SerializedData {
return serializeAiDialogueHistory(item);
}) as readonly any[]),
['include_citations']:
val.includeCitations == void 0 ? void 0 : val.includeCitations,
['ai_agent']:
val.aiAgent == void 0 ? void 0 : serializeAiAgentAsk(val.aiAgent),
};
Expand Down Expand Up @@ -218,12 +237,39 @@ export function deserializeAiAsk(val: SerializedData): AiAsk {
return deserializeAiAskItemsField(itm);
}) as readonly any[])
: [];
if (!(val.dialogue_history == void 0) && !sdIsList(val.dialogue_history)) {
throw new BoxSdkError({
message: 'Expecting array for "dialogue_history" of type "AiAsk"',
});
}
const dialogueHistory: undefined | readonly AiDialogueHistory[] =
val.dialogue_history == void 0
? void 0
: sdIsList(val.dialogue_history)
? (val.dialogue_history.map(function (
itm: SerializedData
): AiDialogueHistory {
return deserializeAiDialogueHistory(itm);
}) as readonly any[])
: [];
if (
!(val.include_citations == void 0) &&
!sdIsBoolean(val.include_citations)
) {
throw new BoxSdkError({
message: 'Expecting boolean for "include_citations" of type "AiAsk"',
});
}
const includeCitations: undefined | boolean =
val.include_citations == void 0 ? void 0 : val.include_citations;
const aiAgent: undefined | AiAgentAsk =
val.ai_agent == void 0 ? void 0 : deserializeAiAgentAsk(val.ai_agent);
return {
mode: mode,
prompt: prompt,
items: items,
dialogueHistory: dialogueHistory,
includeCitations: includeCitations,
aiAgent: aiAgent,
} satisfies AiAsk;
}
Loading

0 comments on commit 1df04ed

Please sign in to comment.