This commit is contained in:
2026-10-31 17:19:29 +03:30
parent b6421be673
commit 99ed7416fd
12 changed files with 13981 additions and 961 deletions
+110
View File
@@ -144,3 +144,113 @@
}
// TODO: Remove ...
//
// Reading Messages ...
// var messages = await dataProvider.LoadMessages(
// conversationId: conversationId,
// cancellationToken: cancellationToken
// );
//
// TODO: Parse Files ...
// for Attached them into Prompt Message ...
// //
// // Handle Memory ...
// IList<ChatMessage> history = await PrepareMemory(
// project: project,
// messages: messages,
// cancellationToken: cancellationToken
// );
// //
// // Prepare and Add Prompt Message ...
// var promptMessage = new XAiMessageDto
// {
// Content = prompt,
// OwnerId = ownerId,
// Role = XAiChatRole.User,
// CreatedOn = DateTime.UtcNow,
// ConversationId = conversationId,
// };
// promptMessage = await dataProvider.AddMessage(
// item: promptMessage,
// connectionId: connectionId,
// conversationId: conversationId,
// cancellationToken: cancellationToken
// );
// promptMessage = await dataProvider.Enrich(
// source: promptMessage,
// cancellationToken: cancellationToken
// );
// //
// // Attach Uploaded Files ...
// var promptChatMessage = promptMessage
// .ToChatMessages();
// history.Add(promptChatMessage);
// //
// // Ask Questions From LLM ...
// using var client = Descriptor.GetClient();
// var enumerable = client.GetStreamingResponseAsync(
// options: null,
// messages: history
// );
// //
// long sequence = 1;
// var answer = string.Empty;
// await foreach (var res in enumerable)
// {
// //
// // Cancellation Token ...
// if (cancellationToken.IsCancellationRequested)
// {
// yield break;
// }
// //
// var resp = new XAiResonseMessage
// {
// OwnerId = ownerId,
// Content = res.Text,
// Sequence = sequence,
// Role = XAiChatRole.System,
// RespondTo = promptMessage.Id,
// RespondedOn = DateTime.UtcNow,
// };
// //
// sequence++;
// answer += res.Text;
// //
// yield return resp;
// }
// //
// // Prepare Answer AI Message ...
// var result = new XAiMessageDto
// {
// Content = answer,
// OwnerId = ownerId,
// Role = XAiChatRole.System,
// CreatedOn = DateTime.UtcNow,
// ConversationId = conversationId
// };
// result = await dataProvider.AddMessage(
// item: result,
// connectionId: connectionId,
// conversationId: conversationId,
// cancellationToken: cancellationToken
// );
@@ -0,0 +1,30 @@
using xAiApi.Interfaces;
using xCommons.Providers;
using xCommons.Configurations;
using Microsoft.AspNetCore.Mvc;
using xIdentityService.Interfaces;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Authorization;
namespace xAiApi.Controllers
{
[Authorize]
[Route("[controller]")]
public class DefaultEmbeddingController : XAiEmbeddingServiceControllerBase<IXAiEmbeddingService>
{
public DefaultEmbeddingController(
ILogger<DefaultEmbeddingController> logger,
IXAiEmbeddingService embeddingService,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider
) : base(
logger: logger,
appConfiguration: appConfiguration,
identityProvider: identityProvider,
embeddingService: embeddingService,
validationProvider: validationProvider
)
{ }
}
}
@@ -0,0 +1,26 @@
using xAiApi.Interfaces;
using xCommons.Providers;
using xCommons.Configurations;
using xIdentityService.Interfaces;
using Microsoft.Extensions.Logging;
namespace xAiApi.Controllers
{
public class DefaultThinkingAiController : XAiServiceControllerBase<IXDefaultThinkingAiService>
{
public DefaultThinkingAiController(
ILogger<DefaultThinkingAiController> logger,
IXDefaultThinkingAiService aiService,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider
) : base(
logger,
aiService,
appConfiguration,
identityProvider,
validationProvider
)
{ }
}
}
@@ -0,0 +1,113 @@
using System;
using System.Threading;
using xAiApi.Interfaces;
using xCommons.Providers;
using System.Threading.Tasks;
using xCommons.Configurations;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using xIdentityService.Interfaces;
using Microsoft.Extensions.Logging;
using xIdentityService.Controllers;
using Microsoft.AspNetCore.Authorization;
namespace xAiApi.Controllers
{
[Authorize]
[Route("[controller]")]
public abstract class XAiEmbeddingServiceControllerBase<TEmbeddingService> : XBaseIdentityApiV1Controller, IXAiEmbeddingServiceControllerBase
where TEmbeddingService : IXAiEmbeddingServiceBase
{
private readonly TEmbeddingService embeddingService;
protected XAiEmbeddingServiceControllerBase(
ILogger logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider,
TEmbeddingService embeddingService
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider
)
{
this.embeddingService = embeddingService;
}
/// <summary>
/// Request For Embedding Specified String ...
/// </summary>
/// <param name="content"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[AllowAnonymous]
[HttpGet("Embedding")]
public async Task<ActionResult<float[]>> Embedding(
[FromQuery] string content,
CancellationToken cancellationToken = default
)
{
//
try
{
//
// Validate ...
ValidationProvider.NotEmpty(content);
//
var result = await embeddingService.Embedding(
content: content,
cancellationToken: cancellationToken
);
//
return Ok(result);
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Request For Embedding Specified Batch ...
/// </summary>
/// <param name="batch"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[AllowAnonymous]
[HttpGet("Embeddings")]
public async Task<ActionResult<IReadOnlyList<float[]>>> Embeddings(
[FromQuery] string[] batch,
CancellationToken cancellationToken = default
)
{
//
try
{
//
// Validate ...
ValidationProvider.NotZeroChilds(batch);
//
var result = await embeddingService.Embeddings(
batch: batch,
cancellationToken: cancellationToken
);
//
return Ok(result);
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
}
}