last ...
This commit is contained in:
@@ -12,7 +12,9 @@ namespace xAiApi.Constants
|
|||||||
public const string XAiApiIntroductionPromptName = "Introduction";
|
public const string XAiApiIntroductionPromptName = "Introduction";
|
||||||
|
|
||||||
//
|
//
|
||||||
|
public const string XAiDefaultModelName = "Gemma";
|
||||||
public const string XAiEmbeddingModelName = "Embed";
|
public const string XAiEmbeddingModelName = "Embed";
|
||||||
|
public const string XAiDefaultThinkingModelName = "Qwen";
|
||||||
public const string XAiEmbeddingPromptName = "Embedding";
|
public const string XAiEmbeddingPromptName = "Embedding";
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using xAiApi.Interfaces;
|
||||||
|
using xCommons.Configurations;
|
||||||
|
using xCommons.Providers;
|
||||||
|
|
||||||
|
namespace xAiApi.Controllers
|
||||||
|
{
|
||||||
|
public class DefaultThinkingAiController : XAiServiceControllerBase<IXDefaultThinkingAiService>
|
||||||
|
{
|
||||||
|
public DefaultThinkingAiController(
|
||||||
|
ILogger<DefaultThinkingAiController> logger,
|
||||||
|
IXDefaultThinkingAiService aiService,
|
||||||
|
XAppConfiguration appConfiguration,
|
||||||
|
XValidationProvider validationProvider
|
||||||
|
) : base(logger, aiService, appConfiguration, validationProvider)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using xAiModels.Models;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.AI;
|
using Microsoft.Extensions.AI;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace xAiApi.Interfaces
|
namespace xAiApi.Interfaces
|
||||||
{
|
{
|
||||||
@@ -12,6 +13,16 @@ namespace xAiApi.Interfaces
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IXAiServiceBase : IDisposable
|
public interface IXAiServiceBase : IDisposable
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Chat Options ...
|
||||||
|
/// </summary>
|
||||||
|
ChatOptions Options { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Descriptor of Models which used in Service ...
|
||||||
|
/// </summary>
|
||||||
|
XAiModelDescriptor Descriptor { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Base Method for Communicate with LLM ...
|
/// Base Method for Communicate with LLM ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -37,9 +48,8 @@ namespace xAiApi.Interfaces
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get LLM Client instance for Communicating with LLM ...
|
/// Get LLM Client instance for Communicating with LLM ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="llm"></param>
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IChatClient GetClient(string llm = null);
|
IChatClient GetClient();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create Custom HttpClient for Communicating with LLM API ...
|
/// Create Custom HttpClient for Communicating with LLM API ...
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
namespace xAiApi.Interfaces
|
||||||
|
{
|
||||||
|
public interface IXDefaultThinkingAiService: IXAiServiceBase
|
||||||
|
{ }
|
||||||
|
}
|
||||||
+32
-17
@@ -4,6 +4,7 @@ using OllamaSharp;
|
|||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using xAiApi.Constants;
|
using xAiApi.Constants;
|
||||||
|
using xAiModels.Models;
|
||||||
using xAiApi.Interfaces;
|
using xAiApi.Interfaces;
|
||||||
using xAiApi.Extensions;
|
using xAiApi.Extensions;
|
||||||
using System.ClientModel;
|
using System.ClientModel;
|
||||||
@@ -24,6 +25,16 @@ namespace xAiApi.Providers
|
|||||||
{
|
{
|
||||||
public abstract class XAIServiceBase : IXAiServiceBase
|
public abstract class XAIServiceBase : IXAiServiceBase
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Chat Options ...
|
||||||
|
/// </summary>
|
||||||
|
public ChatOptions Options { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Descriptor of Models which used in Service ...
|
||||||
|
/// </summary>
|
||||||
|
public XAiModelDescriptor Descriptor { get; }
|
||||||
|
|
||||||
private readonly IXAiDataProvider dataProvider;
|
private readonly IXAiDataProvider dataProvider;
|
||||||
private readonly ILogger<XAIServiceBase> logger;
|
private readonly ILogger<XAIServiceBase> logger;
|
||||||
private readonly XAiApiConfiguration configuration;
|
private readonly XAiApiConfiguration configuration;
|
||||||
@@ -31,12 +42,25 @@ namespace xAiApi.Providers
|
|||||||
protected XAIServiceBase(
|
protected XAIServiceBase(
|
||||||
IXAiDataProvider dataProvider,
|
IXAiDataProvider dataProvider,
|
||||||
ILogger<XAIServiceBase> logger,
|
ILogger<XAIServiceBase> logger,
|
||||||
XAiApiConfiguration configuration
|
XAiApiConfiguration configuration,
|
||||||
|
string model = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.dataProvider = dataProvider;
|
this.dataProvider = dataProvider;
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Prepare Embedding Model Descriptor ...
|
||||||
|
Descriptor = configuration.GetModel(model);
|
||||||
|
if (!Descriptor.IsValid())
|
||||||
|
{
|
||||||
|
XException.InvalidConfiguration.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Prepare Chat Options based On Tools ...
|
||||||
|
Options = new ChatOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -130,28 +154,19 @@ namespace xAiApi.Providers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get LLM Client instance for Communicating with LLM ...
|
/// Get LLM Client instance for Communicating with LLM ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="llm"></param>
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual IChatClient GetClient(string llm = null)
|
public virtual IChatClient GetClient()
|
||||||
{
|
{
|
||||||
//
|
|
||||||
// Retrieve Model Descriptor ...
|
|
||||||
var modelDescriptor = configuration.GetModel(llm);
|
|
||||||
if (modelDescriptor.IsNullOrDefault())
|
|
||||||
{
|
|
||||||
XException.NotFound.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Try to Initialize LLm ...
|
// Try to Initialize LLm ...
|
||||||
var model = modelDescriptor.LLM;
|
var model = Descriptor.LLM;
|
||||||
var apiKey = modelDescriptor.ApiKey;
|
var apiKey = Descriptor.ApiKey;
|
||||||
var url = new Uri(modelDescriptor.Url);
|
var url = new Uri(Descriptor.Url);
|
||||||
var httpClient = GetHttpClient(modelDescriptor.Url);
|
var httpClient = GetHttpClient(Descriptor.Url);
|
||||||
|
|
||||||
//
|
//
|
||||||
IChatClient result = null;
|
IChatClient result = null;
|
||||||
switch (modelDescriptor.Provider)
|
switch (Descriptor.Provider)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
case XAiModelProviderType.Ollama:
|
case XAiModelProviderType.Ollama:
|
||||||
@@ -163,7 +178,7 @@ namespace xAiApi.Providers
|
|||||||
.UseFunctionInvocation()
|
.UseFunctionInvocation()
|
||||||
.Build();
|
.Build();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//
|
//
|
||||||
case XAiModelProviderType.OpenAI:
|
case XAiModelProviderType.OpenAI:
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using OpenAI;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OllamaSharp;
|
using OllamaSharp;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -6,20 +7,18 @@ using xAiApi.Constants;
|
|||||||
using xAiModels.Models;
|
using xAiModels.Models;
|
||||||
using xAiApi.Extensions;
|
using xAiApi.Extensions;
|
||||||
using xAiApi.Interfaces;
|
using xAiApi.Interfaces;
|
||||||
using OllamaSharp.Models;
|
|
||||||
using xAiService.Helpers;
|
using xAiService.Helpers;
|
||||||
|
using System.ClientModel;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
|
using xAiModels.Constants;
|
||||||
using xAiModels.Extensions;
|
using xAiModels.Extensions;
|
||||||
using xAiModels.Interfaces;
|
using xAiModels.Interfaces;
|
||||||
using xAiApi.Configurations;
|
using xAiApi.Configurations;
|
||||||
using xExceptions.Constants;
|
using xExceptions.Constants;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.AI;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.AI;
|
|
||||||
using xAiModels.Constants;
|
|
||||||
using OpenAI;
|
|
||||||
using System.ClientModel;
|
|
||||||
using System.ClientModel.Primitives;
|
using System.ClientModel.Primitives;
|
||||||
|
|
||||||
namespace xAiApi.Providers
|
namespace xAiApi.Providers
|
||||||
@@ -37,7 +36,7 @@ namespace xAiApi.Providers
|
|||||||
XAiApiConfiguration configuration,
|
XAiApiConfiguration configuration,
|
||||||
ILogger<XAiEmbeddingServiceBase> logger,
|
ILogger<XAiEmbeddingServiceBase> logger,
|
||||||
string embeddingModelName = XAiApiConstants.XAiEmbeddingModelName
|
string embeddingModelName = XAiApiConstants.XAiEmbeddingModelName
|
||||||
) : base(dataProvider, logger, configuration)
|
) : base(dataProvider, logger, configuration, null)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Prepare Embedding Model Descriptor ...
|
// Prepare Embedding Model Descriptor ...
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using xAiApi.Constants;
|
||||||
using xAiApi.Configurations;
|
|
||||||
using xAiApi.Interfaces;
|
using xAiApi.Interfaces;
|
||||||
using xAiModels.Interfaces;
|
using xAiModels.Interfaces;
|
||||||
|
using xAiApi.Configurations;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace xAiApi.Providers
|
namespace xAiApi.Providers
|
||||||
{
|
{
|
||||||
@@ -14,7 +15,8 @@ namespace xAiApi.Providers
|
|||||||
) : base(
|
) : base(
|
||||||
dataProvider,
|
dataProvider,
|
||||||
logger,
|
logger,
|
||||||
configuration
|
configuration,
|
||||||
|
XAiApiConstants.XAiDefaultModelName
|
||||||
)
|
)
|
||||||
{ }
|
{ }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using xAiApi.Constants;
|
||||||
using xAiApi.Configurations;
|
|
||||||
using xAiApi.Interfaces;
|
using xAiApi.Interfaces;
|
||||||
using xAiModels.Interfaces;
|
using xAiModels.Interfaces;
|
||||||
|
using xAiApi.Configurations;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace xAiApi.Providers
|
namespace xAiApi.Providers
|
||||||
{
|
{
|
||||||
@@ -14,7 +15,8 @@ namespace xAiApi.Providers
|
|||||||
) : base(
|
) : base(
|
||||||
dataProvider,
|
dataProvider,
|
||||||
configuration,
|
configuration,
|
||||||
logger
|
logger,
|
||||||
|
XAiApiConstants.XAiEmbeddingModelName
|
||||||
)
|
)
|
||||||
{ }
|
{ }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
using xAiApi.Constants;
|
||||||
|
using xAiApi.Interfaces;
|
||||||
|
using xAiModels.Interfaces;
|
||||||
|
using xAiApi.Configurations;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.AI;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
|
||||||
|
namespace xAiApi.Providers
|
||||||
|
{
|
||||||
|
public class XDefaultThinkingAiService : XAIServiceBase, IXDefaultThinkingAiService
|
||||||
|
{
|
||||||
|
public XDefaultThinkingAiService(
|
||||||
|
IXAiDataProvider dataProvider,
|
||||||
|
ILogger<XAIServiceBase> logger,
|
||||||
|
XAiApiConfiguration configuration,
|
||||||
|
ReasoningEffort effort = ReasoningEffort.Medium,
|
||||||
|
ReasoningOutput output = ReasoningOutput.Full
|
||||||
|
) : base(
|
||||||
|
dataProvider,
|
||||||
|
logger,
|
||||||
|
configuration,
|
||||||
|
XAiApiConstants.XAiDefaultThinkingModelName
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Preparing Reasoning ...
|
||||||
|
Options.Reasoning = new ReasoningOptions
|
||||||
|
{
|
||||||
|
Output = output,
|
||||||
|
Effort = effort,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
-5
@@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using xAiApi.DI;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using xAiModels.DI;
|
||||||
using xTagService.DI;
|
using xTagService.DI;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using xAiApi.Database;
|
using xAiApi.Database;
|
||||||
@@ -9,13 +11,16 @@ using xPushService.DI;
|
|||||||
using xFileService.DI;
|
using xFileService.DI;
|
||||||
using xDataService.DI;
|
using xDataService.DI;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using xAiApi.Providers;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using xAiApi.Extensions;
|
using xAiApi.Extensions;
|
||||||
using xStringService.DI;
|
using xStringService.DI;
|
||||||
|
using xAiApi.Interfaces;
|
||||||
using xStorageService.DI;
|
using xStorageService.DI;
|
||||||
using xIdentityService.DI;
|
using xIdentityService.DI;
|
||||||
using xDataService.Models;
|
using xDataService.Models;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
|
using xPushService.Helpers;
|
||||||
using xCommons.Configurations;
|
using xCommons.Configurations;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
@@ -25,11 +30,6 @@ using Newtonsoft.Json.Serialization;
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using IdentityModel.AspNetCore.OAuth2Introspection;
|
using IdentityModel.AspNetCore.OAuth2Introspection;
|
||||||
using xPushService.Helpers;
|
|
||||||
using xAiApi.DI;
|
|
||||||
using xAiApi.Interfaces;
|
|
||||||
using xAiApi.Providers;
|
|
||||||
using xAiModels.DI;
|
|
||||||
|
|
||||||
namespace xAiApi
|
namespace xAiApi
|
||||||
{
|
{
|
||||||
@@ -189,6 +189,7 @@ namespace xAiApi
|
|||||||
// Register Default Ai Service ...
|
// Register Default Ai Service ...
|
||||||
services.AddScoped<IXDefaultAiService, XDefaultAiService>();
|
services.AddScoped<IXDefaultAiService, XDefaultAiService>();
|
||||||
services.AddScoped<IXDefaultEmbeddingService, XDefaultEmbeddingService>();
|
services.AddScoped<IXDefaultEmbeddingService, XDefaultEmbeddingService>();
|
||||||
|
services.AddScoped<IXDefaultThinkingAiService, XDefaultThinkingAiService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
|
|||||||
Reference in New Issue
Block a user