115 lines
2.9 KiB
C#
115 lines
2.9 KiB
C#
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
|
|
}
|
|
} |