last ...
This commit is contained in:
@@ -12,7 +12,9 @@ namespace xAiApi.Constants
|
||||
public const string XAiApiIntroductionPromptName = "Introduction";
|
||||
|
||||
//
|
||||
public const string XAiDefaultModelName = "Gemma";
|
||||
public const string XAiEmbeddingModelName = "Embed";
|
||||
public const string XAiDefaultThinkingModelName = "Qwen";
|
||||
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.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using xAiModels.Models;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.AI;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace xAiApi.Interfaces
|
||||
{
|
||||
@@ -12,6 +13,16 @@ namespace xAiApi.Interfaces
|
||||
/// </summary>
|
||||
public interface IXAiServiceBase : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Chat Options ...
|
||||
/// </summary>
|
||||
ChatOptions Options { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Descriptor of Models which used in Service ...
|
||||
/// </summary>
|
||||
XAiModelDescriptor Descriptor { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Base Method for Communicate with LLM ...
|
||||
/// </summary>
|
||||
@@ -37,9 +48,8 @@ namespace xAiApi.Interfaces
|
||||
/// <summary>
|
||||
/// Get LLM Client instance for Communicating with LLM ...
|
||||
/// </summary>
|
||||
/// <param name="llm"></param>
|
||||
/// <returns></returns>
|
||||
IChatClient GetClient(string llm = null);
|
||||
IChatClient GetClient();
|
||||
|
||||
/// <summary>
|
||||
/// 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.Threading;
|
||||
using xAiApi.Constants;
|
||||
using xAiModels.Models;
|
||||
using xAiApi.Interfaces;
|
||||
using xAiApi.Extensions;
|
||||
using System.ClientModel;
|
||||
@@ -24,6 +25,16 @@ namespace xAiApi.Providers
|
||||
{
|
||||
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 ILogger<XAIServiceBase> logger;
|
||||
private readonly XAiApiConfiguration configuration;
|
||||
@@ -31,12 +42,25 @@ namespace xAiApi.Providers
|
||||
protected XAIServiceBase(
|
||||
IXAiDataProvider dataProvider,
|
||||
ILogger<XAIServiceBase> logger,
|
||||
XAiApiConfiguration configuration
|
||||
XAiApiConfiguration configuration,
|
||||
string model = null
|
||||
)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.dataProvider = dataProvider;
|
||||
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>
|
||||
/// Get LLM Client instance for Communicating with LLM ...
|
||||
/// </summary>
|
||||
/// <param name="llm"></param>
|
||||
/// <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 ...
|
||||
var model = modelDescriptor.LLM;
|
||||
var apiKey = modelDescriptor.ApiKey;
|
||||
var url = new Uri(modelDescriptor.Url);
|
||||
var httpClient = GetHttpClient(modelDescriptor.Url);
|
||||
var model = Descriptor.LLM;
|
||||
var apiKey = Descriptor.ApiKey;
|
||||
var url = new Uri(Descriptor.Url);
|
||||
var httpClient = GetHttpClient(Descriptor.Url);
|
||||
|
||||
//
|
||||
IChatClient result = null;
|
||||
switch (modelDescriptor.Provider)
|
||||
switch (Descriptor.Provider)
|
||||
{
|
||||
//
|
||||
case XAiModelProviderType.Ollama:
|
||||
@@ -163,7 +178,7 @@ namespace xAiApi.Providers
|
||||
.UseFunctionInvocation()
|
||||
.Build();
|
||||
break;
|
||||
|
||||
|
||||
//
|
||||
case XAiModelProviderType.OpenAI:
|
||||
//
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using OpenAI;
|
||||
using System.Linq;
|
||||
using OllamaSharp;
|
||||
using System.Threading;
|
||||
@@ -6,20 +7,18 @@ using xAiApi.Constants;
|
||||
using xAiModels.Models;
|
||||
using xAiApi.Extensions;
|
||||
using xAiApi.Interfaces;
|
||||
using OllamaSharp.Models;
|
||||
using xAiService.Helpers;
|
||||
using System.ClientModel;
|
||||
using xCommons.Extensions;
|
||||
using xAiModels.Constants;
|
||||
using xAiModels.Extensions;
|
||||
using xAiModels.Interfaces;
|
||||
using xAiApi.Configurations;
|
||||
using xExceptions.Constants;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.AI;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.AI;
|
||||
using xAiModels.Constants;
|
||||
using OpenAI;
|
||||
using System.ClientModel;
|
||||
using System.ClientModel.Primitives;
|
||||
|
||||
namespace xAiApi.Providers
|
||||
@@ -37,7 +36,7 @@ namespace xAiApi.Providers
|
||||
XAiApiConfiguration configuration,
|
||||
ILogger<XAiEmbeddingServiceBase> logger,
|
||||
string embeddingModelName = XAiApiConstants.XAiEmbeddingModelName
|
||||
) : base(dataProvider, logger, configuration)
|
||||
) : base(dataProvider, logger, configuration, null)
|
||||
{
|
||||
//
|
||||
// Prepare Embedding Model Descriptor ...
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xAiApi.Configurations;
|
||||
using xAiApi.Constants;
|
||||
using xAiApi.Interfaces;
|
||||
using xAiModels.Interfaces;
|
||||
using xAiApi.Configurations;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace xAiApi.Providers
|
||||
{
|
||||
@@ -14,7 +15,8 @@ namespace xAiApi.Providers
|
||||
) : base(
|
||||
dataProvider,
|
||||
logger,
|
||||
configuration
|
||||
configuration,
|
||||
XAiApiConstants.XAiDefaultModelName
|
||||
)
|
||||
{ }
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xAiApi.Configurations;
|
||||
using xAiApi.Constants;
|
||||
using xAiApi.Interfaces;
|
||||
using xAiModels.Interfaces;
|
||||
using xAiApi.Configurations;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace xAiApi.Providers
|
||||
{
|
||||
@@ -14,7 +15,8 @@ namespace xAiApi.Providers
|
||||
) : base(
|
||||
dataProvider,
|
||||
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.IO;
|
||||
using xAiApi.DI;
|
||||
using System.Linq;
|
||||
using xAiModels.DI;
|
||||
using xTagService.DI;
|
||||
using System.Net.Http;
|
||||
using xAiApi.Database;
|
||||
@@ -9,13 +11,16 @@ using xPushService.DI;
|
||||
using xFileService.DI;
|
||||
using xDataService.DI;
|
||||
using Newtonsoft.Json;
|
||||
using xAiApi.Providers;
|
||||
using System.Reflection;
|
||||
using xAiApi.Extensions;
|
||||
using xStringService.DI;
|
||||
using xAiApi.Interfaces;
|
||||
using xStorageService.DI;
|
||||
using xIdentityService.DI;
|
||||
using xDataService.Models;
|
||||
using xCommons.Extensions;
|
||||
using xPushService.Helpers;
|
||||
using xCommons.Configurations;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
@@ -25,11 +30,6 @@ using Newtonsoft.Json.Serialization;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using IdentityModel.AspNetCore.OAuth2Introspection;
|
||||
using xPushService.Helpers;
|
||||
using xAiApi.DI;
|
||||
using xAiApi.Interfaces;
|
||||
using xAiApi.Providers;
|
||||
using xAiModels.DI;
|
||||
|
||||
namespace xAiApi
|
||||
{
|
||||
@@ -189,6 +189,7 @@ namespace xAiApi
|
||||
// Register Default Ai Service ...
|
||||
services.AddScoped<IXDefaultAiService, XDefaultAiService>();
|
||||
services.AddScoped<IXDefaultEmbeddingService, XDefaultEmbeddingService>();
|
||||
services.AddScoped<IXDefaultThinkingAiService, XDefaultThinkingAiService>();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
|
||||
Reference in New Issue
Block a user