From 2696a9850c691e48c0bb73b2c18cf6142d6a2807 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sat, 1 Aug 2026 10:52:50 +0330 Subject: [PATCH] last ... --- Configurations/XAiApiConfiguration.cs | 12 ++++++ Constants/ConfigurationNodeNames.cs | 7 ++++ Constants/XAiModelProviderType.cs | 13 +++++++ Extensions/ChatResponseExtensions.cs | 26 +++++++++++++ Extensions/XAiApiConfigurationExtensions.cs | 42 +++++++++++++++++++++ Models/XAiModelDescriptor.cs | 35 +++++++++++++++++ 6 files changed, 135 insertions(+) create mode 100644 Configurations/XAiApiConfiguration.cs create mode 100644 Constants/ConfigurationNodeNames.cs create mode 100644 Constants/XAiModelProviderType.cs create mode 100644 Extensions/ChatResponseExtensions.cs create mode 100644 Extensions/XAiApiConfigurationExtensions.cs create mode 100644 Models/XAiModelDescriptor.cs diff --git a/Configurations/XAiApiConfiguration.cs b/Configurations/XAiApiConfiguration.cs new file mode 100644 index 0000000..28ef6ef --- /dev/null +++ b/Configurations/XAiApiConfiguration.cs @@ -0,0 +1,12 @@ +using xAiModels.Models; + +namespace xAiModels.Configurations +{ + public class XAiApiConfiguration + { + /// + /// Model Providers ... + /// + public XAiModelDescriptor[] Models { get; set; } = []; + } +} \ No newline at end of file diff --git a/Constants/ConfigurationNodeNames.cs b/Constants/ConfigurationNodeNames.cs new file mode 100644 index 0000000..a38524b --- /dev/null +++ b/Constants/ConfigurationNodeNames.cs @@ -0,0 +1,7 @@ +namespace xAiModels.Constants +{ + public partial struct ConfigurationNodeNames + { + public const string AI_API_NODE = "AiApiConfiguration"; + } +} \ No newline at end of file diff --git a/Constants/XAiModelProviderType.cs b/Constants/XAiModelProviderType.cs new file mode 100644 index 0000000..b7cb76e --- /dev/null +++ b/Constants/XAiModelProviderType.cs @@ -0,0 +1,13 @@ +namespace xAiModels.Constants +{ + /// + /// Specifiy Provider Type ... + /// + public enum XAiModelProviderType + { + None, + Ollama, + DeepSeek, + HuggingFace + } +} \ No newline at end of file diff --git a/Extensions/ChatResponseExtensions.cs b/Extensions/ChatResponseExtensions.cs new file mode 100644 index 0000000..f50a2e2 --- /dev/null +++ b/Extensions/ChatResponseExtensions.cs @@ -0,0 +1,26 @@ +using Microsoft.Extensions.AI; +using xCommons.Extensions; + +namespace xAiModels.Extensions +{ + public static class ChatResponseExtensions + { + /// + /// Validate a Chat Response ... + /// + /// + /// + public static bool IsValid(this ChatResponse source) + { + // + var result = + source is not null && + !source.IsNullOrDefault() && + !string.IsNullOrWhiteSpace(source.Text) && + source.FinishReason == ChatFinishReason.Stop; + + // + return result; + } + } +} \ No newline at end of file diff --git a/Extensions/XAiApiConfigurationExtensions.cs b/Extensions/XAiApiConfigurationExtensions.cs new file mode 100644 index 0000000..f566f78 --- /dev/null +++ b/Extensions/XAiApiConfigurationExtensions.cs @@ -0,0 +1,42 @@ +using System.Linq; +using xAiModels.Configurations; +using xAiModels.Models; +using xCommons.Extensions; + +namespace xAiModels.Extensions +{ + public static class XAiApiConfigurationExtensions + { + /// + /// Validate Api Configuration ... + /// + /// + /// + public static bool IsValid(this XAiApiConfiguration source) + { + return + !source.IsNullOrDefault() && + source.Models.HasChild(); + } + + /// + /// Retrieve Default Model Descriptor ... + /// + /// + /// + public static XAiModelDescriptor GetDefaultModel(this XAiApiConfiguration source) + { + // + XAiModelDescriptor result = null; + + // + if (source.IsValid()) + { + result = source.Models.First(); + } + + // + return result; + } + } +} \ No newline at end of file diff --git a/Models/XAiModelDescriptor.cs b/Models/XAiModelDescriptor.cs new file mode 100644 index 0000000..f23b72a --- /dev/null +++ b/Models/XAiModelDescriptor.cs @@ -0,0 +1,35 @@ +using xAiModels.Constants; + +namespace xAiModels.Models +{ + /// + /// Describe a Provided Model ... + /// + public class XAiModelDescriptor + { + /// + /// Provider Name ... + /// + public string Name { get; set; } + + /// + /// LLM Provider Url ... + /// + public string Url { get; set; } + + /// + /// Model Name ... + /// + public string LLM { get; set; } + + /// + /// Api Key for Connection ... + /// + public string ApiKey { get; set; } + + /// + /// Specified Model Provider Type ... + /// + public XAiModelProviderType Provider { get; set; } = XAiModelProviderType.Ollama; + } +} \ No newline at end of file