Cleanup and Backup Exists AiApi and Create a New .net 10 App and Configureit for using xDashboard ...
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Controllers;
|
||||
using xCommons.Providers;
|
||||
|
||||
@@ -1,193 +0,0 @@
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xCommons.Attributes;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Providers;
|
||||
using xIdentityHelper;
|
||||
using xIdentityService.Controllers;
|
||||
using xIdentityService.Interfaces;
|
||||
|
||||
namespace xAiApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Test all Authentication Policies ...
|
||||
/// </summary>
|
||||
[RequireXPowered(false)]
|
||||
public class TestIdentity : XIBaseController
|
||||
{
|
||||
public TestIdentity(
|
||||
ILogger<TestIdentity> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
XValidationProvider validationProvider
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
identityProvider,
|
||||
validationProvider
|
||||
)
|
||||
{ }
|
||||
|
||||
//
|
||||
#region Test Actions ...
|
||||
/// <summary>
|
||||
/// API Read Scope
|
||||
/// </summary>
|
||||
/// <returns>string message</returns>
|
||||
[HttpGet("PassReadAccess")]
|
||||
[Authorize(Policy = XPolicies.ReadAccess)]
|
||||
public ActionResult<string> PassReadAccess()
|
||||
{
|
||||
return Ok("Read Access Passed ...");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// API Write Scope
|
||||
/// </summary>
|
||||
/// <returns>string message</returns>
|
||||
[HttpGet("PassWriteAccess")]
|
||||
[Authorize(Policy = XPolicies.WriteAccess)]
|
||||
public ActionResult<string> PassWriteAccess()
|
||||
{
|
||||
return Ok("Write Access Passed ...");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// API Admin Scope
|
||||
/// </summary>
|
||||
/// <returns>string message</returns>
|
||||
[HttpGet("PassAdminAccess")]
|
||||
[Authorize(Policy = XPolicies.AdminAccess)]
|
||||
public ActionResult<string> PassAdminAccess()
|
||||
{
|
||||
return Ok("Admin Access Passed ...");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// API Manage Scop
|
||||
/// </summary>
|
||||
/// <returns>string message</returns>
|
||||
[HttpGet("PassManageAccess")]
|
||||
[Authorize(Policy = XPolicies.ManageAccess)]
|
||||
public ActionResult<string> PassManageAccess()
|
||||
{
|
||||
return Ok("Manage Access Passed ...");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a simple Action which returns a List of Authenticated User Claims
|
||||
/// </summary>
|
||||
/// <returns>string message which represent current user's claims</returns>
|
||||
[HttpGet("HiClaims")]
|
||||
[Authorize(Policy = XPolicies.User)]
|
||||
public ActionResult<string> HiClaims()
|
||||
{
|
||||
//
|
||||
var result = new
|
||||
{
|
||||
name = User.Identity.Name,
|
||||
claims = User.Claims.Select(c => new
|
||||
{
|
||||
c.Type,
|
||||
c.Value
|
||||
})
|
||||
};
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a simple Hello User for Checking Authentication and Policy
|
||||
/// </summary>
|
||||
/// <returns>string message which contains authenticated user name</returns>
|
||||
[HttpGet("HiUser")]
|
||||
[Authorize(Policy = XPolicies.User)]
|
||||
public ActionResult<string> HiUser()
|
||||
{
|
||||
//
|
||||
var result = $"Hi User: {User.Identity.Name} ...";
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a simple Hello User for Checking Authentication and Policy
|
||||
/// </summary>
|
||||
/// <returns>string message which contains authenticated user name</returns>
|
||||
[HttpGet("HiEnabledUser")]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public ActionResult<string> HiEnabledUser()
|
||||
{
|
||||
//
|
||||
var result = $"Hi User: {User.Identity.Name} is Enabled ...";
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a simple Hello User for Checking Authentication and Policy
|
||||
/// </summary>
|
||||
/// <returns>string message which contains authenticated user name</returns>
|
||||
[HttpGet("HiAgent")]
|
||||
[Authorize(Policy = XPolicies.Agent)]
|
||||
public ActionResult<string> HiAgent()
|
||||
{
|
||||
//
|
||||
var result = $"Hi Agent: {User.Identity.Name} ...";
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a simple Hello User for Checking Authentication and Policy
|
||||
/// </summary>
|
||||
/// <returns>string message which contains authenticated user name</returns>
|
||||
[HttpGet("HiEnabledAgent")]
|
||||
[Authorize(Policy = XPolicies.EnabledAgent)]
|
||||
public ActionResult<string> HiEnabledAgent()
|
||||
{
|
||||
//
|
||||
var result = $"Hi Agent: {User.Identity.Name} is Enabled ...";
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a simple Hello User for Checking Authentication and Policy
|
||||
/// </summary>
|
||||
/// <returns>string message which contains authenticated user name</returns>
|
||||
[HttpGet("HiAdmin")]
|
||||
[Authorize(Policy = XPolicies.Admin)]
|
||||
public ActionResult<string> HiAdmin()
|
||||
{
|
||||
//
|
||||
var result = $"Hi Admin: {User.Identity.Name} ...";
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a simple Hello User for Checking Authentication and Policy
|
||||
/// </summary>
|
||||
/// <returns>string message which contains authenticated user name</returns>
|
||||
[HttpGet("HiEnabledAdmin")]
|
||||
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
||||
public ActionResult<string> HiEnabledAdmin()
|
||||
{
|
||||
//
|
||||
var result = $"Hi Admin: {User.Identity.Name} is Enabled ...";
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using xCommons.Attributes;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Providers;
|
||||
using xIdentityHelper;
|
||||
using xIdentityService.Controllers;
|
||||
using xIdentityService.Interfaces;
|
||||
|
||||
namespace xAiApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Test all Authentication Policies ...
|
||||
/// </summary>
|
||||
[RequireXPowered(false)]
|
||||
public class TestIdentityController : XBaseIdentityController
|
||||
{
|
||||
public TestIdentityController(
|
||||
ILogger<TestIdentityController> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
XValidationProvider validationProvider
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
identityProvider,
|
||||
validationProvider
|
||||
)
|
||||
{ }
|
||||
|
||||
//
|
||||
#region Test Actions ...
|
||||
/// <summary>
|
||||
/// API Read Scope
|
||||
/// </summary>
|
||||
/// <returns>string message</returns>
|
||||
[HttpGet ("PassReadAccess")]
|
||||
[Authorize (Policy = XPolicies.ReadAccess)]
|
||||
public ActionResult<string> PassReadAccess () {
|
||||
return Ok ("Read Access Passed ...");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// API Write Scope
|
||||
/// </summary>
|
||||
/// <returns>string message</returns>
|
||||
[HttpGet ("PassWriteAccess")]
|
||||
[Authorize (Policy = XPolicies.WriteAccess)]
|
||||
public ActionResult<string> PassWriteAccess () {
|
||||
return Ok ("Write Access Passed ...");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// API Admin Scope
|
||||
/// </summary>
|
||||
/// <returns>string message</returns>
|
||||
[HttpGet ("PassAdminAccess")]
|
||||
[Authorize (Policy = XPolicies.AdminAccess)]
|
||||
public ActionResult<string> PassAdminAccess () {
|
||||
return Ok ("Admin Access Passed ...");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// API Manage Scop
|
||||
/// </summary>
|
||||
/// <returns>string message</returns>
|
||||
[HttpGet ("PassManageAccess")]
|
||||
[Authorize (Policy = XPolicies.ManageAccess)]
|
||||
public ActionResult<string> PassManageAccess () {
|
||||
return Ok ("Manage Access Passed ...");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a simple Action which returns a List of Authenticated User Claims
|
||||
/// </summary>
|
||||
/// <returns>string message which represent current user's claims</returns>
|
||||
[HttpGet ("HiClaims")]
|
||||
[Authorize (Policy = XPolicies.User)]
|
||||
public ActionResult<string> HiClaims () {
|
||||
//
|
||||
var result = new {
|
||||
name = User?.Identity?.Name,
|
||||
claims = User?.Claims.Select (c => new {
|
||||
c.Type, c.Value
|
||||
})
|
||||
};
|
||||
|
||||
//
|
||||
return Ok (result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a simple Hello User for Checking Authentication and Policy
|
||||
/// </summary>
|
||||
/// <returns>string message which contains authenticated user name</returns>
|
||||
[HttpGet ("HiUser")]
|
||||
[Authorize (Policy = XPolicies.User)]
|
||||
public ActionResult<string> HiUser () {
|
||||
//
|
||||
var result = $"Hi User: {User?.Identity?.Name} ...";
|
||||
|
||||
//
|
||||
return Ok (result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a simple Hello User for Checking Authentication and Policy
|
||||
/// </summary>
|
||||
/// <returns>string message which contains authenticated user name</returns>
|
||||
[HttpGet ("HiEnabledUser")]
|
||||
[Authorize (Policy = XPolicies.EnabledUser)]
|
||||
public ActionResult<string> HiEnabledUser () {
|
||||
//
|
||||
var result = $"Hi User: {User?.Identity?.Name} is Enabled ...";
|
||||
|
||||
//
|
||||
return Ok (result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a simple Hello User for Checking Authentication and Policy
|
||||
/// </summary>
|
||||
/// <returns>string message which contains authenticated user name</returns>
|
||||
[HttpGet ("HiAgent")]
|
||||
[Authorize (Policy = XPolicies.Agent)]
|
||||
public ActionResult<string> HiAgent () {
|
||||
//
|
||||
var result = $"Hi Agent: {User?.Identity?.Name} ...";
|
||||
|
||||
//
|
||||
return Ok (result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a simple Hello User for Checking Authentication and Policy
|
||||
/// </summary>
|
||||
/// <returns>string message which contains authenticated user name</returns>
|
||||
[HttpGet ("HiEnabledAgent")]
|
||||
[Authorize (Policy = XPolicies.EnabledAgent)]
|
||||
public ActionResult<string> HiEnabledAgent () {
|
||||
//
|
||||
var result = $"Hi Agent: {User?.Identity?.Name} is Enabled ...";
|
||||
|
||||
//
|
||||
return Ok (result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a simple Hello User for Checking Authentication and Policy
|
||||
/// </summary>
|
||||
/// <returns>string message which contains authenticated user name</returns>
|
||||
[HttpGet ("HiAdmin")]
|
||||
[Authorize (Policy = XPolicies.Admin)]
|
||||
public ActionResult<string> HiAdmin () {
|
||||
//
|
||||
var result = $"Hi Admin: {User?.Identity?.Name} ...";
|
||||
|
||||
//
|
||||
return Ok (result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a simple Hello User for Checking Authentication and Policy
|
||||
/// </summary>
|
||||
/// <returns>string message which contains authenticated user name</returns>
|
||||
[HttpGet ("HiEnabledAdmin")]
|
||||
[Authorize (Policy = XPolicies.EnabledAdmin)]
|
||||
public ActionResult<string> HiEnabledAdmin () {
|
||||
//
|
||||
var result = $"Hi Admin: {User?.Identity?.Name} is Enabled ...";
|
||||
|
||||
//
|
||||
return Ok (result);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,313 +0,0 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.AI;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OpenAI.Realtime;
|
||||
using xAiApi.AI.Interfaces;
|
||||
using xAiApi.AI.Models.Dtos;
|
||||
using xAiApi.Base;
|
||||
using xAiModels.Models;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Extensions;
|
||||
using xCommons.Providers;
|
||||
using xExceptions.Constants;
|
||||
using xIdentityHelper;
|
||||
using xIdentityService.Constants;
|
||||
using xIdentityService.Interfaces;
|
||||
|
||||
namespace xAiApi.Controllers.V1
|
||||
{
|
||||
/// <summary>
|
||||
/// a Controller Which Provides Actions for
|
||||
/// using Ai Service ...
|
||||
/// </summary>
|
||||
public class AIController : XIBaseV1Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Ai Provider ...
|
||||
/// </summary>
|
||||
private readonly IXAiProvider aiService;
|
||||
|
||||
//
|
||||
#region Constructor ...
|
||||
public AIController(
|
||||
IXAiProvider aiService,
|
||||
ILogger<XIBaseV1Controller> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
XValidationProvider validationProvider
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
identityProvider,
|
||||
validationProvider
|
||||
)
|
||||
{
|
||||
this.aiService = aiService;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Actions ...
|
||||
/// <summary>
|
||||
/// As a Message from Ai ...
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// </remarks>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Ask")]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public async Task<ActionResult<XAiMessageDto>> Ask(
|
||||
[FromQuery] XAiAskRequestDto request,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate Model ...
|
||||
var isValid =
|
||||
ModelState.IsValid &&
|
||||
!request.IsNull() &&
|
||||
!request.Prompt.IsNullOrEmpty();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve User Info ...
|
||||
var userInfo = await GetUserInfo();
|
||||
|
||||
//
|
||||
// Retrieve Result ...
|
||||
var result = await aiService
|
||||
.Ask(
|
||||
userInfo: userInfo,
|
||||
prompt: request.Prompt,
|
||||
projectId: request.ProjectId,
|
||||
cancellationToken: cancellationToken,
|
||||
conversationId: request.ConversationId
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// As a Message from Ai ...
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// </remarks>
|
||||
/// <param name="prompt">specified prompt</param>
|
||||
/// <param name="projectId">active Project Id</param>
|
||||
/// <param name="conversationId">active Conversation Id</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns>Ai Model's answer <see cref="XAiMessageDto"/></returns>
|
||||
[HttpGet("AskAI")]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public async Task<ActionResult<XAiMessageDto>> AskAI(
|
||||
[FromQuery] string prompt,
|
||||
[FromQuery] string projectId = null,
|
||||
[FromQuery] string conversationId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
var userInfo = await GetUserInfo();
|
||||
var result = await aiService
|
||||
.Ask(
|
||||
prompt: prompt,
|
||||
userInfo: userInfo,
|
||||
projectId: projectId,
|
||||
conversationId: conversationId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ask a Message from Ai using Streamin Pattern ...
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// </remarks>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("AskStream")]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public async Task AskStream(
|
||||
[FromQuery] XAiAskRequestDto request,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate Model ...
|
||||
var isValid =
|
||||
ModelState.IsValid &&
|
||||
!request.IsNull() &&
|
||||
!request.Prompt.IsNullOrEmpty();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Adding Content Type ...
|
||||
Response.Headers
|
||||
.Append("Content-Type", "text/event-stream");
|
||||
|
||||
//
|
||||
// Retrieve User Info ...
|
||||
var userInfo = await GetUserInfo();
|
||||
|
||||
//
|
||||
// Access Async Enumerable ...
|
||||
var stream = aiService
|
||||
.AskStream(
|
||||
userInfo: userInfo,
|
||||
prompt: request.Prompt,
|
||||
projectId: request.ProjectId,
|
||||
cancellationToken: cancellationToken,
|
||||
conversationId: request.ConversationId
|
||||
);
|
||||
|
||||
//
|
||||
// Loop through Enumerable ...
|
||||
await foreach (var message in stream)
|
||||
{
|
||||
//
|
||||
// Converts Model to Json String ...
|
||||
var json = message.ToJSON();
|
||||
|
||||
//
|
||||
// Generates Json byte[] ...
|
||||
var bytes = json.ToBytes();
|
||||
|
||||
//
|
||||
// Write Bytes to Stream ...
|
||||
await Response.Body.WriteAsync(
|
||||
bytes,
|
||||
0,
|
||||
bytes.Length,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Flushing Stream ...
|
||||
await Response.Body.FlushAsync(cancellationToken);
|
||||
}
|
||||
|
||||
//
|
||||
// Closing Connection ...
|
||||
await Response.Body.FlushAsync();
|
||||
}
|
||||
catch (Exception)
|
||||
{ }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ask a Message from Ai using Streamin Pattern ...
|
||||
/// </summary>
|
||||
/// <param name="prompt"></param>
|
||||
/// <param name="projectId"></param>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("AskAIStream")]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public async Task AskAIStream(
|
||||
[FromQuery] string prompt,
|
||||
[FromQuery] string projectId = null,
|
||||
[FromQuery] string conversationId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
// Adding Content Type ...
|
||||
Response.Headers
|
||||
.Append("Content-Type", "text/event-stream");
|
||||
|
||||
//
|
||||
var userInfo = await GetUserInfo();
|
||||
var stream = aiService
|
||||
.AskStream(
|
||||
prompt: prompt,
|
||||
userInfo: userInfo,
|
||||
projectId: projectId,
|
||||
conversationId: conversationId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Loop through Enumerable ...
|
||||
await foreach (var message in stream)
|
||||
{
|
||||
//
|
||||
// Converts Model to Json String ...
|
||||
var json = message.ToJSON();
|
||||
|
||||
//
|
||||
// Generates Json byte[] ...
|
||||
var bytes = json.ToBytes();
|
||||
|
||||
//
|
||||
// Write Bytes to Stream ...
|
||||
await Response.Body.WriteAsync(
|
||||
bytes,
|
||||
0,
|
||||
bytes.Length,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Flushing Stream ...
|
||||
await Response.Body.FlushAsync(cancellationToken);
|
||||
}
|
||||
|
||||
//
|
||||
// Closing Connection ...
|
||||
await Response.Body.FlushAsync();
|
||||
}
|
||||
catch (Exception)
|
||||
{ }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xAiApi.AI.Interfaces.Entities;
|
||||
using xAiApi.AI.Models.Entities;
|
||||
using xAiApi.Base;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Providers;
|
||||
using xIdentityService.Interfaces;
|
||||
using xPushService.Base;
|
||||
|
||||
namespace xAiApi.Controllers.V1.Entities
|
||||
{
|
||||
public class AiConversationsController : XIBaseV1EntityHubController<XAiConversation, Guid>
|
||||
{
|
||||
public AiConversationsController(
|
||||
ILogger<AiConversationsController> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
XValidationProvider validationProvider,
|
||||
IXAiConversationRepository repository,
|
||||
IHubContext<XBaseEntityHub<XAiConversation, Guid>> hub = null
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
identityProvider,
|
||||
validationProvider,
|
||||
repository,
|
||||
hub
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xAiApi.AI.Interfaces.Entities;
|
||||
using xAiApi.AI.Models.Entities;
|
||||
using xAiApi.Base;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Providers;
|
||||
using xIdentityService.Interfaces;
|
||||
using xPushService.Base;
|
||||
|
||||
namespace xAiApi.Controllers.V1.Entities
|
||||
{
|
||||
public class AiMessagesController : XIBaseV1EntityHubController<XAiMessage, Guid>
|
||||
{
|
||||
public AiMessagesController(
|
||||
ILogger<AiMessagesController> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
XValidationProvider validationProvider,
|
||||
IXAiMessageRepository repository,
|
||||
IHubContext<XBaseEntityHub<XAiMessage, Guid>> hub = null
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
identityProvider,
|
||||
validationProvider,
|
||||
repository,
|
||||
hub
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xAiApi.AI.Interfaces.Entities;
|
||||
using xAiApi.AI.Models.Entities;
|
||||
using xAiApi.Base;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Providers;
|
||||
using xIdentityService.Interfaces;
|
||||
using xPushService.Base;
|
||||
|
||||
namespace xAiApi.Controllers.V1.Entities
|
||||
{
|
||||
public class AiProjectsController : XIBaseV1EntityHubController<XAiProject, Guid>
|
||||
{
|
||||
public AiProjectsController(
|
||||
ILogger<AiProjectsController> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
XValidationProvider validationProvider,
|
||||
IXAiProjectRepository repository,
|
||||
IHubContext<XBaseEntityHub<XAiProject, Guid>> hub = null
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
identityProvider,
|
||||
validationProvider,
|
||||
repository,
|
||||
hub
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -1,557 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.EntityFrameworkCore.Query;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xAiApi.Base;
|
||||
using xAiApi.Data.Interfaces;
|
||||
using xAiApi.Data.Models.Entities;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Extensions;
|
||||
using xCommons.Providers;
|
||||
using xIdentityHelper;
|
||||
using xIdentityService.Interfaces;
|
||||
using xModels.Base;
|
||||
using xModels.Dtos;
|
||||
using xPushService.Base;
|
||||
using xPushService.Constants;
|
||||
|
||||
namespace xAiApi.Controllers.V1.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple XTest Entity Controller ...
|
||||
/// </summary>
|
||||
public class TestsController : XIBaseV1EntityHubController<XTest, int>
|
||||
{
|
||||
//
|
||||
#region Constructor ...
|
||||
public TestsController(
|
||||
ILogger<TestsController> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
XValidationProvider validationProvider,
|
||||
IXTestRepository repository,
|
||||
IHubContext<XBaseEntityHub<XTest, int>> hub = null,
|
||||
Func<IQueryable<XTest>, IOrderedQueryable<XTest>> defaultOrderBuilder = null,
|
||||
Func<IQueryable<XTest>, IIncludableQueryable<XTest, object>> defaultIncludeBuilder = null
|
||||
) : base(
|
||||
hub: hub,
|
||||
logger: logger,
|
||||
repository: repository,
|
||||
appConfiguration: appConfiguration,
|
||||
identityProvider: identityProvider,
|
||||
validationProvider: validationProvider,
|
||||
defaultOrderBuilder: defaultOrderBuilder,
|
||||
defaultIncludeBuilder: defaultIncludeBuilder
|
||||
)
|
||||
{ }
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Actions ...
|
||||
//
|
||||
#region Add ...
|
||||
/// <summary>
|
||||
/// Add Specified Item ...
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Sample request:
|
||||
///
|
||||
/// {
|
||||
/// "title": ""
|
||||
/// }
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
||||
public override async Task<ActionResult<XTest>> Add(
|
||||
[FromBody] XTest item,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var entity = await base
|
||||
.Add(
|
||||
item: item,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Handle Sending Push Notification ...
|
||||
if (!entity.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await SendPush(
|
||||
payLoad: entity.ToJSON(),
|
||||
cancellationToken: cancellationToken,
|
||||
action: XBaseEntityHubAction.Add.GetStringValue()
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update Specified Item ...
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Sample request:
|
||||
///
|
||||
/// {
|
||||
/// "title": ""
|
||||
/// }
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("AddOrUpdate")]
|
||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
||||
public override async Task<ActionResult<XTest>> AddOrUpdate(
|
||||
[FromBody] XTest item,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var entity = await base
|
||||
.AddOrUpdate(
|
||||
item: item,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Handle Sending Push Notification ...
|
||||
if (!entity.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await SendPush(
|
||||
payLoad: entity.ToJSON(),
|
||||
cancellationToken: cancellationToken,
|
||||
action: XBaseEntityHubAction.AddOrUpdate.GetStringValue()
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add Many Specified Items ...
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Sample request:
|
||||
///
|
||||
/// {
|
||||
/// "items": [
|
||||
/// {
|
||||
/// "title": ""
|
||||
/// }
|
||||
/// ]
|
||||
/// }
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("AddMany")]
|
||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
||||
public override async Task<ActionResult> AddMany(
|
||||
[FromBody] XBaseRangeRequest<XTest> request,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base
|
||||
.AddMany(
|
||||
request: request,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
if (!(result as OkObjectResult).IsNull())
|
||||
{
|
||||
//
|
||||
await SendPush(
|
||||
payLoad: request.Items.ToJSON(),
|
||||
cancellationToken: cancellationToken,
|
||||
action: XBaseEntityHubAction.AddMany.GetStringValue()
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Retrieve ...
|
||||
/// <summary>
|
||||
/// Get Specified Item by Providing Identifier ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="useDefaultIncludes"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}")]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public override async Task<ActionResult<XTest>> Get(
|
||||
[FromRoute] int id,
|
||||
[FromQuery] bool ignoreSoftDeleteds = true,
|
||||
[FromQuery] bool useDefaultIncludes = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
return await base
|
||||
.Get(
|
||||
id: id,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds,
|
||||
useDefaultIncludes: useDefaultIncludes
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all Exists Items ...
|
||||
/// </summary>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="useDefaultOrders"></param>
|
||||
/// <param name="useDefaultIncludes"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public override async Task<ActionResult<IEnumerable<XTest>>> GetAll(
|
||||
[FromQuery] bool ignoreSoftDeleteds = true,
|
||||
[FromQuery] bool useDefaultOrders = false,
|
||||
[FromQuery] bool useDefaultIncludes = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
return await base
|
||||
.GetAll(
|
||||
useDefaultOrders: useDefaultOrders,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds,
|
||||
useDefaultIncludes: useDefaultIncludes
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find Item based on Provided Query ....
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="useDefaultIncludes"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("FindOne/{query}")]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public override async Task<ActionResult<XTest>> FindOne(
|
||||
[FromRoute] string query,
|
||||
[FromQuery] bool ignoreSoftDeleteds = true,
|
||||
[FromQuery] bool useDefaultIncludes = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
return await base
|
||||
.FindOne(
|
||||
query: query,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds,
|
||||
useDefaultIncludes: useDefaultIncludes
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find Items based on Provided Query ...
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="useDefaultOrders"></param>
|
||||
/// <param name="useDefaultIncludes"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("FindMany/{query}")]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public override async Task<ActionResult<IEnumerable<XTest>>> FindMany(
|
||||
[FromRoute] string query,
|
||||
[FromQuery] bool ignoreSoftDeleteds = true,
|
||||
[FromQuery] bool useDefaultOrders = false,
|
||||
[FromQuery] bool useDefaultIncludes = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
return await base
|
||||
.FindMany(
|
||||
query: query,
|
||||
useDefaultOrders: useDefaultOrders,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds,
|
||||
useDefaultIncludes: useDefaultIncludes
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Items based on Query Mechanism ...
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="useDefaultOrders"></param>
|
||||
/// <param name="useDefaultIncludes"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Query")]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public override async Task<ActionResult<XQueryResult<XTest>>> Query(
|
||||
[FromQuery] XQuery query,
|
||||
[FromQuery] bool ignoreSoftDeleteds = true,
|
||||
[FromQuery] bool useDefaultOrders = false,
|
||||
[FromQuery] bool useDefaultIncludes = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
return await base
|
||||
.Query(
|
||||
query: query,
|
||||
useDefaultOrders: useDefaultOrders,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds,
|
||||
useDefaultIncludes: useDefaultIncludes
|
||||
);
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Update ...
|
||||
/// <summary>
|
||||
/// Update an Item ...
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Sample request:
|
||||
///
|
||||
/// {
|
||||
/// "title": ""
|
||||
/// }
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("{id}")]
|
||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
||||
public override async Task<ActionResult<XTest>> Update(
|
||||
[FromRoute] int id,
|
||||
[FromBody] XTest item,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var entity = await base
|
||||
.Update(
|
||||
id: id,
|
||||
item: item,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
if (!entity.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await SendPush(
|
||||
payLoad: entity.ToJSON(),
|
||||
cancellationToken: cancellationToken,
|
||||
action: XBaseEntityHubAction.Update.GetStringValue()
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update a Collection of Items ...
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Sample request:
|
||||
///
|
||||
/// {
|
||||
/// "items": [
|
||||
/// {
|
||||
/// "id": 1,
|
||||
/// "title": "Hi there ..."
|
||||
/// }
|
||||
/// ]
|
||||
/// }
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("UpdateMany")]
|
||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
||||
public override async Task<ActionResult<bool>> UpdateMany(
|
||||
[FromBody] XBaseRangeRequest<XTest> request,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base
|
||||
.UpdateMany(
|
||||
request: request,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
var resultObject = (result.Result as OkObjectResult).Value;
|
||||
if (!resultObject.IsNull() && (bool)resultObject)
|
||||
{
|
||||
//
|
||||
await SendPush(
|
||||
payLoad: request.Items.ToJSON(),
|
||||
cancellationToken: cancellationToken,
|
||||
action: XBaseEntityHubAction.UpdateMany.GetStringValue()
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Exists ...
|
||||
/// <summary>
|
||||
/// Check an Item Exists or not ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}/IsExists")]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public override async Task<ActionResult<bool>> IsExists(
|
||||
[FromRoute] int id,
|
||||
[FromQuery] bool ignoreSoftDeleteds = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
return await base
|
||||
.IsExists(
|
||||
id: id,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Remove ...
|
||||
/// <summary>
|
||||
/// Remove an Item ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="softDelete"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{id}")]
|
||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
||||
public override async Task<ActionResult<XTest>> Remove(
|
||||
[FromRoute] int id,
|
||||
[FromQuery] bool softDelete = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var entity = await base
|
||||
.Remove(
|
||||
id: id,
|
||||
softDelete: softDelete,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
if (!entity.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await SendPush(
|
||||
payLoad: entity.ToJSON(),
|
||||
cancellationToken: cancellationToken,
|
||||
action: XBaseEntityHubAction.Delete.GetStringValue()
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove Many Items ...
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Sample request:
|
||||
///
|
||||
/// {
|
||||
/// "items": [
|
||||
/// {
|
||||
/// "id": 1,
|
||||
/// "title": "Hi there ..."
|
||||
/// }
|
||||
/// ]
|
||||
/// }
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="softDelete"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("RemoveMany")]
|
||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
||||
public override async Task<ActionResult> RemoveMany(
|
||||
[FromBody] XBaseRangeRequest<XTest> request,
|
||||
[FromQuery] bool softDelete = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base
|
||||
.RemoveMany(
|
||||
request: request,
|
||||
softDelete: softDelete,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
if (!(result as OkObjectResult).IsNull())
|
||||
{
|
||||
//
|
||||
await SendPush(
|
||||
payLoad: request.Items.ToJSON(),
|
||||
cancellationToken: cancellationToken,
|
||||
action: XBaseEntityHubAction.DeleteMany.GetStringValue()
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xAiApi.Base;
|
||||
using xAiApi.Helpers;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Providers;
|
||||
using xIdentityHelper;
|
||||
using xIdentityService.Interfaces;
|
||||
|
||||
namespace xAiApi.Controllers.V1
|
||||
{
|
||||
public class OllamaController : XIBaseV1Controller
|
||||
{
|
||||
public OllamaController(
|
||||
ILogger<XIBaseV1Controller> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
XValidationProvider validationProvider
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
identityProvider,
|
||||
validationProvider
|
||||
)
|
||||
{ }
|
||||
|
||||
//
|
||||
#region Actions ...
|
||||
/// <summary>
|
||||
/// Retrieve Ollama Version ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Version")]
|
||||
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
||||
public async Task<ActionResult<string>> GetVersion()
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
var result = await XOllamaHelper.GetVersion();
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve a List of Available models ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Models")]
|
||||
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
||||
public async Task<ActionResult<IEnumerable<string>>> GetModels()
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
var result = await XOllamaHelper.GetModels();
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find a model ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("FindModel")]
|
||||
[Authorize(Policy = XPolicies.Admin)]
|
||||
public async Task<ActionResult<IEnumerable<string>>> FindModel(
|
||||
[FromQuery]
|
||||
string model
|
||||
)
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
var result = await XOllamaHelper.FindModel(model);
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user