From c82de23511b7e20bb7d533b370d8f9a9694e0245 Mon Sep 17 00:00:00 2001 From: Demis Bellot Date: Sat, 29 Jun 2024 11:24:18 +0800 Subject: [PATCH] Add support for ignoring SSL errors for local AI Server --- MyApp.ServiceInterface/Data/AppConfig.cs | 27 +- MyApp.Tests/AiServerTests.cs | 20 + MyApp.Tests/TestUtils.cs | 10 + MyApp.Tests/dtos.cs | 1019 ++++++++++++++++++++++ 4 files changed, 1075 insertions(+), 1 deletion(-) create mode 100644 MyApp.Tests/AiServerTests.cs create mode 100644 MyApp.Tests/dtos.cs diff --git a/MyApp.ServiceInterface/Data/AppConfig.cs b/MyApp.ServiceInterface/Data/AppConfig.cs index 45a33c5..ada3c1b 100644 --- a/MyApp.ServiceInterface/Data/AppConfig.cs +++ b/MyApp.ServiceInterface/Data/AppConfig.cs @@ -1,5 +1,6 @@ using System.Collections.Concurrent; using System.Data; +using System.Net.Http.Headers; using MyApp.ServiceModel; using ServiceStack; using ServiceStack.OrmLite; @@ -24,8 +25,32 @@ public class AppConfig public string? RedditClient { get; set; } public string? RedditSecret { get; set; } public string? RedditAccessToken { get; set; } - public JsonApiClient CreateAiServerClient() => new(AiServerBaseUrl) { BearerToken = AiServerApiKey }; + + public JsonApiClient CreateAiServerClientIgnoringSsl(string baseUrl) + { + var client = new JsonApiClient(AiServerBaseUrl); + + // Ignore local SSL Errors + var handler = HttpUtils.HttpClientHandlerFactory(); + handler.ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, cetChain, policyErrors) => true; + var httpClient = new HttpClient(handler, disposeHandler:client.HttpMessageHandler == null) { + BaseAddress = new Uri(AiServerBaseUrl), + }; + httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AiServerApiKey); + client = new JsonApiClient(httpClient) { + BearerToken = AiServerApiKey + }; + return client; + } + public JsonApiClient CreateAiServerClient() + { + // if (Env.IsLinux && AiServerBaseUrl.StartsWith("https://localhost")) + // return CreateAiServerClientIgnoringSsl(AiServerBaseUrl); + + return new JsonApiClient(AiServerBaseUrl) { BearerToken = AiServerApiKey }; + } + public string CacheDir { get; set; } public string ProfilesDir { get; set; } public string NotificationsEmail { get; set; } = "notifications@pvq.app"; diff --git a/MyApp.Tests/AiServerTests.cs b/MyApp.Tests/AiServerTests.cs new file mode 100644 index 0000000..a67514c --- /dev/null +++ b/MyApp.Tests/AiServerTests.cs @@ -0,0 +1,20 @@ +using AiServer.ServiceModel; +using NUnit.Framework; +using ServiceStack; +using ServiceStack.DataAnnotations; +using ServiceStack.Text; + +namespace MyApp.Tests; + +[Explicit("Requires Local AI Server")] +public class AiServerTests +{ + [Test] + public void Can_QueryApiModels() + { + var client = TestUtils.CreateAiDevClient(); + var api = client.Api(new QueryApiModels()); + api.ThrowIfError(); + api.Response.PrintDump(); + } +} \ No newline at end of file diff --git a/MyApp.Tests/TestUtils.cs b/MyApp.Tests/TestUtils.cs index e76ebc5..887f40b 100644 --- a/MyApp.Tests/TestUtils.cs +++ b/MyApp.Tests/TestUtils.cs @@ -61,5 +61,15 @@ await client.ApiAsync(new Authenticate }); return client; } + + public static JsonApiClient CreateAiDevClient() => new("https://localhost:5005") + { + BearerToken = Environment.GetEnvironmentVariable("AK_PVQ") + }; + public static JsonApiClient CreateAiProdClient() => new("https://openai.servicestack.net") + { + BearerToken = Environment.GetEnvironmentVariable("AK_PVQ") + }; + } \ No newline at end of file diff --git a/MyApp.Tests/dtos.cs b/MyApp.Tests/dtos.cs new file mode 100644 index 0000000..4cd423e --- /dev/null +++ b/MyApp.Tests/dtos.cs @@ -0,0 +1,1019 @@ +/* Options: +Date: 2024-06-27 11:27:42 +Version: 8.31 +Tip: To override a DTO option, remove "//" prefix before updating +BaseUrl: https://localhost:5005 + +//GlobalNamespace: +//MakePartial: True +//MakeVirtual: True +//MakeInternal: False +//MakeDataContractsExtensible: False +//AddNullableAnnotations: False +//AddReturnMarker: True +//AddDescriptionAsComments: True +//AddDataContractAttributes: False +//AddIndexesToDataMembers: False +//AddGeneratedCodeAttributes: False +//AddResponseStatus: False +//AddImplicitVersion: +//InitializeCollections: True +//ExportValueTypes: False +//IncludeTypes: +//ExcludeTypes: +//AddNamespaces: +//AddDefaultXmlNamespace: http://schemas.servicestack.net/types +*/ + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.Serialization; +using ServiceStack; +using ServiceStack.DataAnnotations; +using AiServer.ServiceModel; +using AiServer.ServiceModel.Types; + +namespace AiServer.ServiceModel +{ + public partial class ApiModel + { + public virtual int Id { get; set; } + public virtual string Name { get; set; } + public virtual string Parameters { get; set; } + public virtual int? ContextSize { get; set; } + public virtual string Website { get; set; } + public virtual string Developer { get; set; } + public virtual string Notes { get; set; } + } + + public partial class ApiProvider + { + public ApiProvider() + { + TaskPaths = new Dictionary{}; + Models = new List{}; + } + + public virtual int Id { get; set; } + public virtual string Name { get; set; } + public virtual int ApiTypeId { get; set; } + public virtual string ApiKey { get; set; } + public virtual string ApiKeyHeader { get; set; } + public virtual string ApiBaseUrl { get; set; } + public virtual string HeartbeatUrl { get; set; } + public virtual Dictionary TaskPaths { get; set; } + public virtual int Concurrency { get; set; } + public virtual int Priority { get; set; } + public virtual bool Enabled { get; set; } + public virtual DateTime? OfflineDate { get; set; } + public virtual DateTime CreatedDate { get; set; } + public virtual ApiType ApiType { get; set; } + public virtual List Models { get; set; } + } + + public partial class ApiProviderModel + { + public virtual int Id { get; set; } + public virtual int ApiProviderId { get; set; } + public virtual string Model { get; set; } + public virtual string ApiModel { get; set; } + } + + public partial class ApiType + { + public ApiType() + { + TaskPaths = new Dictionary{}; + ApiModels = new Dictionary{}; + } + + public virtual int Id { get; set; } + public virtual string Name { get; set; } + public virtual string Website { get; set; } + public virtual string ApiBaseUrl { get; set; } + public virtual string HeartbeatUrl { get; set; } + public virtual string OpenAiProvider { get; set; } + public virtual Dictionary TaskPaths { get; set; } + public virtual Dictionary ApiModels { get; set; } + } + + public partial class ChangeApiProviderStatus + : IReturn, IPost + { + public virtual string Provider { get; set; } + public virtual bool Online { get; set; } + } + + public partial class ChatApiProvider + : IReturn, IPost + { + public virtual string Provider { get; set; } + public virtual string Model { get; set; } + public virtual OpenAiChat Request { get; set; } + public virtual string Prompt { get; set; } + } + + public partial class ChatFailedTasks + : IReturn, IPost + { + public ChatFailedTasks() + { + RequeueFailedTaskIds = new List{}; + } + + public virtual bool? ResetErrorState { get; set; } + public virtual List RequeueFailedTaskIds { get; set; } + } + + public partial class ChatNotifyCompletedTasks + : IReturn, IPost + { + public ChatNotifyCompletedTasks() + { + Ids = new List{}; + } + + [Validate("NotEmpty")] + public virtual List Ids { get; set; } + } + + public partial class ChatNotifyCompletedTasksResponse + { + public ChatNotifyCompletedTasksResponse() + { + Errors = new Dictionary{}; + Results = new List{}; + } + + public virtual Dictionary Errors { get; set; } + public virtual List Results { get; set; } + public virtual ResponseStatus ResponseStatus { get; set; } + } + + public partial class ChatOperations + : IReturn, IPost + { + public virtual bool? ResetTaskQueue { get; set; } + public virtual bool? RequeueIncompleteTasks { get; set; } + } + + public partial class Choice + { + /// + ///The reason the model stopped generating tokens. This will be stop if the model hit a natural stop point or a provided stop sequence, length if the maximum number of tokens specified in the request was reached, content_filter if content was omitted due to a flag from our content filters, tool_calls if the model called a tool + /// + [DataMember(Name="finish_reason")] + public virtual string FinishReason { get; set; } + + /// + ///The index of the choice in the list of choices. + /// + [DataMember(Name="index")] + public virtual int Index { get; set; } + + /// + ///A chat completion message generated by the model. + /// + [DataMember(Name="message")] + public virtual ChoiceMessage Message { get; set; } + } + + [DataContract] + public partial class ChoiceMessage + { + public ChoiceMessage() + { + ToolCalls = new ToolCall[]{}; + } + + /// + ///The contents of the message. + /// + [DataMember(Name="content")] + public virtual string Content { get; set; } + + /// + ///The tool calls generated by the model, such as function calls. + /// + [DataMember(Name="tool_calls")] + public virtual ToolCall[] ToolCalls { get; set; } + + /// + ///The role of the author of this message. + /// + [DataMember(Name="role")] + public virtual string Role { get; set; } + } + + public partial class CompleteOpenAiChat + : IReturn, IPost + { + public virtual long Id { get; set; } + public virtual string Provider { get; set; } + public virtual int DurationMs { get; set; } + public virtual OpenAiChatResponse Response { get; set; } + } + + public partial class CreateApiKey + : IReturn, IPost + { + public CreateApiKey() + { + Scopes = new List{}; + Meta = new Dictionary{}; + } + + public virtual string Key { get; set; } + public virtual string Name { get; set; } + public virtual string UserId { get; set; } + public virtual string UserName { get; set; } + public virtual List Scopes { get; set; } + public virtual string Notes { get; set; } + public virtual int? RefId { get; set; } + public virtual string RefIdStr { get; set; } + public virtual Dictionary Meta { get; set; } + } + + public partial class CreateApiKeyResponse + { + public virtual int Id { get; set; } + public virtual string Key { get; set; } + public virtual string Name { get; set; } + public virtual string UserId { get; set; } + public virtual string UserName { get; set; } + public virtual string VisibleKey { get; set; } + public virtual DateTime CreatedDate { get; set; } + public virtual DateTime? ExpiryDate { get; set; } + public virtual DateTime? CancelledDate { get; set; } + public virtual string Notes { get; set; } + } + + /// + ///Different Models available for the API + /// + public partial class CreateApiModel + : IReturn, ICreateDb + { + public virtual string Name { get; set; } + public virtual string Parameters { get; set; } + public virtual string Website { get; set; } + public virtual int? ContextSize { get; set; } + public virtual string Developer { get; set; } + public virtual string Notes { get; set; } + } + + /// + ///Create an API Provider that can process AI Tasks + /// + public partial class CreateApiProvider + : IReturn, ICreateDb + { + /// + ///The unique name for this API Provider + /// + public virtual string Name { get; set; } + /// + ///The behavior for this API Provider + /// + public virtual int ApiTypeId { get; set; } + /// + ///The API Key to use for this Provider + /// + public virtual string ApiKey { get; set; } + /// + ///Send the API Key in the Header instead of Authorization Bearer + /// + public virtual string ApiKeyHeader { get; set; } + /// + ///The Base URL for the API Provider + /// + public virtual string ApiBaseUrl { get; set; } + /// + ///The URL to check if the API Provider is still online + /// + public virtual string HeartbeatUrl { get; set; } + /// + ///Override API Paths for different AI Tasks + /// + public virtual Dictionary TaskPaths { get; set; } + /// + ///How many requests should be made concurrently + /// + public virtual int Concurrency { get; set; } + /// + ///What priority to give this Provider to use for processing models + /// + public virtual int Priority { get; set; } + /// + ///Whether the Provider is enabled + /// + public virtual bool Enabled { get; set; } + /// + ///The models this API Provider can process + /// + public virtual List Models { get; set; } + } + + /// + ///Register a Model supported by an API Provider + /// + public partial class CreateApiProviderModel + : IReturn, ICreateDb + { + /// + ///The ApiProvider Id + /// + public virtual int ApiProviderId { get; set; } + /// + ///Supported ApiModel Name + /// + public virtual string Model { get; set; } + /// + ///Model to use when sending requests to the API Provider + /// + public virtual string ApiModel { get; set; } + } + + public partial class CreateOpenAiChat + : IReturn, ICreateDb + { + public virtual string RefId { get; set; } + public virtual string Provider { get; set; } + public virtual string ReplyTo { get; set; } + public virtual string Tag { get; set; } + public virtual OpenAiChat Request { get; set; } + } + + public partial class CreateOpenAiChatResponse + { + public virtual long Id { get; set; } + public virtual string RefId { get; set; } + public virtual ResponseStatus ResponseStatus { get; set; } + } + + /// + ///Delete a Model supported by the API Provider + /// + public partial class DeleteApiProviderModel + : IReturn, IDeleteDb + { + /// + ///The ApiProviderModel Id + /// + public virtual int Id { get; set; } + } + + public partial class FetchOpenAiChatRequests + : IReturn, IPost + { + public FetchOpenAiChatRequests() + { + Models = new string[]{}; + } + + [Validate("NotEmpty")] + public virtual string[] Models { get; set; } + + [Validate("NotEmpty")] + public virtual string Provider { get; set; } + + public virtual string Worker { get; set; } + public virtual int? Take { get; set; } + } + + public partial class FetchOpenAiChatRequestsResponse + { + public FetchOpenAiChatRequestsResponse() + { + Results = new OpenAiChatRequest[]{}; + } + + public virtual OpenAiChatRequest[] Results { get; set; } + public virtual ResponseStatus ResponseStatus { get; set; } + } + + public partial class FirePeriodicTask + : IReturn, IPost + { + public virtual PeriodicFrequency Frequency { get; set; } + } + + public partial class GetActiveProviders + : IReturn, IGet + { + } + + public partial class GetActiveProvidersResponse + { + public GetActiveProvidersResponse() + { + Results = new ApiProvider[]{}; + } + + public virtual ApiProvider[] Results { get; set; } + public virtual ResponseStatus ResponseStatus { get; set; } + } + + public partial class GetApiWorkerStats + : IReturn, IGet + { + } + + public partial class GetApiWorkerStatsResponse + { + public GetApiWorkerStatsResponse() + { + Results = new List{}; + } + + public virtual List Results { get; set; } + public virtual ResponseStatus ResponseStatus { get; set; } + } + + public partial class GetOpenAiChat + : IReturn, IGet + { + public virtual int? Id { get; set; } + public virtual string RefId { get; set; } + } + + public partial class GetOpenAiChatResponse + { + public virtual OpenAiChatTask Result { get; set; } + public virtual ResponseStatus ResponseStatus { get; set; } + } + + public partial class GetSummaryStats + : IReturn, IGet + { + public virtual DateTime? From { get; set; } + public virtual DateTime? To { get; set; } + } + + public partial class GetSummaryStatsResponse + { + public GetSummaryStatsResponse() + { + ProviderStats = new List{}; + ModelStats = new List{}; + MonthStats = new List{}; + } + + public virtual List ProviderStats { get; set; } + public virtual List ModelStats { get; set; } + public virtual List MonthStats { get; set; } + } + + [Route("/hello/{Name}")] + public partial class Hello + : IReturn, IGet + { + public virtual string Name { get; set; } + } + + public partial class HelloResponse + { + public virtual string Result { get; set; } + } + + /// + ///Given a list of messages comprising a conversation, the model will return a response. + /// + [DataContract] + public partial class OpenAiChat + { + public OpenAiChat() + { + Messages = new List{}; + LogitBias = new Dictionary{}; + Stop = new List{}; + Tools = new List{}; + } + + /// + ///A list of messages comprising the conversation so far. + /// + [DataMember(Name="messages")] + public virtual List Messages { get; set; } + + /// + ///ID of the model to use. See the model endpoint compatibility table for details on which models work with the Chat API + /// + [DataMember(Name="model")] + public virtual string Model { get; set; } + + /// + ///Number between `-2.0` and `2.0`. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. + /// + [DataMember(Name="frequency_penalty")] + public virtual double? FrequencyPenalty { get; set; } + + /// + ///Modify the likelihood of specified tokens appearing in the completion. + /// + [DataMember(Name="logit_bias")] + public virtual Dictionary LogitBias { get; set; } + + /// + ///Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the content of message. + /// + [DataMember(Name="logprobs")] + public virtual bool? LogProbs { get; set; } + + /// + ///An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability. logprobs must be set to true if this parameter is used. + /// + [DataMember(Name="top_logprobs")] + public virtual int? TopLogProbs { get; set; } + + /// + ///The maximum number of tokens that can be generated in the chat completion. + /// + [DataMember(Name="max_tokens")] + public virtual int? MaxTokens { get; set; } + + /// + ///How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep `n` as `1` to minimize costs. + /// + [DataMember(Name="n")] + public virtual int? N { get; set; } + + /// + ///Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. + /// + [DataMember(Name="presence_penalty")] + public virtual double? PresencePenalty { get; set; } + + /// + ///An object specifying the format that the model must output. Compatible with GPT-4 Turbo and all GPT-3.5 Turbo models newer than `gpt-3.5-turbo-1106`. Setting Type to ResponseFormat.JsonObject enables JSON mode, which guarantees the message the model generates is valid JSON. + /// + [DataMember(Name="response_format")] + public virtual OpenAiResponseFormat ResponseFormat { get; set; } + + /// + ///This feature is in Beta. If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend. + /// + [DataMember(Name="seed")] + public virtual int? Seed { get; set; } + + /// + ///Up to 4 sequences where the API will stop generating further tokens. + /// + [DataMember(Name="stop")] + public virtual List Stop { get; set; } + + /// + ///If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a `data: [DONE]` message. + /// + [DataMember(Name="stream")] + public virtual bool? Stream { get; set; } + + /// + ///What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. + /// + [DataMember(Name="temperature")] + public virtual double? Temperature { get; set; } + + /// + ///An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. + /// + [DataMember(Name="top_p")] + public virtual double TopP { get; set; } + + /// + ///A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported. + /// + [DataMember(Name="tools")] + public virtual List Tools { get; set; } + + /// + ///A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. + /// + [DataMember(Name="user")] + public virtual string User { get; set; } + } + + [DataContract] + public partial class OpenAiChatResponse + { + public OpenAiChatResponse() + { + Choices = new List{}; + } + + /// + ///A unique identifier for the chat completion. + /// + [DataMember(Name="id")] + public virtual string Id { get; set; } + + /// + ///A list of chat completion choices. Can be more than one if n is greater than 1. + /// + [DataMember(Name="choices")] + public virtual List Choices { get; set; } + + /// + ///The Unix timestamp (in seconds) of when the chat completion was created. + /// + [DataMember(Name="created")] + public virtual long Created { get; set; } + + /// + ///The model used for the chat completion. + /// + [DataMember(Name="model")] + public virtual string Model { get; set; } + + /// + ///This fingerprint represents the backend configuration that the model runs with. + /// + [DataMember(Name="system_fingerprint")] + public virtual string SystemFingerprint { get; set; } + + /// + ///The object type, which is always chat.completion. + /// + [DataMember(Name="object")] + public virtual string Object { get; set; } + + /// + ///Usage statistics for the completion request. + /// + [DataMember(Name="usage")] + public virtual OpenAiUsage Usage { get; set; } + } + + /// + ///A list of messages comprising the conversation so far. + /// + [DataContract] + public partial class OpenAiMessage + { + public OpenAiMessage() + { + ToolCalls = new ToolCall[]{}; + } + + /// + ///The contents of the message. + /// + [DataMember(Name="content")] + public virtual string Content { get; set; } + + /// + ///The role of the author of this message. Valid values are `system`, `user`, `assistant` and `tool`. + /// + [DataMember(Name="role")] + public virtual string Role { get; set; } + + /// + ///An optional name for the participant. Provides the model information to differentiate between participants of the same role. + /// + [DataMember(Name="name")] + public virtual string Name { get; set; } + + /// + ///The tool calls generated by the model, such as function calls. + /// + [DataMember(Name="tool_calls")] + public virtual ToolCall[] ToolCalls { get; set; } + + /// + ///Tool call that this message is responding to. + /// + [DataMember(Name="tool_call_id")] + public virtual string ToolCallId { get; set; } + } + + [DataContract] + public partial class OpenAiResponseFormat + { + /// + ///An object specifying the format that the model must output. Compatible with GPT-4 Turbo and all GPT-3.5 Turbo models newer than gpt-3.5-turbo-1106. + /// + [DataMember(Name="response_format")] + public virtual ResponseFormat Type { get; set; } + } + + [DataContract] + public partial class OpenAiTools + { + /// + ///The type of the tool. Currently, only function is supported. + /// + [DataMember(Name="type")] + public virtual OpenAiToolType Type { get; set; } + } + + public enum OpenAiToolType + { + [EnumMember(Value="function")] + Function, + } + + /// + ///Usage statistics for the completion request. + /// + [DataContract] + public partial class OpenAiUsage + { + /// + ///Number of tokens in the generated completion. + /// + [DataMember(Name="completion_tokens")] + public virtual int CompletionTokens { get; set; } + + /// + ///Number of tokens in the prompt. + /// + [DataMember(Name="prompt_tokens")] + public virtual int PromptTokens { get; set; } + + /// + ///Total number of tokens used in the request (prompt + completion). + /// + [DataMember(Name="total_tokens")] + public virtual int TotalTokens { get; set; } + } + + /// + ///Different Models available in AI Server + /// + public partial class QueryApiModels + : QueryDb, IReturn> + { + } + + /// + ///View and API Provider Models + /// + public partial class QueryApiProviderModels + : QueryDb, IReturn> + { + public virtual int? ApiProviderId { get; set; } + public virtual string Model { get; set; } + public virtual string ApiModel { get; set; } + } + + /// + ///API Providers that can process AI Tasks + /// + public partial class QueryApiProviders + : QueryDb, IReturn> + { + public virtual string Name { get; set; } + } + + /// + ///The Type and behavior of different API Providers + /// + public partial class QueryApiType + : QueryDb, IReturn> + { + } + + public partial class QueryCompletedChatTasks + : QueryDb, IReturn> + { + public virtual string Db { get; set; } + public virtual int? Id { get; set; } + public virtual string RefId { get; set; } + } + + public partial class QueryFailedChatTasks + : QueryDb, IReturn> + { + public virtual string Db { get; set; } + } + + public partial class QueryOpenAiChat + : QueryDb, IReturn> + { + public virtual int? Id { get; set; } + public virtual string RefId { get; set; } + } + + public partial class QueryTaskSummary + : QueryDb, IReturn> + { + } + + public partial class RerunCompletedTasks + : IReturn, IPost + { + public RerunCompletedTasks() + { + Ids = new List{}; + } + + public virtual List Ids { get; set; } + } + + public partial class RerunCompletedTasksResponse + { + public RerunCompletedTasksResponse() + { + Errors = new Dictionary{}; + Results = new List{}; + } + + public virtual Dictionary Errors { get; set; } + public virtual List Results { get; set; } + public virtual ResponseStatus ResponseStatus { get; set; } + } + + public partial class ResetActiveProviders + : IReturn, IGet + { + } + + public enum ResponseFormat + { + [EnumMember(Value="text")] + Text, + [EnumMember(Value="json_object")] + JsonObject, + } + + public partial class RestartWorkers + : IReturn, IPost + { + } + + public partial class StartWorkers + : IReturn, IPost + { + } + + public partial class StopWorkers + : IReturn, IPost + { + } + + public partial class SummaryStats + { + public virtual string Name { get; set; } + public virtual int TotalTasks { get; set; } + public virtual int TotalPromptTokens { get; set; } + public virtual int TotalCompletionTokens { get; set; } + public virtual double TotalMinutes { get; set; } + public virtual double TokensPerSecond { get; set; } + } + + public partial class TaskBase + { + public virtual long Id { get; set; } + public virtual string Model { get; set; } + public virtual string Provider { get; set; } + public virtual string RefId { get; set; } + public virtual string Tag { get; set; } + public virtual string ReplyTo { get; set; } + public virtual DateTime CreatedDate { get; set; } + public virtual string CreatedBy { get; set; } + public virtual string Worker { get; set; } + public virtual string WorkerIp { get; set; } + public virtual string RequestId { get; set; } + public virtual DateTime? StartedDate { get; set; } + public virtual DateTime? CompletedDate { get; set; } + public virtual int DurationMs { get; set; } + public virtual int? RetryLimit { get; set; } + public virtual int Retries { get; set; } + public virtual DateTime? NotificationDate { get; set; } + public virtual string ErrorCode { get; set; } + public virtual ResponseStatus Error { get; set; } + } + + public partial class TaskSummary + { + public virtual long Id { get; set; } + public virtual TaskType Type { get; set; } + public virtual string Model { get; set; } + public virtual string Provider { get; set; } + public virtual string RefId { get; set; } + public virtual string Tag { get; set; } + public virtual int PromptTokens { get; set; } + public virtual int CompletionTokens { get; set; } + public virtual int DurationMs { get; set; } + public virtual DateTime CreatedDate { get; set; } + } + + public enum TaskType + { + OpenAiChat = 1, + } + + /// + ///The tool calls generated by the model, such as function calls. + /// + [DataContract] + public partial class ToolCall + { + /// + ///The ID of the tool call. + /// + [DataMember(Name="id")] + public virtual string Id { get; set; } + + /// + ///The type of the tool. Currently, only `function` is supported. + /// + [DataMember(Name="type")] + public virtual string Type { get; set; } + + /// + ///The function that the model called. + /// + [DataMember(Name="function")] + public virtual string Function { get; set; } + } + + public partial class UpdateApiProvider + : IReturn, IPatchDb + { + public virtual int Id { get; set; } + public virtual string ApiKey { get; set; } + public virtual string ApiBaseUrl { get; set; } + public virtual string HeartbeatUrl { get; set; } + public virtual int? Concurrency { get; set; } + public virtual int? Priority { get; set; } + public virtual bool? Enabled { get; set; } + } + + /// + ///Update the Model supported by the API Provider + /// + public partial class UpdateApiProviderModel + : IReturn, IPatchDb + { + /// + ///The ApiProviderModel Id + /// + public virtual int Id { get; set; } + /// + ///The ApiProvider Id + /// + public virtual int? ApiProviderId { get; set; } + /// + ///Supported ApiModel Name + /// + public virtual string Model { get; set; } + /// + ///Model to use when sending requests to the API Provider + /// + public virtual string ApiModel { get; set; } + } + + public partial class WorkerStats + { + public virtual string Name { get; set; } + public virtual long Queued { get; set; } + public virtual long Received { get; set; } + public virtual long Completed { get; set; } + public virtual long Retries { get; set; } + public virtual long Failed { get; set; } + public virtual DateTime? Offline { get; set; } + public virtual bool Running { get; set; } + } + +} + +namespace AiServer.ServiceModel.Types +{ + public partial class OpenAiChatCompleted + : OpenAiChatTask + { + } + + public partial class OpenAiChatFailed + : OpenAiChatTask + { + public virtual DateTime FailedDate { get; set; } + } + + public partial class OpenAiChatRequest + { + public virtual long Id { get; set; } + public virtual string Model { get; set; } + public virtual string Provider { get; set; } + public virtual OpenAiChat Request { get; set; } + } + + public partial class OpenAiChatTask + : TaskBase + { + public virtual OpenAiChat Request { get; set; } + public virtual OpenAiChatResponse Response { get; set; } + } + + public enum PeriodicFrequency + { + Minute, + Hourly, + Daily, + Monthly, + } + +} +