diff --git a/.codegen.json b/.codegen.json index 7ec7c97f..01055c76 100644 --- a/.codegen.json +++ b/.codegen.json @@ -1 +1 @@ -{ "engineHash": "afd7974", "specHash": "1698c95", "version": "0.3.0" } +{ "engineHash": "afd7974", "specHash": "63d1af0", "version": "0.3.0" } diff --git a/Box.Sdk.Gen/Client/BoxClient.cs b/Box.Sdk.Gen/Client/BoxClient.cs index 33b87809..b31029f2 100644 --- a/Box.Sdk.Gen/Client/BoxClient.cs +++ b/Box.Sdk.Gen/Client/BoxClient.cs @@ -145,6 +145,8 @@ public class BoxClient : IBoxClient { public IIntegrationMappingsManager IntegrationMappings { get; set; } + public IAiManager Ai { get; set; } + public BoxClient(IAuthentication auth, NetworkSession networkSession = default) { Auth = auth; NetworkSession = networkSession ?? new NetworkSession(baseUrls: new BaseUrls()); @@ -216,6 +218,7 @@ public BoxClient(IAuthentication auth, NetworkSession networkSession = default) Workflows = new WorkflowsManager(networkSession: this.NetworkSession) { Auth = this.Auth }; SignTemplates = new SignTemplatesManager(networkSession: this.NetworkSession) { Auth = this.Auth }; IntegrationMappings = new IntegrationMappingsManager(networkSession: this.NetworkSession) { Auth = this.Auth }; + Ai = new AiManager(networkSession: this.NetworkSession) { Auth = this.Auth }; } /// /// Create a new client to impersonate user with the provided ID. All calls made with the new client will be made in context of the impersonated user, leaving the original client unmodified. diff --git a/Box.Sdk.Gen/Client/IBoxClient.cs b/Box.Sdk.Gen/Client/IBoxClient.cs index 4d460609..1e019cfe 100644 --- a/Box.Sdk.Gen/Client/IBoxClient.cs +++ b/Box.Sdk.Gen/Client/IBoxClient.cs @@ -143,5 +143,7 @@ public interface IBoxClient { public IIntegrationMappingsManager IntegrationMappings { get; set; } + public IAiManager Ai { get; set; } + } } \ No newline at end of file diff --git a/Box.Sdk.Gen/Managers/Ai/AiManager.cs b/Box.Sdk.Gen/Managers/Ai/AiManager.cs new file mode 100644 index 00000000..25fd2cc2 --- /dev/null +++ b/Box.Sdk.Gen/Managers/Ai/AiManager.cs @@ -0,0 +1,58 @@ +using Unions; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using DictionaryExtensions; +using Serializer; +using Fetch; +using Box.Sdk.Gen.Schemas; +using Box.Sdk.Gen; + +namespace Box.Sdk.Gen.Managers { + public class AiManager : IAiManager { + public IAuthentication? Auth { get; set; } = default; + + public NetworkSession NetworkSession { get; set; } + + public AiManager(NetworkSession networkSession = default) { + NetworkSession = networkSession ?? new NetworkSession(); + } + /// + /// Sends an AI request to supported LLMs and returns an answer specifically focused on the user's question given the provided context. + /// + /// + /// Request body of createAiAsk method + /// + /// + /// Headers of createAiAsk method + /// + /// + /// Token used for request cancellation. + /// + public async System.Threading.Tasks.Task CreateAiAskAsync(AiAsk requestBody, CreateAiAskHeaders? headers = default, System.Threading.CancellationToken? cancellationToken = null) { + headers = headers ?? new CreateAiAskHeaders(); + Dictionary headersMap = Utils.PrepareParams(map: DictionaryUtils.MergeDictionaries(new Dictionary() { }, headers.ExtraHeaders)); + FetchResponse response = await HttpClientAdapter.FetchAsync(string.Concat(this.NetworkSession.BaseUrls.BaseUrl, "/v2/ai/ask"), new FetchOptions(method: "POST", headers: headersMap, data: SimpleJsonSerializer.Serialize(requestBody), contentType: "application/json", responseFormat: "json", auth: this.Auth, networkSession: this.NetworkSession, cancellationToken: cancellationToken)).ConfigureAwait(false); + return SimpleJsonSerializer.Deserialize(response.Data); + } + + /// + /// Sends an AI request to supported LLMs and returns an answer specifically focused on the creation of new text. + /// + /// + /// Request body of createAiTextGen method + /// + /// + /// Headers of createAiTextGen method + /// + /// + /// Token used for request cancellation. + /// + public async System.Threading.Tasks.Task CreateAiTextGenAsync(AiTextGen requestBody, CreateAiTextGenHeaders? headers = default, System.Threading.CancellationToken? cancellationToken = null) { + headers = headers ?? new CreateAiTextGenHeaders(); + Dictionary headersMap = Utils.PrepareParams(map: DictionaryUtils.MergeDictionaries(new Dictionary() { }, headers.ExtraHeaders)); + FetchResponse response = await HttpClientAdapter.FetchAsync(string.Concat(this.NetworkSession.BaseUrls.BaseUrl, "/v2/ai/text_gen"), new FetchOptions(method: "POST", headers: headersMap, data: SimpleJsonSerializer.Serialize(requestBody), contentType: "application/json", responseFormat: "json", auth: this.Auth, networkSession: this.NetworkSession, cancellationToken: cancellationToken)).ConfigureAwait(false); + return SimpleJsonSerializer.Deserialize(response.Data); + } + + } +} \ No newline at end of file diff --git a/Box.Sdk.Gen/Managers/Ai/CreateAiAskHeaders.cs b/Box.Sdk.Gen/Managers/Ai/CreateAiAskHeaders.cs new file mode 100644 index 00000000..efcbbe2a --- /dev/null +++ b/Box.Sdk.Gen/Managers/Ai/CreateAiAskHeaders.cs @@ -0,0 +1,18 @@ +using Unions; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using Box.Sdk.Gen.Schemas; +using Box.Sdk.Gen; + +namespace Box.Sdk.Gen.Managers { + public class CreateAiAskHeaders { + /// + /// Extra headers that will be included in the HTTP request. + /// + public Dictionary ExtraHeaders { get; set; } + + public CreateAiAskHeaders(Dictionary extraHeaders = default) { + ExtraHeaders = extraHeaders ?? new Dictionary() { }; + } + } +} \ No newline at end of file diff --git a/Box.Sdk.Gen/Managers/Ai/CreateAiTextGenHeaders.cs b/Box.Sdk.Gen/Managers/Ai/CreateAiTextGenHeaders.cs new file mode 100644 index 00000000..5ab4e20e --- /dev/null +++ b/Box.Sdk.Gen/Managers/Ai/CreateAiTextGenHeaders.cs @@ -0,0 +1,18 @@ +using Unions; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using Box.Sdk.Gen.Schemas; +using Box.Sdk.Gen; + +namespace Box.Sdk.Gen.Managers { + public class CreateAiTextGenHeaders { + /// + /// Extra headers that will be included in the HTTP request. + /// + public Dictionary ExtraHeaders { get; set; } + + public CreateAiTextGenHeaders(Dictionary extraHeaders = default) { + ExtraHeaders = extraHeaders ?? new Dictionary() { }; + } + } +} \ No newline at end of file diff --git a/Box.Sdk.Gen/Managers/Ai/IAiManager.cs b/Box.Sdk.Gen/Managers/Ai/IAiManager.cs new file mode 100644 index 00000000..61d3cb31 --- /dev/null +++ b/Box.Sdk.Gen/Managers/Ai/IAiManager.cs @@ -0,0 +1,18 @@ +using Unions; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using Box.Sdk.Gen.Schemas; +using Box.Sdk.Gen; + +namespace Box.Sdk.Gen.Managers { + public interface IAiManager { + public IAuthentication? Auth { get; set; } + + public NetworkSession NetworkSession { get; set; } + + public System.Threading.Tasks.Task CreateAiAskAsync(AiAsk requestBody, CreateAiAskHeaders? headers = default, System.Threading.CancellationToken? cancellationToken = null); + + public System.Threading.Tasks.Task CreateAiTextGenAsync(AiTextGen requestBody, CreateAiTextGenHeaders? headers = default, System.Threading.CancellationToken? cancellationToken = null); + + } +} \ No newline at end of file diff --git a/Box.Sdk.Gen/Schemas/AiAsk.cs b/Box.Sdk.Gen/Schemas/AiAsk.cs new file mode 100644 index 00000000..9de38e25 --- /dev/null +++ b/Box.Sdk.Gen/Schemas/AiAsk.cs @@ -0,0 +1,33 @@ +using Unions; +using System.Text.Json.Serialization; +using System; +using System.Collections.ObjectModel; +using System.Collections.Generic; + +namespace Box.Sdk.Gen.Schemas { + public class AiAsk { + /// + /// The mode specifies if this request is for a single or multiple items. + /// + [JsonPropertyName("mode")] + public AiAskModeField Mode { get; set; } + + /// + /// The prompt provided by the client to be answered by the LLM. + /// + [JsonPropertyName("prompt")] + public string Prompt { get; set; } + + /// + /// The items to be processed by the LLM, often files. + /// + [JsonPropertyName("items")] + public IReadOnlyList Items { get; set; } + + public AiAsk(AiAskModeField mode, string prompt, IReadOnlyList items) { + Mode = mode; + Prompt = prompt; + Items = items; + } + } +} \ No newline at end of file diff --git a/Box.Sdk.Gen/Schemas/AiAskItemsField.cs b/Box.Sdk.Gen/Schemas/AiAskItemsField.cs new file mode 100644 index 00000000..63e9642c --- /dev/null +++ b/Box.Sdk.Gen/Schemas/AiAskItemsField.cs @@ -0,0 +1,29 @@ +using Unions; +using System.Text.Json.Serialization; + +namespace Box.Sdk.Gen.Schemas { + public class AiAskItemsField { + /// + /// The id of the item + /// + [JsonPropertyName("id")] + public string Id { get; set; } + + /// + /// The type of the item + /// + [JsonPropertyName("type")] + public AiAskItemsTypeField Type { get; set; } + + /// + /// The content of the item, often the text representation. + /// + [JsonPropertyName("content")] + public string? Content { get; set; } = default; + + public AiAskItemsField(string id, AiAskItemsTypeField type = AiAskItemsTypeField.File) { + Id = id; + Type = type; + } + } +} \ No newline at end of file diff --git a/Box.Sdk.Gen/Schemas/AiAskItemsTypeField.cs b/Box.Sdk.Gen/Schemas/AiAskItemsTypeField.cs new file mode 100644 index 00000000..ba774feb --- /dev/null +++ b/Box.Sdk.Gen/Schemas/AiAskItemsTypeField.cs @@ -0,0 +1,11 @@ +using System.ComponentModel; +using Serializer; +using System.Text.Json.Serialization; + +namespace Box.Sdk.Gen.Schemas { + [JsonConverter(typeof(StringEnumConverter))] + public enum AiAskItemsTypeField { + [Description("file")] + File + } +} \ No newline at end of file diff --git a/Box.Sdk.Gen/Schemas/AiAskModeField.cs b/Box.Sdk.Gen/Schemas/AiAskModeField.cs new file mode 100644 index 00000000..8b9750eb --- /dev/null +++ b/Box.Sdk.Gen/Schemas/AiAskModeField.cs @@ -0,0 +1,13 @@ +using System.ComponentModel; +using Serializer; +using System.Text.Json.Serialization; + +namespace Box.Sdk.Gen.Schemas { + [JsonConverter(typeof(StringEnumConverter))] + public enum AiAskModeField { + [Description("multiple_item_qa")] + MultipleItemQa, + [Description("single_item_qa")] + SingleItemQa + } +} \ No newline at end of file diff --git a/Box.Sdk.Gen/Schemas/AiResponse.cs b/Box.Sdk.Gen/Schemas/AiResponse.cs new file mode 100644 index 00000000..d94a657b --- /dev/null +++ b/Box.Sdk.Gen/Schemas/AiResponse.cs @@ -0,0 +1,32 @@ +using Unions; +using System.Text.Json.Serialization; +using System; +using System.Collections.ObjectModel; +using System.Collections.Generic; + +namespace Box.Sdk.Gen.Schemas { + public class AiResponse { + /// + /// The answer provided by the LLM. + /// + [JsonPropertyName("answer")] + public string Answer { get; set; } + + /// + /// The ISO date formatted timestamp of when the answer to the prompt was created. + /// + [JsonPropertyName("created_at")] + public System.DateTimeOffset CreatedAt { get; set; } + + /// + /// The reason the response finishes. + /// + [JsonPropertyName("completion_reason")] + public string? CompletionReason { get; set; } = default; + + public AiResponse(string answer, System.DateTimeOffset createdAt) { + Answer = answer; + CreatedAt = createdAt; + } + } +} \ No newline at end of file diff --git a/Box.Sdk.Gen/Schemas/AiTextGen.cs b/Box.Sdk.Gen/Schemas/AiTextGen.cs new file mode 100644 index 00000000..10fcc573 --- /dev/null +++ b/Box.Sdk.Gen/Schemas/AiTextGen.cs @@ -0,0 +1,32 @@ +using Unions; +using System.Text.Json.Serialization; +using System; +using System.Collections.ObjectModel; +using System.Collections.Generic; + +namespace Box.Sdk.Gen.Schemas { + public class AiTextGen { + /// + /// The prompt provided by the client to be answered by the LLM. + /// + [JsonPropertyName("prompt")] + public string Prompt { get; set; } + + /// + /// The items to be processed by the LLM, often files. + /// + [JsonPropertyName("items")] + public IReadOnlyList Items { get; set; } + + /// + /// The history of prompts and answers previously passed to the LLM. This provides additional context to the LLM in generating the response. + /// + [JsonPropertyName("dialogue_history")] + public IReadOnlyList? DialogueHistory { get; set; } = default; + + public AiTextGen(string prompt, IReadOnlyList items) { + Prompt = prompt; + Items = items; + } + } +} \ No newline at end of file diff --git a/Box.Sdk.Gen/Schemas/AiTextGenDialogueHistoryField.cs b/Box.Sdk.Gen/Schemas/AiTextGenDialogueHistoryField.cs new file mode 100644 index 00000000..a6f53a95 --- /dev/null +++ b/Box.Sdk.Gen/Schemas/AiTextGenDialogueHistoryField.cs @@ -0,0 +1,31 @@ +using Unions; +using System.Text.Json.Serialization; +using System; +using System.Collections.ObjectModel; +using System.Collections.Generic; + +namespace Box.Sdk.Gen.Schemas { + public class AiTextGenDialogueHistoryField { + /// + /// The prompt previously provided by the client and answered by the LLM. + /// + [JsonPropertyName("prompt")] + public string? Prompt { get; set; } = default; + + /// + /// The answer previously provided by the LLM. + /// + [JsonPropertyName("answer")] + public string? Answer { get; set; } = default; + + /// + /// The ISO date formatted timestamp of when the previous answer to the prompt was created. + /// + [JsonPropertyName("created_at")] + public System.DateTimeOffset? CreatedAt { get; set; } = default; + + public AiTextGenDialogueHistoryField() { + + } + } +} \ No newline at end of file diff --git a/Box.Sdk.Gen/Schemas/AiTextGenItemsField.cs b/Box.Sdk.Gen/Schemas/AiTextGenItemsField.cs new file mode 100644 index 00000000..dc942436 --- /dev/null +++ b/Box.Sdk.Gen/Schemas/AiTextGenItemsField.cs @@ -0,0 +1,31 @@ +using Unions; +using System.Text.Json.Serialization; +using System; +using System.Collections.ObjectModel; +using System.Collections.Generic; + +namespace Box.Sdk.Gen.Schemas { + public class AiTextGenItemsField { + /// + /// The id of the item. + /// + [JsonPropertyName("id")] + public string? Id { get; set; } = default; + + /// + /// The type of the item. + /// + [JsonPropertyName("type")] + public AiTextGenItemsTypeField? Type { get; set; } = default; + + /// + /// The content to use as context for generating new text or editing existing text. + /// + [JsonPropertyName("content")] + public string? Content { get; set; } = default; + + public AiTextGenItemsField() { + + } + } +} \ No newline at end of file diff --git a/Box.Sdk.Gen/Schemas/AiTextGenItemsTypeField.cs b/Box.Sdk.Gen/Schemas/AiTextGenItemsTypeField.cs new file mode 100644 index 00000000..2d57a919 --- /dev/null +++ b/Box.Sdk.Gen/Schemas/AiTextGenItemsTypeField.cs @@ -0,0 +1,11 @@ +using System.ComponentModel; +using Serializer; +using System.Text.Json.Serialization; + +namespace Box.Sdk.Gen.Schemas { + [JsonConverter(typeof(StringEnumConverter))] + public enum AiTextGenItemsTypeField { + [Description("file")] + File + } +} \ No newline at end of file diff --git a/Box.Sdk.Gen/Schemas/PostOAuth2Revoke.cs b/Box.Sdk.Gen/Schemas/PostOAuth2Revoke.cs index 9da5afeb..83070024 100644 --- a/Box.Sdk.Gen/Schemas/PostOAuth2Revoke.cs +++ b/Box.Sdk.Gen/Schemas/PostOAuth2Revoke.cs @@ -1,5 +1,8 @@ using Unions; using System.Text.Json.Serialization; +using System; +using System.Collections.ObjectModel; +using System.Collections.Generic; namespace Box.Sdk.Gen.Schemas { public class PostOAuth2Revoke { diff --git a/Box.Sdk.Gen/Schemas/PostOAuth2Token.cs b/Box.Sdk.Gen/Schemas/PostOAuth2Token.cs index 11447d54..fc2673b7 100644 --- a/Box.Sdk.Gen/Schemas/PostOAuth2Token.cs +++ b/Box.Sdk.Gen/Schemas/PostOAuth2Token.cs @@ -1,5 +1,8 @@ using Unions; using System.Text.Json.Serialization; +using System; +using System.Collections.ObjectModel; +using System.Collections.Generic; namespace Box.Sdk.Gen.Schemas { public class PostOAuth2Token { diff --git a/Box.Sdk.Gen/Schemas/PostOAuth2TokenRefreshAccessToken.cs b/Box.Sdk.Gen/Schemas/PostOAuth2TokenRefreshAccessToken.cs index 892285f4..6b6afdec 100644 --- a/Box.Sdk.Gen/Schemas/PostOAuth2TokenRefreshAccessToken.cs +++ b/Box.Sdk.Gen/Schemas/PostOAuth2TokenRefreshAccessToken.cs @@ -1,5 +1,8 @@ using Unions; using System.Text.Json.Serialization; +using System; +using System.Collections.ObjectModel; +using System.Collections.Generic; namespace Box.Sdk.Gen.Schemas { public class PostOAuth2TokenRefreshAccessToken { diff --git a/Box.Sdk.Gen/Schemas/ZipDownloadRequestItemsField.cs b/Box.Sdk.Gen/Schemas/ZipDownloadRequestItemsField.cs index 59b65bd5..6b100b3f 100644 --- a/Box.Sdk.Gen/Schemas/ZipDownloadRequestItemsField.cs +++ b/Box.Sdk.Gen/Schemas/ZipDownloadRequestItemsField.cs @@ -1,5 +1,8 @@ using Unions; using System.Text.Json.Serialization; +using System; +using System.Collections.ObjectModel; +using System.Collections.Generic; namespace Box.Sdk.Gen.Schemas { public class ZipDownloadRequestItemsField { diff --git a/docs/Ai.md b/docs/Ai.md new file mode 100644 index 00000000..d67b7cb5 --- /dev/null +++ b/docs/Ai.md @@ -0,0 +1,62 @@ +# IAiManager + + +- [Send AI Ask request](#send-ai-ask-request) +- [Send AI Text Gen request](#send-ai-text-gen-request) + +## Send AI Ask request + +Sends an AI request to supported LLMs and returns an answer specifically focused on the user's question given the provided context. + +This operation is performed by calling function `CreateAiAsk`. + +See the endpoint docs at +[API Reference](https://developer.box.com/reference/post-ai-ask/). + +*Currently we don't have an example for calling `CreateAiAsk` in integration tests* + +### Arguments + +- requestBody `AiAsk` + - Request body of createAiAsk method +- headers `CreateAiAskHeaders` + - Headers of createAiAsk method +- cancellationToken `System.Threading.CancellationToken?` + - Token used for request cancellation. + + +### Returns + +This function returns a value of type `AiResponse`. + +A successful response including the answer from the LLM. + + +## Send AI Text Gen request + +Sends an AI request to supported LLMs and returns an answer specifically focused on the creation of new text. + +This operation is performed by calling function `CreateAiTextGen`. + +See the endpoint docs at +[API Reference](https://developer.box.com/reference/post-ai-text-gen/). + +*Currently we don't have an example for calling `CreateAiTextGen` in integration tests* + +### Arguments + +- requestBody `AiTextGen` + - Request body of createAiTextGen method +- headers `CreateAiTextGenHeaders` + - Headers of createAiTextGen method +- cancellationToken `System.Threading.CancellationToken?` + - Token used for request cancellation. + + +### Returns + +This function returns a value of type `AiResponse`. + +A successful response including the answer from the LLM. + +