diff --git a/DI/XDIHelperExtension.cs b/DI/XDIHelperExtension.cs
index b035f5e..40548ee 100644
--- a/DI/XDIHelperExtension.cs
+++ b/DI/XDIHelperExtension.cs
@@ -1,5 +1,41 @@
+using System.Net.Http;
+using System.Threading;
+using xAiModels.Constants;
+using xAiService.Services;
+using Microsoft.Extensions.DependencyInjection;
+
namespace xAiService.DI
{
public static partial class XDIHelperExtension
- { }
+ {
+ ///
+ /// Register XAiMcpClient in DI ...
+ ///
+ ///
+ public static void AddXAiMcpClient(
+ this IServiceCollection source
+ )
+ {
+ //
+ // Register Http Client ...
+ source.AddHttpClient(
+ XAiMcpConstants.XAiMcpClientName,
+ client =>
+ {
+ client.Timeout = Timeout.InfiniteTimeSpan;
+ }
+ )
+ .ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
+ {
+ ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true
+ });
+
+ //
+ source.AddScoped();
+ source.AddSingleton();
+
+ //
+ source.AddHostedService();
+ }
+ }
}
\ No newline at end of file
diff --git a/Extensions/XAiServiceExtensions.cs b/Extensions/XAiServiceExtensions.cs
index 7272d06..5160f42 100644
--- a/Extensions/XAiServiceExtensions.cs
+++ b/Extensions/XAiServiceExtensions.cs
@@ -1,6 +1,10 @@
+using xAiModels.Models;
using xCommons.Extensions;
+using xAiService.Services;
using xExceptions.Constants;
using xIdentityModels.Models;
+using Microsoft.Extensions.AI;
+using System.Collections.Generic;
namespace xAiService.Extensions
{
@@ -40,5 +44,35 @@ namespace xAiService.Extensions
invalidException.Throw();
}
}
+
+ ///
+ /// Converts To AITools ...
+ ///
+ ///
+ ///
+ ///
+ public static IList ToAITools(
+ this IList source,
+ XAiMcpClient client
+ )
+ {
+ //
+ if (client.IsNullOrDefault())
+ {
+ XException.InvalidArgs.Throw();
+ }
+
+ //
+ var result = new List();
+
+ //
+ foreach (var tool in source)
+ {
+ result.Add(new XAiMcpAIFunction(client, tool));
+ }
+
+ //
+ return result;
+ }
}
}
\ No newline at end of file
diff --git a/Services/XAiMcpAIFunction.cs b/Services/XAiMcpAIFunction.cs
new file mode 100644
index 0000000..6401efd
--- /dev/null
+++ b/Services/XAiMcpAIFunction.cs
@@ -0,0 +1,86 @@
+using System.Text.Json;
+using System.Threading;
+using xAiModels.Models;
+using xCommons.Extensions;
+using xExceptions.Constants;
+using System.Text.Json.Nodes;
+using System.Threading.Tasks;
+using Microsoft.Extensions.AI;
+
+namespace xAiService.Services
+{
+ ///
+ /// a Customized AIFunction Implementation ...
+ ///
+ public class XAiMcpAIFunction : AIFunction
+ {
+ //
+ private readonly XAiMcpClient client;
+ private readonly JsonElement jsonSchema;
+ private readonly XAiMcpToolDefinition definition;
+
+ public XAiMcpAIFunction(
+ XAiMcpClient client,
+ XAiMcpToolDefinition definition
+ )
+ {
+ //
+ if (client.IsNull() || definition.IsNull())
+ {
+ XException.InvalidArgs.Throw();
+ }
+
+ //
+ this.client = client;
+ this.definition = definition;
+
+ //
+ jsonSchema = definition.InputSchema.Clone();
+ }
+
+ //
+ public override string Name => definition.Name;
+ public override JsonElement JsonSchema => jsonSchema;
+ public override string Description => definition.Description;
+
+ ///
+ /// Invoke Tool ...
+ ///
+ ///
+ ///
+ ///
+ protected override async ValueTask