diff --git a/.codegen.json b/.codegen.json index 7d2dfec7..19cd2cdc 100644 --- a/.codegen.json +++ b/.codegen.json @@ -1 +1 @@ -{ "engineHash": "ab2fc63", "specHash": "9919482", "version": "1.3.0" } +{ "engineHash": "ab2fc63", "specHash": "871a814", "version": "1.3.0" } diff --git a/docs/ai.md b/docs/ai.md index 2c6ae571..ecc209d3 100644 --- a/docs/ai.md +++ b/docs/ai.md @@ -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. @@ -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); ``` diff --git a/src/managers/ai.generated.ts b/src/managers/ai.generated.ts index eb378879..4da5d78b 100644 --- a/src/managers/ai.generated.ts +++ b/src/managers/ai.generated.ts @@ -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'; @@ -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} + * @returns {Promise} */ async createAiAsk( requestBody: AiAsk, optionalsInput: CreateAiAskOptionalsInput = {} - ): Promise { + ): Promise { const optionals: CreateAiAskOptionals = new CreateAiAskOptionals({ headers: optionalsInput.headers, cancellationToken: optionalsInput.cancellationToken, @@ -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. diff --git a/src/schemas/aiAgentAsk.generated.ts b/src/schemas/aiAgentAsk.generated.ts index 9974cdfd..46a95d70 100644 --- a/src/schemas/aiAgentAsk.generated.ts +++ b/src/schemas/aiAgentAsk.generated.ts @@ -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 & Partial> + ) { + 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; @@ -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 @@ -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 = @@ -85,5 +170,5 @@ export function deserializeAiAgentAsk(val: SerializedData): AiAgentAsk { basicText: basicText, longTextMulti: longTextMulti, basicTextMulti: basicTextMulti, - } satisfies AiAgentAsk; + } satisfies AiAgentAskInput; } diff --git a/src/schemas/aiAgentTextGen.generated.ts b/src/schemas/aiAgentTextGen.generated.ts index 0c4df5f0..8e568017 100644 --- a/src/schemas/aiAgentTextGen.generated.ts +++ b/src/schemas/aiAgentTextGen.generated.ts @@ -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 & Partial> + ) { + 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; @@ -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 @@ -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; } diff --git a/src/schemas/aiAsk.generated.ts b/src/schemas/aiAsk.generated.ts index 0cd60b9a..5ced877e 100644 --- a/src/schemas/aiAsk.generated.ts +++ b/src/schemas/aiAsk.generated.ts @@ -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'; @@ -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 { @@ -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), }; @@ -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; } diff --git a/src/schemas/aiAskResponse.generated.ts b/src/schemas/aiAskResponse.generated.ts new file mode 100644 index 00000000..485649e1 --- /dev/null +++ b/src/schemas/aiAskResponse.generated.ts @@ -0,0 +1,99 @@ +import { serializeAiCitation } from './aiCitation.generated.js'; +import { deserializeAiCitation } from './aiCitation.generated.js'; +import { serializeDateTime } from '../internal/utils.js'; +import { deserializeDateTime } from '../internal/utils.js'; +import { AiCitation } from './aiCitation.generated.js'; +import { DateTime } from '../internal/utils.js'; +import { BoxSdkError } from '../box/errors.js'; +import { SerializedData } from '../serialization/json.js'; +import { sdIsEmpty } from '../serialization/json.js'; +import { sdIsBoolean } from '../serialization/json.js'; +import { sdIsNumber } from '../serialization/json.js'; +import { sdIsString } from '../serialization/json.js'; +import { sdIsList } from '../serialization/json.js'; +import { sdIsMap } from '../serialization/json.js'; +export interface AiAskResponse { + /** + * The answer provided by the LLM. */ + readonly answer: string; + /** + * The ISO date formatted timestamp of when the answer to the prompt was created. */ + readonly createdAt: DateTime; + /** + * The reason the response finishes. */ + readonly completionReason?: string; + /** + * The citations of the LLM's answer reference. */ + readonly citations?: readonly AiCitation[]; +} +export function serializeAiAskResponse(val: AiAskResponse): SerializedData { + return { + ['answer']: val.answer, + ['created_at']: serializeDateTime(val.createdAt), + ['completion_reason']: + val.completionReason == void 0 ? void 0 : val.completionReason, + ['citations']: + val.citations == void 0 + ? void 0 + : (val.citations.map(function (item: AiCitation): SerializedData { + return serializeAiCitation(item); + }) as readonly any[]), + }; +} +export function deserializeAiAskResponse(val: SerializedData): AiAskResponse { + if (!sdIsMap(val)) { + throw new BoxSdkError({ message: 'Expecting a map for "AiAskResponse"' }); + } + if (val.answer == void 0) { + throw new BoxSdkError({ + message: 'Expecting "answer" of type "AiAskResponse" to be defined', + }); + } + if (!sdIsString(val.answer)) { + throw new BoxSdkError({ + message: 'Expecting string for "answer" of type "AiAskResponse"', + }); + } + const answer: string = val.answer; + if (val.created_at == void 0) { + throw new BoxSdkError({ + message: 'Expecting "created_at" of type "AiAskResponse" to be defined', + }); + } + if (!sdIsString(val.created_at)) { + throw new BoxSdkError({ + message: 'Expecting string for "created_at" of type "AiAskResponse"', + }); + } + const createdAt: DateTime = deserializeDateTime(val.created_at); + if ( + !(val.completion_reason == void 0) && + !sdIsString(val.completion_reason) + ) { + throw new BoxSdkError({ + message: + 'Expecting string for "completion_reason" of type "AiAskResponse"', + }); + } + const completionReason: undefined | string = + val.completion_reason == void 0 ? void 0 : val.completion_reason; + if (!(val.citations == void 0) && !sdIsList(val.citations)) { + throw new BoxSdkError({ + message: 'Expecting array for "citations" of type "AiAskResponse"', + }); + } + const citations: undefined | readonly AiCitation[] = + val.citations == void 0 + ? void 0 + : sdIsList(val.citations) + ? (val.citations.map(function (itm: SerializedData): AiCitation { + return deserializeAiCitation(itm); + }) as readonly any[]) + : []; + return { + answer: answer, + createdAt: createdAt, + completionReason: completionReason, + citations: citations, + } satisfies AiAskResponse; +} diff --git a/src/schemas/aiCitation.generated.ts b/src/schemas/aiCitation.generated.ts new file mode 100644 index 00000000..edc2e254 --- /dev/null +++ b/src/schemas/aiCitation.generated.ts @@ -0,0 +1,77 @@ +import { BoxSdkError } from '../box/errors.js'; +import { SerializedData } from '../serialization/json.js'; +import { sdIsEmpty } from '../serialization/json.js'; +import { sdIsBoolean } from '../serialization/json.js'; +import { sdIsNumber } from '../serialization/json.js'; +import { sdIsString } from '../serialization/json.js'; +import { sdIsList } from '../serialization/json.js'; +import { sdIsMap } from '../serialization/json.js'; +export type AiCitationTypeField = 'file'; +export interface AiCitation { + /** + * The specific content from where the answer was referenced. */ + readonly content?: string; + /** + * The id of the item. */ + readonly id?: string; + /** + * The type of the item. */ + readonly type?: AiCitationTypeField; + /** + * The name of the item. */ + readonly name?: string; +} +export function serializeAiCitationTypeField( + val: AiCitationTypeField +): SerializedData { + return val; +} +export function deserializeAiCitationTypeField( + val: SerializedData +): AiCitationTypeField { + if (val == 'file') { + return val; + } + throw new BoxSdkError({ message: "Can't deserialize AiCitationTypeField" }); +} +export function serializeAiCitation(val: AiCitation): SerializedData { + return { + ['content']: val.content == void 0 ? void 0 : val.content, + ['id']: val.id == void 0 ? void 0 : val.id, + ['type']: + val.type == void 0 ? void 0 : serializeAiCitationTypeField(val.type), + ['name']: val.name == void 0 ? void 0 : val.name, + }; +} +export function deserializeAiCitation(val: SerializedData): AiCitation { + if (!sdIsMap(val)) { + throw new BoxSdkError({ message: 'Expecting a map for "AiCitation"' }); + } + if (!(val.content == void 0) && !sdIsString(val.content)) { + throw new BoxSdkError({ + message: 'Expecting string for "content" of type "AiCitation"', + }); + } + const content: undefined | string = + val.content == void 0 ? void 0 : val.content; + if (!(val.id == void 0) && !sdIsString(val.id)) { + throw new BoxSdkError({ + message: 'Expecting string for "id" of type "AiCitation"', + }); + } + const id: undefined | string = val.id == void 0 ? void 0 : val.id; + const type: undefined | AiCitationTypeField = + val.type == void 0 ? void 0 : deserializeAiCitationTypeField(val.type); + if (!(val.name == void 0) && !sdIsString(val.name)) { + throw new BoxSdkError({ + message: 'Expecting string for "name" of type "AiCitation"', + }); + } + const name: undefined | string = val.name == void 0 ? void 0 : val.name; + return { + content: content, + id: id, + type: type, + name: name, + } satisfies AiCitation; +} diff --git a/src/schemas/aiDialogueHistory.generated.ts b/src/schemas/aiDialogueHistory.generated.ts new file mode 100644 index 00000000..442eb841 --- /dev/null +++ b/src/schemas/aiDialogueHistory.generated.ts @@ -0,0 +1,65 @@ +import { serializeDateTime } from '../internal/utils.js'; +import { deserializeDateTime } from '../internal/utils.js'; +import { DateTime } from '../internal/utils.js'; +import { BoxSdkError } from '../box/errors.js'; +import { SerializedData } from '../serialization/json.js'; +import { sdIsEmpty } from '../serialization/json.js'; +import { sdIsBoolean } from '../serialization/json.js'; +import { sdIsNumber } from '../serialization/json.js'; +import { sdIsString } from '../serialization/json.js'; +import { sdIsList } from '../serialization/json.js'; +import { sdIsMap } from '../serialization/json.js'; +export interface AiDialogueHistory { + /** + * The prompt previously provided by the client and answered by the LLM. */ + readonly prompt?: string; + /** + * The answer previously provided by the LLM. */ + readonly answer?: string; + /** + * The ISO date formatted timestamp of when the previous answer to the prompt was created. */ + readonly createdAt?: DateTime; +} +export function serializeAiDialogueHistory( + val: AiDialogueHistory +): SerializedData { + return { + ['prompt']: val.prompt == void 0 ? void 0 : val.prompt, + ['answer']: val.answer == void 0 ? void 0 : val.answer, + ['created_at']: + val.createdAt == void 0 ? void 0 : serializeDateTime(val.createdAt), + }; +} +export function deserializeAiDialogueHistory( + val: SerializedData +): AiDialogueHistory { + if (!sdIsMap(val)) { + throw new BoxSdkError({ + message: 'Expecting a map for "AiDialogueHistory"', + }); + } + if (!(val.prompt == void 0) && !sdIsString(val.prompt)) { + throw new BoxSdkError({ + message: 'Expecting string for "prompt" of type "AiDialogueHistory"', + }); + } + const prompt: undefined | string = val.prompt == void 0 ? void 0 : val.prompt; + if (!(val.answer == void 0) && !sdIsString(val.answer)) { + throw new BoxSdkError({ + message: 'Expecting string for "answer" of type "AiDialogueHistory"', + }); + } + const answer: undefined | string = val.answer == void 0 ? void 0 : val.answer; + if (!(val.created_at == void 0) && !sdIsString(val.created_at)) { + throw new BoxSdkError({ + message: 'Expecting string for "created_at" of type "AiDialogueHistory"', + }); + } + const createdAt: undefined | DateTime = + val.created_at == void 0 ? void 0 : deserializeDateTime(val.created_at); + return { + prompt: prompt, + answer: answer, + createdAt: createdAt, + } satisfies AiDialogueHistory; +} diff --git a/src/schemas/aiTextGen.generated.ts b/src/schemas/aiTextGen.generated.ts index 4def7e0f..8b451f5f 100644 --- a/src/schemas/aiTextGen.generated.ts +++ b/src/schemas/aiTextGen.generated.ts @@ -1,9 +1,9 @@ +import { serializeAiDialogueHistory } from './aiDialogueHistory.generated.js'; +import { deserializeAiDialogueHistory } from './aiDialogueHistory.generated.js'; import { serializeAiAgentTextGen } from './aiAgentTextGen.generated.js'; import { deserializeAiAgentTextGen } from './aiAgentTextGen.generated.js'; -import { serializeDateTime } from '../internal/utils.js'; -import { deserializeDateTime } from '../internal/utils.js'; +import { AiDialogueHistory } from './aiDialogueHistory.generated.js'; import { AiAgentTextGen } from './aiAgentTextGen.generated.js'; -import { DateTime } from '../internal/utils.js'; import { BoxSdkError } from '../box/errors.js'; import { SerializedData } from '../serialization/json.js'; import { sdIsEmpty } from '../serialization/json.js'; @@ -24,17 +24,6 @@ export interface AiTextGenItemsField { * The content to use as context for generating new text or editing existing text. */ readonly content?: string; } -export interface AiTextGenDialogueHistoryField { - /** - * The prompt previously provided by the client and answered by the LLM. */ - readonly prompt?: string; - /** - * The answer previously provided by the LLM. */ - readonly answer?: string; - /** - * The ISO date formatted timestamp of when the previous answer to the prompt was created. */ - readonly createdAt?: DateTime; -} export interface AiTextGen { /** * The prompt provided by the client to be answered by the LLM. The prompt's length is limited to 10000 characters. */ @@ -48,7 +37,7 @@ export interface AiTextGen { readonly items: readonly AiTextGenItemsField[]; /** * 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 AiTextGenDialogueHistoryField[]; + readonly dialogueHistory?: readonly AiDialogueHistory[]; readonly aiAgent?: AiAgentTextGen; } export function serializeAiTextGenItemsTypeField( @@ -101,52 +90,6 @@ export function deserializeAiTextGenItemsField( val.content == void 0 ? void 0 : val.content; return { id: id, type: type, content: content } satisfies AiTextGenItemsField; } -export function serializeAiTextGenDialogueHistoryField( - val: AiTextGenDialogueHistoryField -): SerializedData { - return { - ['prompt']: val.prompt == void 0 ? void 0 : val.prompt, - ['answer']: val.answer == void 0 ? void 0 : val.answer, - ['created_at']: - val.createdAt == void 0 ? void 0 : serializeDateTime(val.createdAt), - }; -} -export function deserializeAiTextGenDialogueHistoryField( - val: SerializedData -): AiTextGenDialogueHistoryField { - if (!sdIsMap(val)) { - throw new BoxSdkError({ - message: 'Expecting a map for "AiTextGenDialogueHistoryField"', - }); - } - if (!(val.prompt == void 0) && !sdIsString(val.prompt)) { - throw new BoxSdkError({ - message: - 'Expecting string for "prompt" of type "AiTextGenDialogueHistoryField"', - }); - } - const prompt: undefined | string = val.prompt == void 0 ? void 0 : val.prompt; - if (!(val.answer == void 0) && !sdIsString(val.answer)) { - throw new BoxSdkError({ - message: - 'Expecting string for "answer" of type "AiTextGenDialogueHistoryField"', - }); - } - const answer: undefined | string = val.answer == void 0 ? void 0 : val.answer; - if (!(val.created_at == void 0) && !sdIsString(val.created_at)) { - throw new BoxSdkError({ - message: - 'Expecting string for "created_at" of type "AiTextGenDialogueHistoryField"', - }); - } - const createdAt: undefined | DateTime = - val.created_at == void 0 ? void 0 : deserializeDateTime(val.created_at); - return { - prompt: prompt, - answer: answer, - createdAt: createdAt, - } satisfies AiTextGenDialogueHistoryField; -} export function serializeAiTextGen(val: AiTextGen): SerializedData { return { ['prompt']: val.prompt, @@ -159,9 +102,9 @@ export function serializeAiTextGen(val: AiTextGen): SerializedData { val.dialogueHistory == void 0 ? void 0 : (val.dialogueHistory.map(function ( - item: AiTextGenDialogueHistoryField + item: AiDialogueHistory ): SerializedData { - return serializeAiTextGenDialogueHistoryField(item); + return serializeAiDialogueHistory(item); }) as readonly any[]), ['ai_agent']: val.aiAgent == void 0 ? void 0 : serializeAiAgentTextGen(val.aiAgent), @@ -202,14 +145,14 @@ export function deserializeAiTextGen(val: SerializedData): AiTextGen { message: 'Expecting array for "dialogue_history" of type "AiTextGen"', }); } - const dialogueHistory: undefined | readonly AiTextGenDialogueHistoryField[] = + const dialogueHistory: undefined | readonly AiDialogueHistory[] = val.dialogue_history == void 0 ? void 0 : sdIsList(val.dialogue_history) ? (val.dialogue_history.map(function ( itm: SerializedData - ): AiTextGenDialogueHistoryField { - return deserializeAiTextGenDialogueHistoryField(itm); + ): AiDialogueHistory { + return deserializeAiDialogueHistory(itm); }) as readonly any[]) : []; const aiAgent: undefined | AiAgentTextGen = diff --git a/src/test/ai.generated.test.ts b/src/test/ai.generated.test.ts index 838e8e87..4b307467 100644 --- a/src/test/ai.generated.test.ts +++ b/src/test/ai.generated.test.ts @@ -1,7 +1,7 @@ import { serializeFileFull } from '../schemas/fileFull.generated.js'; import { deserializeFileFull } from '../schemas/fileFull.generated.js'; -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 { serializeAiAsk } from '../schemas/aiAsk.generated.js'; import { deserializeAiAsk } from '../schemas/aiAsk.generated.js'; import { serializeAiAskModeField } from '../schemas/aiAsk.generated.js'; @@ -10,14 +10,16 @@ import { serializeAiAskItemsField } from '../schemas/aiAsk.generated.js'; import { deserializeAiAskItemsField } from '../schemas/aiAsk.generated.js'; import { serializeAiAskItemsTypeField } from '../schemas/aiAsk.generated.js'; import { deserializeAiAskItemsTypeField } 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 { serializeAiTextGenItemsField } from '../schemas/aiTextGen.generated.js'; import { deserializeAiTextGenItemsField } from '../schemas/aiTextGen.generated.js'; import { serializeAiTextGenItemsTypeField } from '../schemas/aiTextGen.generated.js'; import { deserializeAiTextGenItemsTypeField } from '../schemas/aiTextGen.generated.js'; -import { serializeAiTextGenDialogueHistoryField } from '../schemas/aiTextGen.generated.js'; -import { deserializeAiTextGenDialogueHistoryField } from '../schemas/aiTextGen.generated.js'; +import { serializeAiDialogueHistory } from '../schemas/aiDialogueHistory.generated.js'; +import { deserializeAiDialogueHistory } from '../schemas/aiDialogueHistory.generated.js'; import { serializeAiAgentAskOrAiAgentTextGen } from '../schemas/aiAgentAskOrAiAgentTextGen.generated.js'; import { deserializeAiAgentAskOrAiAgentTextGen } from '../schemas/aiAgentAskOrAiAgentTextGen.generated.js'; import { serializeGetAiAgentDefaultConfigQueryParamsModeField } from '../managers/ai.generated.js'; @@ -28,15 +30,16 @@ import { serializeAiAgentTextGen } from '../schemas/aiAgentTextGen.generated.js' import { deserializeAiAgentTextGen } from '../schemas/aiAgentTextGen.generated.js'; import { BoxClient } from '../client.generated.js'; import { FileFull } from '../schemas/fileFull.generated.js'; -import { AiResponse } from '../schemas/aiResponse.generated.js'; +import { AiAskResponse } from '../schemas/aiAskResponse.generated.js'; import { AiAsk } from '../schemas/aiAsk.generated.js'; import { AiAskModeField } from '../schemas/aiAsk.generated.js'; import { AiAskItemsField } from '../schemas/aiAsk.generated.js'; import { AiAskItemsTypeField } from '../schemas/aiAsk.generated.js'; +import { AiResponse } from '../schemas/aiResponse.generated.js'; import { AiTextGen } from '../schemas/aiTextGen.generated.js'; import { AiTextGenItemsField } from '../schemas/aiTextGen.generated.js'; import { AiTextGenItemsTypeField } from '../schemas/aiTextGen.generated.js'; -import { AiTextGenDialogueHistoryField } from '../schemas/aiTextGen.generated.js'; +import { AiDialogueHistory } from '../schemas/aiDialogueHistory.generated.js'; import { AiAgentAskOrAiAgentTextGen } from '../schemas/aiAgentAskOrAiAgentTextGen.generated.js'; import { GetAiAgentDefaultConfigQueryParams } from '../managers/ai.generated.js'; import { GetAiAgentDefaultConfigQueryParamsModeField } from '../managers/ai.generated.js'; @@ -58,7 +61,7 @@ import { sdIsMap } from '../serialization/json.js'; export const client: BoxClient = getDefaultClient(); test('testAskAISingleItem', async function testAskAISingleItem(): Promise { const fileToAsk: FileFull = await uploadNewFile(); - const response: AiResponse = await client.ai.createAiAsk({ + const response: AiAskResponse = await client.ai.createAiAsk({ mode: 'single_item_qa' as AiAskModeField, prompt: 'which direction sun rises', items: [ @@ -80,7 +83,7 @@ test('testAskAISingleItem', async function testAskAISingleItem(): Promise { test('testAskAIMultipleItems', async function testAskAIMultipleItems(): Promise { const fileToAsk1: FileFull = await uploadNewFile(); const fileToAsk2: FileFull = await uploadNewFile(); - const response: AiResponse = await client.ai.createAiAsk({ + const response: AiAskResponse = await client.ai.createAiAsk({ mode: 'multiple_item_qa' as AiAskModeField, prompt: 'Which direction sun rises?', items: [ @@ -122,12 +125,12 @@ test('testAITextGenWithDialogueHistory', async function testAITextGenWithDialogu 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); if (!(response.answer.includes('sun') as boolean)) {