last ...
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
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 class DefaultAiController : XAiServiceControllerBase<IXDefaultAiService>
|
||||
{
|
||||
public DefaultAiController(
|
||||
ILogger<DefaultAiController> logger,
|
||||
IXDefaultAiService aiService,
|
||||
XAppConfiguration appConfiguration,
|
||||
XValidationProvider validationProvider
|
||||
) : base(
|
||||
logger,
|
||||
aiService,
|
||||
appConfiguration,
|
||||
validationProvider
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
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.Controllers;
|
||||
using xCommons.Providers;
|
||||
|
||||
namespace xAiApi.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
[Route ("[controller]")]
|
||||
public abstract class XAiServiceControllerBase<TAiService> : XBaseController, IXAiServiceControllerBase
|
||||
where TAiService : IXAiServiceBase
|
||||
{
|
||||
private readonly TAiService aiService;
|
||||
|
||||
protected XAiServiceControllerBase(
|
||||
ILogger logger,
|
||||
TAiService aiService,
|
||||
XAppConfiguration appConfiguration,
|
||||
XValidationProvider validationProvider
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
validationProvider
|
||||
)
|
||||
{
|
||||
this.aiService = aiService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ask Question and Get Response ...
|
||||
/// </summary>
|
||||
/// <param name="question"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("Ask")]
|
||||
public virtual async Task<ActionResult<string>> Ask(
|
||||
[FromQuery] string question,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
ValidationProvider.NotEmpty(question);
|
||||
|
||||
//
|
||||
var result = await aiService.AskAsync(
|
||||
prompt: question,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user