last ...
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xAiService.Interfaces;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Providers;
|
||||
using xIdentityService.Controllers;
|
||||
using xIdentityService.Interfaces;
|
||||
|
||||
namespace xAiService.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// a Controller base Class which implement based Actions to Provides AI Service Access ...
|
||||
/// </summary>
|
||||
public abstract class XAiServiceControllerBase : XIBaseProviderController, IXAiServiceControllerBase
|
||||
{
|
||||
private readonly IXAiService aiService;
|
||||
|
||||
protected XAiServiceControllerBase(
|
||||
ILogger logger,
|
||||
IXAiService aiService,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
XValidationProvider validationProvider
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
identityProvider,
|
||||
validationProvider
|
||||
)
|
||||
{
|
||||
this.aiService = aiService;
|
||||
}
|
||||
|
||||
//
|
||||
#region Text Actions ...
|
||||
[HttpGet("Ask")]
|
||||
public virtual async Task<ActionResult<string>> Ask(
|
||||
[FromQuery] string prompt,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
var result = await aiService
|
||||
.GetTextResponseAsync(
|
||||
prompt: prompt,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user