last ...
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xAiApi.Helpers;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Controllers;
|
||||
using xCommons.Extensions;
|
||||
using xCommons.Providers;
|
||||
using xIdentityHelper;
|
||||
|
||||
namespace xAiApi.Controllers
|
||||
{
|
||||
public class OSController : XBaseController
|
||||
{
|
||||
public OSController(
|
||||
ILogger<OSController> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
XValidationProvider validationProvider
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
validationProvider
|
||||
)
|
||||
{ }
|
||||
|
||||
//
|
||||
#region Actions ...
|
||||
/// <summary>
|
||||
/// Get OS Type ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("OSType")]
|
||||
[Authorize(Policy = XPolicies.Admin)]
|
||||
public ActionResult<string> GetOSType()
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
var osType = XOsHelper.GetOSType();
|
||||
var result = osType.GetStringValue();
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get OS Description ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("OSDescription")]
|
||||
[Authorize(Policy = XPolicies.Admin)]
|
||||
public ActionResult<string> GetOSDescription()
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
var result = XOsHelper.GetOSDescription();
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xAiApi.AI.Interfaces;
|
||||
using xAiApi.Base;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Providers;
|
||||
using xIdentityService.Interfaces;
|
||||
|
||||
namespace xAiApi.Controllers.V1
|
||||
{
|
||||
public class AIController : XIBaseV1Controller
|
||||
{
|
||||
private readonly IXAIService aiService;
|
||||
|
||||
public AIController(
|
||||
IXAIService aiService,
|
||||
ILogger<XIBaseV1Controller> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
XValidationProvider validationProvider
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
identityProvider,
|
||||
validationProvider
|
||||
)
|
||||
{
|
||||
this.aiService = aiService;
|
||||
}
|
||||
|
||||
//
|
||||
#region Actions ...
|
||||
[AllowAnonymous]
|
||||
[HttpGet("AskAI")]
|
||||
public async Task<ActionResult<string>> AskAI(
|
||||
[FromQuery] string prompt
|
||||
)
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
var result = await aiService
|
||||
.GetTextResponseAsync(prompt);
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
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.Admin)]
|
||||
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.Admin)]
|
||||
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