last works on AiApi:
- Default Ai Service and Controller; - Default Embeding and Controller; - ...
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xAiApi.Interfaces;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Providers;
|
||||
|
||||
namespace xAiApi.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
[Route("[controller]")]
|
||||
public abstract class XAiEmbeddingServiceControllerBase<TAiService> : XAiServiceControllerBase<TAiService>, IXAiEmbeddingServiceControllerBase
|
||||
where TAiService : IXAiEmbeddingServiceBase
|
||||
{
|
||||
private readonly TAiService aiService;
|
||||
|
||||
protected XAiEmbeddingServiceControllerBase(
|
||||
ILogger logger,
|
||||
TAiService aiService,
|
||||
XAppConfiguration appConfiguration,
|
||||
XValidationProvider validationProvider
|
||||
) : base(
|
||||
logger,
|
||||
aiService,
|
||||
appConfiguration,
|
||||
validationProvider
|
||||
)
|
||||
{
|
||||
this.aiService = aiService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request For Embedding Specified String ...
|
||||
/// </summary>
|
||||
/// <param name="content"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("Embeding")]
|
||||
public async Task<ActionResult<float[]>> Embeding(
|
||||
[FromQuery] string content,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
ValidationProvider.NotEmpty(content);
|
||||
|
||||
//
|
||||
var result = await aiService.Embeding(
|
||||
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("Embedings")]
|
||||
public async Task<ActionResult<IReadOnlyList<float[]>>> Embedings(
|
||||
[FromQuery] string[] batch,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
ValidationProvider.NotZeroChilds(batch);
|
||||
|
||||
//
|
||||
var result = await aiService.Embedings(
|
||||
batch: batch,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user