last ...
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using xAiService.Models;
|
||||||
|
|
||||||
|
namespace xAiService.Configurations
|
||||||
|
{
|
||||||
|
public partial class XAIServiceConfiguration
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// List of Text Generator Models ...
|
||||||
|
/// </summary>
|
||||||
|
/// <value></value>
|
||||||
|
public Dictionary<string, XAILLMDescriptor> TextGenerators { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// List of Image Generator Models ...
|
||||||
|
/// </summary>
|
||||||
|
/// <value></value>
|
||||||
|
public Dictionary<string, XAILLMDescriptor> ImageGenerators { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace xAiService.Constants
|
||||||
|
{
|
||||||
|
public partial struct ConfigurationNodeNames
|
||||||
|
{
|
||||||
|
public const string AI_SERVICE_NODE = "AIServiceConfiguration";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using xAiService.Configurations;
|
||||||
|
using xAiService.Constants;
|
||||||
|
using xAiService.Extensions;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xExceptions.Constants;
|
||||||
|
|
||||||
|
namespace xAiService.DI
|
||||||
|
{
|
||||||
|
public static partial class XDIHelperExtension
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Extract AI Service Configuration ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static XAIServiceConfiguration GetXAIServiceConfiguration(this IConfiguration source)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XAIServiceConfiguration result = null;
|
||||||
|
|
||||||
|
//
|
||||||
|
var section = source.GetSection(ConfigurationNodeNames.AI_SERVICE_NODE);
|
||||||
|
if (!section.IsNull())
|
||||||
|
{
|
||||||
|
result = section.Get<XAIServiceConfiguration>();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add AI Service Configuration ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="configuration"></param>
|
||||||
|
public static void AddXAIServiceConfiguration(
|
||||||
|
this IServiceCollection source,
|
||||||
|
XAIServiceConfiguration configuration
|
||||||
|
)
|
||||||
|
{
|
||||||
|
source.AddSingleton<XAIServiceConfiguration>(configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddXAIService(
|
||||||
|
this IServiceCollection services,
|
||||||
|
IConfiguration configuration,
|
||||||
|
ServiceLifetime lifeTime = ServiceLifetime.Singleton
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var config = configuration.GetXAIServiceConfiguration();
|
||||||
|
AddAIService(
|
||||||
|
services,
|
||||||
|
config
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddXAIService(
|
||||||
|
this IServiceCollection services,
|
||||||
|
XAIServiceConfiguration configuration,
|
||||||
|
ServiceLifetime lifeTime = ServiceLifetime.Singleton
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
AddAIService(
|
||||||
|
services,
|
||||||
|
configuration
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Private ...
|
||||||
|
/// <summary>
|
||||||
|
/// a LogTag for Service ...
|
||||||
|
/// </summary>
|
||||||
|
private static string XLogTag = "XFileService";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// print a log in Console ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message"></param>
|
||||||
|
private static void Log(string message)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{XLogTag} => {message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddAIService(
|
||||||
|
this IServiceCollection services,
|
||||||
|
XAIServiceConfiguration configuration,
|
||||||
|
ServiceLifetime lifeTime = ServiceLifetime.Singleton
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var exception = XException.InvalidArgs.ToException(); ;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Services ...
|
||||||
|
var isServicesExists = !services.IsNull();
|
||||||
|
if (!isServicesExists)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
Log("AddAIService failed, services not provided ...");
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Lifetime ...
|
||||||
|
var isLifetimeExists = !lifeTime.IsNull();
|
||||||
|
if (!isLifetimeExists)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
Log("AddAIService failed, lifetime not provided ...");
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Dependencies Exists ...
|
||||||
|
var isDependenciesPassed = true;
|
||||||
|
if (!isDependenciesPassed)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
Log("AddAIService failed due Dependencies Issues, not provided ...");
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Configurations ...
|
||||||
|
var isConfigurationExists =
|
||||||
|
!configuration.IsNull() &&
|
||||||
|
configuration.IsValid();
|
||||||
|
if (!isConfigurationExists)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
Log("AddAIService failed due InValid Service Configuration or not provided ...");
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register Configurations ...
|
||||||
|
services.AddXAIServiceConfiguration(configuration);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register Services ...
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
using xAiService.Configurations;
|
||||||
|
using xAiService.Models;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
|
||||||
|
namespace xAiService.Extensions
|
||||||
|
{
|
||||||
|
public static class ModelExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Validating LLM Descriptor ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool IsValid(this XAILLMDescriptor source)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result =
|
||||||
|
!source.IsNull() &&
|
||||||
|
!source.Url.IsNullOrEmpty() &&
|
||||||
|
!source.Client.IsNullOrEmpty();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate XAIServiceConfiguration ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool IsValid(this XAIServiceConfiguration source)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result =
|
||||||
|
!source.IsNull() &&
|
||||||
|
(source.TextGenerators.Count > 0);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using AutoMapper.Configuration.Conventions;
|
||||||
|
|
||||||
|
namespace xAiService.Models
|
||||||
|
{
|
||||||
|
public class XAILLMDescriptor
|
||||||
|
{
|
||||||
|
public string Url { get; set; }
|
||||||
|
public string Port { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Client { get; set; }
|
||||||
|
public string Descriptor { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,7 +15,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyDescriptionAttribute(("\r\n it is a Part of xSaherElm project which Provides Services to use xSaherEl" +
|
[assembly: System.Reflection.AssemblyDescriptionAttribute(("\r\n it is a Part of xSaherElm project which Provides Services to use xSaherEl" +
|
||||||
"m AI Features ...\r\n "))]
|
"m AI Features ...\r\n "))]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+bbaa05905fc5dfb9bc9282f094c2d3248b9e486d")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c538f9555ab8bfc86ea124ed5bfbd2d63c27f7f9")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("xAiService")]
|
[assembly: System.Reflection.AssemblyProductAttribute("xAiService")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("xAiService")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("xAiService")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
17bf4170f79b796f881d5d7ca98bdf22aaf9999471d839ed8109b7226a063919
|
67816ea562b25f672b311e2c73d380d615ccf404089ec562f84575f6211c1c89
|
||||||
|
|||||||
Reference in New Issue
Block a user