From 0f4a0c1086751a7c2a1e40ce1bc843d6f929e62d Mon Sep 17 00:00:00 2001 From: Luciana Regina Lino Date: Wed, 19 Jun 2024 11:39:14 -0300 Subject: [PATCH] feat (Liquid.Core): Implements core interfaces and classes for cartrigdes of AI functionalities OCR and ChatCompletions. --- .github/workflows/liquid-ci-cd-cache.yml | 26 ------ .../liquid-ci-cd-domain-extensions-crud.yml | 26 ------ .github/workflows/liquid-ci-cd-domain.yml | 26 ------ .../liquid-ci-cd-http-extensions-crud.yml | 26 ------ .github/workflows/liquid-ci-cd-messaging.yaml | 26 ------ .github/workflows/liquid-ci-cd-repository.yml | 26 ------ .../AbstractMappers/OcrResultMapper.cs | 53 +++++++++++ .../Entities/ChatCompletionResult.cs | 24 +++++ src/Liquid.Core/Entities/ChatMessages.cs | 35 +++++++ src/Liquid.Core/Entities/ClientDictionary.cs | 39 ++++++++ src/Liquid.Core/Entities/FunctionBody.cs | 72 +++++++++++++++ src/Liquid.Core/Entities/OcrResult.cs | 91 +++++++++++++++++++ .../Exceptions/DataMappingException.cs | 21 +++++ .../Interfaces/ILiquidChatCompletions.cs | 45 +++++++++ src/Liquid.Core/Interfaces/ILiquidMapper.cs | 19 ++++ src/Liquid.Core/Interfaces/ILiquidOcr.cs | 64 +++++++++++++ src/Liquid.Core/Liquid.Core.csproj | 3 +- .../Settings/CompletionsSettings.cs | 61 +++++++++++++ src/Liquid.Core/Settings/GenAiOptions.cs | 62 +++++++++++++ src/Liquid.Core/Settings/OcrOptions.cs | 38 ++++++++ 20 files changed, 626 insertions(+), 157 deletions(-) delete mode 100644 .github/workflows/liquid-ci-cd-cache.yml delete mode 100644 .github/workflows/liquid-ci-cd-domain-extensions-crud.yml delete mode 100644 .github/workflows/liquid-ci-cd-domain.yml delete mode 100644 .github/workflows/liquid-ci-cd-http-extensions-crud.yml delete mode 100644 .github/workflows/liquid-ci-cd-messaging.yaml delete mode 100644 .github/workflows/liquid-ci-cd-repository.yml create mode 100644 src/Liquid.Core/AbstractMappers/OcrResultMapper.cs create mode 100644 src/Liquid.Core/Entities/ChatCompletionResult.cs create mode 100644 src/Liquid.Core/Entities/ChatMessages.cs create mode 100644 src/Liquid.Core/Entities/ClientDictionary.cs create mode 100644 src/Liquid.Core/Entities/FunctionBody.cs create mode 100644 src/Liquid.Core/Entities/OcrResult.cs create mode 100644 src/Liquid.Core/Exceptions/DataMappingException.cs create mode 100644 src/Liquid.Core/Interfaces/ILiquidChatCompletions.cs create mode 100644 src/Liquid.Core/Interfaces/ILiquidMapper.cs create mode 100644 src/Liquid.Core/Interfaces/ILiquidOcr.cs create mode 100644 src/Liquid.Core/Settings/CompletionsSettings.cs create mode 100644 src/Liquid.Core/Settings/GenAiOptions.cs create mode 100644 src/Liquid.Core/Settings/OcrOptions.cs diff --git a/.github/workflows/liquid-ci-cd-cache.yml b/.github/workflows/liquid-ci-cd-cache.yml deleted file mode 100644 index a625476..0000000 --- a/.github/workflows/liquid-ci-cd-cache.yml +++ /dev/null @@ -1,26 +0,0 @@ -# CI & CD workflow -name: CI/CD - Liquid.Cache component for Liquid Application Framework - -on: - push: - branches: [ main, releases/v2.X.X, releases/v6.X.X ] - paths: - - 'src/Liquid.Cache/**' - - pull_request: - branches: [ main, releases/** ] - types: [opened, synchronize, reopened] - paths: - - 'src/Liquid.Cache/**' - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -jobs: - call-reusable-build-workflow: - uses: Avanade/Liquid-Application-Framework/.github/workflows/base-liquid-ci-and-cd.yml@main - with: - component_name: Liquid.Cache - secrets: - sonar_token: ${{ secrets.SONAR_TOKEN_CACHE }} - nuget_token: ${{ secrets.PUBLISH_TO_NUGET_ORG }} diff --git a/.github/workflows/liquid-ci-cd-domain-extensions-crud.yml b/.github/workflows/liquid-ci-cd-domain-extensions-crud.yml deleted file mode 100644 index dd92386..0000000 --- a/.github/workflows/liquid-ci-cd-domain-extensions-crud.yml +++ /dev/null @@ -1,26 +0,0 @@ -# CI & CD workflow -name: CI/CD - Liquid.Domain.Extensions.Crud component for Liquid Application Framework - -on: - push: - branches: [ main, releases/v2.X.X, releases/v6.X.X ] - paths: - - 'src/Liquid.Domain.Extensions.Crud/**' - - pull_request: - branches: [ main, releases/** ] - types: [opened, synchronize, reopened] - paths: - - 'src/Liquid.Domain.Extensions.Crud/**' - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -jobs: - call-reusable-build-workflow: - uses: Avanade/Liquid-Application-Framework/.github/workflows/base-liquid-ci-and-cd.yml@main - with: - component_name: Liquid.Domain.Extensions.Crud - secrets: - sonar_token: ${{ secrets.SONAR_TOKEN_EXT_CRUD }} - nuget_token: ${{ secrets.PUBLISH_TO_NUGET_ORG }} diff --git a/.github/workflows/liquid-ci-cd-domain.yml b/.github/workflows/liquid-ci-cd-domain.yml deleted file mode 100644 index 9a24bb7..0000000 --- a/.github/workflows/liquid-ci-cd-domain.yml +++ /dev/null @@ -1,26 +0,0 @@ -# CI & CD workflow -name: CI/CD - Liquid.Domain component for Liquid Application Framework - -on: - push: - branches: [ main, releases/v2.X.X, releases/v6.X.X ] - paths: - - 'src/Liquid.Domain/**' - - pull_request: - branches: [ main, releases/** ] - types: [opened, synchronize, reopened] - paths: - - 'src/Liquid.Domain/**' - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -jobs: - call-reusable-build-workflow: - uses: Avanade/Liquid-Application-Framework/.github/workflows/base-liquid-ci-and-cd.yml@main - with: - component_name: Liquid.Domain - secrets: - sonar_token: ${{ secrets.SONAR_TOKEN_DOMAIN }} - nuget_token: ${{ secrets.PUBLISH_TO_NUGET_ORG }} diff --git a/.github/workflows/liquid-ci-cd-http-extensions-crud.yml b/.github/workflows/liquid-ci-cd-http-extensions-crud.yml deleted file mode 100644 index 8f60ee8..0000000 --- a/.github/workflows/liquid-ci-cd-http-extensions-crud.yml +++ /dev/null @@ -1,26 +0,0 @@ -# CI & CD workflow -name: CI/CD - Liquid.WebApi.Http.Extensions.Crud component for Liquid Application Framework - -on: - push: - branches: [ main, releases/v2.X.X, releases/v6.X.X ] - paths: - - 'src/Liquid.WebApi.Http.Extensions.Crud/**' - - pull_request: - branches: [ main, releases/** ] - types: [opened, synchronize, reopened] - paths: - - 'src/Liquid.WebApi.Http.Extensions.Crud/**' - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -jobs: - call-reusable-build-workflow: - uses: Avanade/Liquid-Application-Framework/.github/workflows/base-liquid-ci-and-cd.yml@main - with: - component_name: Liquid.WebApi.Http.Extensions.Crud - secrets: - sonar_token: ${{ secrets.SONAR_TOKEN_HTTP_EXT_CRUD }} - nuget_token: ${{ secrets.PUBLISH_TO_NUGET_ORG }} diff --git a/.github/workflows/liquid-ci-cd-messaging.yaml b/.github/workflows/liquid-ci-cd-messaging.yaml deleted file mode 100644 index 5e274cc..0000000 --- a/.github/workflows/liquid-ci-cd-messaging.yaml +++ /dev/null @@ -1,26 +0,0 @@ -# CI & CD workflow -name: CI/CD - Liquid.Messaging component for Liquid Application Framework - -on: - push: - branches: [ main, releases/v2.X.X, releases/v6.X.X ] - paths: - - 'src/Liquid.Messaging/**' - - pull_request: - branches: [ main, releases/** ] - types: [opened, synchronize, reopened] - paths: - - 'src/Liquid.Messaging/**' - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -jobs: - call-reusable-build-workflow: - uses: Avanade/Liquid-Application-Framework/.github/workflows/base-liquid-ci-and-cd.yml@main - with: - component_name: Liquid.Messaging - secrets: - sonar_token: ${{ secrets.SONAR_TOKEN_MESSAGING }} - nuget_token: ${{ secrets.PUBLISH_TO_NUGET_ORG }} diff --git a/.github/workflows/liquid-ci-cd-repository.yml b/.github/workflows/liquid-ci-cd-repository.yml deleted file mode 100644 index 37297d6..0000000 --- a/.github/workflows/liquid-ci-cd-repository.yml +++ /dev/null @@ -1,26 +0,0 @@ -# CI & CD workflow -name: CI/CD - Liquid.Repository component for Liquid Application Framework - -on: - push: - branches: [ main, releases/v2.X.X, releases/v6.X.X ] - paths: - - 'src/Liquid.Repository/**' - - pull_request: - branches: [ main, releases/** ] - types: [opened, synchronize, reopened] - paths: - - 'src/Liquid.Repository/**' - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -jobs: - call-reusable-build-workflow: - uses: Avanade/Liquid-Application-Framework/.github/workflows/base-liquid-ci-and-cd.yml@main - with: - component_name: Liquid.Repository - secrets: - sonar_token: ${{ secrets.SONAR_TOKEN_REPOSITORY }} - nuget_token: ${{ secrets.PUBLISH_TO_NUGET_ORG }} diff --git a/src/Liquid.Core/AbstractMappers/OcrResultMapper.cs b/src/Liquid.Core/AbstractMappers/OcrResultMapper.cs new file mode 100644 index 0000000..3f98b51 --- /dev/null +++ b/src/Liquid.Core/AbstractMappers/OcrResultMapper.cs @@ -0,0 +1,53 @@ +using Liquid.Core.Entities; +using Liquid.Core.Exceptions; +using Liquid.Core.Interfaces; +using System; +using System.Diagnostics.CodeAnalysis; +using System.Threading.Tasks; + +namespace Liquid.Core.AbstractMappers +{ + /// + /// Defines object that map data between two instance types. + /// + /// type of data source object. + [ExcludeFromCodeCoverage] + public abstract class OcrResultMapper : ILiquidMapper + { + private readonly string _mapperName; + + /// + /// Create a new instance of + /// + /// Mapper implementation name. + public OcrResultMapper(string mapperName) + { + _mapperName = mapperName; + } + /// + public async Task Map(TFrom dataObject) + { + if (dataObject is null) + { + throw new ArgumentNullException(nameof(dataObject)); + } + + try + { + return await MapImpl(dataObject); + } + catch (Exception e) + { + var msg = $"{_mapperName} throw data mapping error: '{e.Message}'"; + + throw new DataMappingException(msg, e); + } + } + /// + /// Create a new instance of + /// with values obtained from . + /// + /// data source object instance. + protected abstract Task MapImpl(TFrom dataObject); + } +} diff --git a/src/Liquid.Core/Entities/ChatCompletionResult.cs b/src/Liquid.Core/Entities/ChatCompletionResult.cs new file mode 100644 index 0000000..26fb5fd --- /dev/null +++ b/src/Liquid.Core/Entities/ChatCompletionResult.cs @@ -0,0 +1,24 @@ +namespace Liquid.Core.Entities +{ + /// + /// Chat completions result set. + /// + public class ChatCompletionResult + { + /// + /// The content of the response message. + /// + public string Content { get; set; } + + /// + /// The reason the model stopped generating tokens, together with any applicable details. + /// + public string FinishReason { get; set; } + + /// + /// The total number of tokens processed for the completions request and response. + /// + public int Usage { get; set; } + + } +} diff --git a/src/Liquid.Core/Entities/ChatMessages.cs b/src/Liquid.Core/Entities/ChatMessages.cs new file mode 100644 index 0000000..f3617f5 --- /dev/null +++ b/src/Liquid.Core/Entities/ChatMessages.cs @@ -0,0 +1,35 @@ + +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace Liquid.Core.Entities +{ + /// + /// The object of context messages associated with a chat completions request + /// + [ExcludeFromCodeCoverage] + public class ChatMessages + { + /// + /// The collection of context messages associated with a chat completions request. + /// + public List Messages { get; set; } = new List(); + } + /// + /// Context message associated with a chat completions request. + /// + [ExcludeFromCodeCoverage] + public class ChatMessage + { + /// + /// The chat role associated with this message. + /// + public string Role { get; set; } + + /// + /// The contents of the message. + /// + public string Content { get; set; } + } + +} \ No newline at end of file diff --git a/src/Liquid.Core/Entities/ClientDictionary.cs b/src/Liquid.Core/Entities/ClientDictionary.cs new file mode 100644 index 0000000..050eed7 --- /dev/null +++ b/src/Liquid.Core/Entities/ClientDictionary.cs @@ -0,0 +1,39 @@ +using System.Diagnostics.CodeAnalysis; + +namespace Liquid.Core.Entities +{ + /// + /// Client dictionary to store client instances. + /// + /// Type of client service. + [ExcludeFromCodeCoverage] + public class ClientDictionary + { + /// + /// Number of executions for this client. + /// + public int Executions { get; set; } = 1; + + + /// + /// Client connection alias. + /// + public string ClientId { get; set; } + + /// + /// Client instance. + /// + public T Client { get; set; } + + /// + /// Initialize a new instance of . + /// + /// Client connection alias. + /// Client instance. + public ClientDictionary(string clientId, T client) + { + ClientId = clientId; + Client = client; + } + } +} diff --git a/src/Liquid.Core/Entities/FunctionBody.cs b/src/Liquid.Core/Entities/FunctionBody.cs new file mode 100644 index 0000000..5d51398 --- /dev/null +++ b/src/Liquid.Core/Entities/FunctionBody.cs @@ -0,0 +1,72 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Text.Json; + +namespace Liquid.Core.Entities +{ + /// + /// The body of a function to be called. + /// + [ExcludeFromCodeCoverage] + public class FunctionBody + { + + /// The name of the function to be called. + public string Name { get; set; } + /// + /// A description of what the function does. The model will use this description when selecting the function and + /// interpreting its parameters. + /// + public string Description { get; set; } + /// + /// The parameters the function accepts, described as a JSON Schema object. + /// + /// To assign an object to this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + public BinaryData Parameters { get; set; } + + /// Initializes a new instance of . + /// The name of the function to be called. + /// + /// A description of what the function does. The model will use this description when selecting the function and + /// interpreting its parameters. + /// + /// The parameters the function accepts, described as a JSON Schema object. + /// + /// + public FunctionBody(string name, string description, BinaryData parameters) + { + if (string.IsNullOrEmpty(name)) + { + throw new ArgumentException($"'{nameof(name)}' cannot be null or empty.", nameof(name)); + } + + if (string.IsNullOrEmpty(description)) + { + throw new ArgumentException($"'{nameof(description)}' cannot be null or empty.", nameof(description)); + } + + Name = name; + Description = description; + Parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); + + } + + /// + /// Initializes a new instance of . + /// + /// function definition JSON string. + public FunctionBody(string functionBody) + { + var function = JsonSerializer.Deserialize(functionBody); + + Name = function.GetProperty("name").ToString(); + Description = function.GetProperty("description").ToString(); + Parameters = BinaryData.FromObjectAsJson(function.GetProperty("parameters")); + } + } +} diff --git a/src/Liquid.Core/Entities/OcrResult.cs b/src/Liquid.Core/Entities/OcrResult.cs new file mode 100644 index 0000000..fa67a88 --- /dev/null +++ b/src/Liquid.Core/Entities/OcrResult.cs @@ -0,0 +1,91 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Drawing; + +namespace Liquid.Core.Entities +{ + /// + /// Optical Character Recognition result set. + /// + [ExcludeFromCodeCoverage] + public class OcrResult + { + /// + /// Recognition result content. + /// + public string Content { get; set; } + + /// + ///Analyzed pages. + /// + public List Pages { get; set; } + } + /// + /// Analyzed page content. + /// + [ExcludeFromCodeCoverage] + public class PageInfo + { + /// + /// recognition result page index. + /// + public int PageNumber { get; set; } + + /// + /// The unit used by the words and lines data polygon properties. + /// + public string PolygonUnit { get; set; } + + /// + /// Extracted words from the page. + /// + public List Words { get; set; } = new List(); + + /// + /// Extracted lines from the page. + /// + public List Lines { get; set; } = new List(); + } + /// + /// A word object consisting of a contiguous sequence of characters. + /// + [ExcludeFromCodeCoverage] + public class WordData + { + /// + /// Text content of the word. + /// + public string Content { get; set; } + /// + /// Confidence of correctly extracting the word. + /// + public float Confidence { get; set; } + + /// + /// The polygon that outlines the content of this word. Coordinates are specified relative to the + /// top-left of the page, and points are ordered clockwise from the left relative to the word + /// orientation. + /// + public List Polygon { get; set; } = new List(); + } + + /// + /// A content line object consisting of an adjacent sequence of content elements + /// + [ExcludeFromCodeCoverage] + public class LineData + { + /// + /// Concatenated content of the contained elements in reading order. + /// + public string Content { get; set; } + + /// + /// The polygon that outlines the content of this line. Coordinates are specified relative to the + /// top-left of the page, and points are ordered clockwise from the left relative to the line + /// orientation. + /// + public List Polygon { get; set; } = new List(); + + } +} diff --git a/src/Liquid.Core/Exceptions/DataMappingException.cs b/src/Liquid.Core/Exceptions/DataMappingException.cs new file mode 100644 index 0000000..c627b21 --- /dev/null +++ b/src/Liquid.Core/Exceptions/DataMappingException.cs @@ -0,0 +1,21 @@ +using System; + +namespace Liquid.Core.Exceptions +{ + [Serializable] + internal class DataMappingException : LiquidException + { + public DataMappingException() + { + } + + public DataMappingException(string message) : base(message) + { + } + + public DataMappingException(string message, Exception innerException) : base(message, innerException) + { + } + + } +} diff --git a/src/Liquid.Core/Interfaces/ILiquidChatCompletions.cs b/src/Liquid.Core/Interfaces/ILiquidChatCompletions.cs new file mode 100644 index 0000000..d872c95 --- /dev/null +++ b/src/Liquid.Core/Interfaces/ILiquidChatCompletions.cs @@ -0,0 +1,45 @@ +using Liquid.Core.Entities; +using Liquid.Core.Settings; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Liquid.Core.Interfaces +{ + /// + /// This service is the hub of Liquid adapter custom completions for Generative AI. + /// + public interface ILiquidChatCompletions + { + + /// + /// Get chat completions for provided content and functions. + /// + /// Context messages associated with chat completions request. + /// A list of functions the model may generate JSON inputs for. + /// The options for chat completions request. + Task FunctionCalling(ChatMessages messages, List functions, CompletionsSettings settings); + + /// + /// Get chat completions for provided chat context messages. + /// + /// A request chat message representing an input from the user. + /// A request chat message containing system instructions that influence how the model will generate a chat completions + /// response. + /// The options for chat completions request. + /// The collection of context messages associated with this chat completions request. + /// Typical usage begins with a chat message for the System role that provides instructions for + /// the behavior of the assistant, followed by alternating messages between the User and + /// Assistant roles. + Task ChatCompletions(string content, string prompt, CompletionsSettings settings, ChatMessages? chatHistory = null); + + /// + /// Return the computed embeddings for a given prompt. + /// + /// Input texts to get embeddings for, encoded as a an array of strings. + /// + /// Client connection alias to use for a chat completions request. + /// This connection must be configured in application previously + Task> GetEmbeddings(string description, string modelName, string clientId); + } +} diff --git a/src/Liquid.Core/Interfaces/ILiquidMapper.cs b/src/Liquid.Core/Interfaces/ILiquidMapper.cs new file mode 100644 index 0000000..daf74e2 --- /dev/null +++ b/src/Liquid.Core/Interfaces/ILiquidMapper.cs @@ -0,0 +1,19 @@ +using System.Threading.Tasks; + +namespace Liquid.Core.Interfaces +{ + /// + /// Defines object that map data between two instance types. + /// + /// type of data source object. + /// results object type. + public interface ILiquidMapper + { + /// + /// Create a new instance of + /// with values obtained from . + /// + /// data source object instance. + Task Map(TFrom dataObject); + } +} diff --git a/src/Liquid.Core/Interfaces/ILiquidOcr.cs b/src/Liquid.Core/Interfaces/ILiquidOcr.cs new file mode 100644 index 0000000..3cbe2c6 --- /dev/null +++ b/src/Liquid.Core/Interfaces/ILiquidOcr.cs @@ -0,0 +1,64 @@ +using Liquid.Core.Entities; +using System.IO; +using System.Threading.Tasks; + +namespace Liquid.Ai.Core.Interfaces +{ + /// + /// Service to analyze information from documents and images and extract it into structured data. + /// It provides the ability to use prebuilt models to analyze receipts, + /// business cards, invoices, to extract document content, and more. + /// + public interface ILiquidRecognition + { + /// + /// Analyzes pages from one or more documents, using a model built with custom documents or one of the prebuilt + /// models provided by the Form Recognizer service. + /// + /// The stream containing one or more documents to analyze. + /// + /// The ID of the model to use for analyzing the input documents. When using a custom built model + /// for analysis, this parameter must be the ID attributed to the model during its creation. When + /// using one of the service's prebuilt models, one of the supported prebuilt model IDs must be passed. + /// + /// The ID of the client configuration to use for analyzing the input documents. + /// When using a default instace of client, this parameter don't need to be passed, but it's default value + /// must be configured on application settings. + Task AnalyzeDocumentAsync(Stream doc, string clientId = "default" , string? modelId = "prebuilt-layout"); + + /// + /// Analyzes pages from one or more documents, using a model built with custom documents or one of the prebuilt + /// models provided by the Form Recognizer service. + /// + /// The absolute URI of the remote file to analyze documents from. + /// + /// The ID of the model to use for analyzing the input documents. When using a custom built model + /// for analysis, this parameter must be the ID attributed to the model during its creation. When + /// using one of the service's prebuilt models, one of the supported prebuilt model IDs must be passed. + /// + /// The ID of the client configuration to use for analyzing the input documents. + /// When using a default instace of client, this parameter don't need to be passed, but it's default value + /// must be configured on application settings. + Task AnalyzeDocumentFromUriAsync(string uri, string clientId = "default", string? modelId = "prebuilt-layout"); + + /// + /// Classifies one or more documents using a document classifier built with custom documents. + /// + /// The ID of the document classifier to use. + /// The stream containing one or more documents to classify. + /// The ID of the client configuration to use for analyzing the input documents. + /// When using a default instace of client, this parameter don't need to be passed, but it's default value + /// must be configured on application settings. + Task ClassifyDocumenAsync(Stream doc, string clientId = "default", string? modelId = "prebuilt-layout"); + + /// + /// Classifies one or more documents using a document classifier built with custom documents. + /// + /// The absolute URI of the remote file to classify documents from. + /// The stream containing one or more documents to classify. + /// The ID of the client configuration to use for analyzing the input documents. + /// When using a default instace of client, this parameter don't need to be passed, but it's default value + /// must be configured on application settings. + Task ClassifyDocumenFromUriAsync(string uri, string clientId = "default", string? modelId = "prebuilt-layout"); + } +} diff --git a/src/Liquid.Core/Liquid.Core.csproj b/src/Liquid.Core/Liquid.Core.csproj index e40ff42..55412fe 100644 --- a/src/Liquid.Core/Liquid.Core.csproj +++ b/src/Liquid.Core/Liquid.Core.csproj @@ -10,7 +10,7 @@ Avanade 2019 https://github.com/Avanade/Liquid-Application-Framework logo.png - 8.0.0-alpha-04 + 8.0.0-alpha-05 true {C33A89FC-4F4D-4274-8D0F-29456BA8F76B} true @@ -26,6 +26,7 @@ + diff --git a/src/Liquid.Core/Settings/CompletionsSettings.cs b/src/Liquid.Core/Settings/CompletionsSettings.cs new file mode 100644 index 0000000..c328f0d --- /dev/null +++ b/src/Liquid.Core/Settings/CompletionsSettings.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Liquid.Core.Settings +{ + /// + /// The options for chat completions request. + /// + [ExcludeFromCodeCoverage] + public class CompletionsSettings + { + /// + /// Client connection alias to use for a chat completions request. + /// This connection must be configured in application previously + /// + public string ClientId { get; set; } + /// + /// The deployment name to use for a chat completions request. + /// + public string DeploymentName { get; set; } + + /// + /// The deployment name to use for an embeddings request. + /// + public string EmbeddingModelName { get; set; } + + /// + /// Sampling temperature to use that controls the apparent creativity of generated + /// completions. + /// + public float Temperature { get; set; } = (float)0.7; + + /// + /// Gets the maximum number of tokens to generate. + /// + public int? MaxTokens { get; set; } = null; + + /// + /// An alternative value to , called nucleus sampling, that causes + /// the model to consider the results of the tokens with probability + /// mass. + /// + public float NucleusSamplingFactor { get; set; } = (float)0.95; + + /// + /// Gets or sets a value that influences the probability of generated tokens appearing based on their + /// cumulative frequency in generated text. + /// + public int FrequencyPenalty { get; set; } = 0; + + /// + /// Gets or sets a value that influences the probability of generated tokens appearing based on their + /// existing presence in generated text. + /// + public int PresencePenalty { get; set; } = 0; + } +} diff --git a/src/Liquid.Core/Settings/GenAiOptions.cs b/src/Liquid.Core/Settings/GenAiOptions.cs new file mode 100644 index 0000000..72122f2 --- /dev/null +++ b/src/Liquid.Core/Settings/GenAiOptions.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Liquid.Core.Settings +{ + /// + /// The options for chat completions request. + /// + [ExcludeFromCodeCoverage] + public class GenAiOptions + { + public List Settings { get; set; } + } + + /// + /// The settings for chat completions request. + /// + [ExcludeFromCodeCoverage] + public class GenAiSettings + { + /// + /// Client connection alias. + /// + public string ClientId { get; set; } + /// + /// The URI for an GenAI resource as retrieved from, for example, Azure Portal. + ///This should include protocol and hostname. + /// + public string Url { get; set; } + + /// + /// Key to use to authenticate with the service. + /// + public string Key { get; set; } + + /// + /// The maximum number of retries to allow. + /// + public int MaxRetries { get; set; } = 0; + + /// + /// the maximum delay in milliseconds between retries. + /// + public int RetryMinDelay { get; set; } = 1000; + + /// + /// the maximum delay in milliseconds between retries. + /// + public int RetryMaxDelay { get; set; } = 10000; + + /// + /// if set to true, the delay between retries will grow exponentially, + /// limited by the values of and . + /// Otherwise, the delay will be fixed by the value of . + /// + public bool ExponentialBackoff { get; set; } = false; + } +} diff --git a/src/Liquid.Core/Settings/OcrOptions.cs b/src/Liquid.Core/Settings/OcrOptions.cs new file mode 100644 index 0000000..855040e --- /dev/null +++ b/src/Liquid.Core/Settings/OcrOptions.cs @@ -0,0 +1,38 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace Liquid.Core.Settings +{ + /// + /// Set of OCR service settings. + /// + [ExcludeFromCodeCoverage] + public class OcrOptions + { + /// + /// Collection of OCR service connection settings. + /// + public List Settings { get; set; } + } + + /// + /// OCR service connection settings. + /// + [ExcludeFromCodeCoverage] + public class OcrSettings + { + /// + /// OCR service connection alias. + /// + public string ClientId { get; set; } + /// + /// OCR service absolute Uri. + /// + public string Url { get; set; } + + /// + /// OCR service access key. + /// + public string Key { get; set; } + } +} \ No newline at end of file