- RAG: real scopes with identifiers conversation/{id}/, project/{id}/, user/{ownerId}/, global/;
- RAG: ownership checks via GetProject/GetConversation; Global write requires admin role;
- RAG: tiered retrieval Conversation -> Project -> User -> Global (single embedding, dedup, TopK fill);
- RAG: apply Type filter, sanitize file names, enforce MaxFilesPerIngest/MaxFileSizeBytes/MaxDocumentsPerScope;
- RAG: store scope/scopeId/type/ownerId metadata; return it in documents and sources;
- RAG: add MigrateLegacyVectorsAsync + POST /Knowledge/MigrateLegacy ({ownerId}/... -> user/{ownerId}/...);
- Knowledge API: scope/scopeId on Ingest, Documents, DELETE Documents;
- Remove ProxyController (root route "{modelName}/{path}" + AllowAnonymous hijacked all 2-segment paths);
- Startup: ExceptionHandler("/error") + HSTS outside Development; Swagger only in Development;
static files before routing; CORS before model proxy; add /error endpoint;
- SSE: all stream endpoints use xHttpService XSseExtensions; validate before streaming;
pre-stream errors return proper HTTP status; remove "Connection: keep-alive";
- Use xAiModels.Constants for XAiKnowledgeScope / Knowledge constants / XOpenAINoKey;
- Register XAiVectorEntityRegisterar in XAiApiDbContext;
- XCodeFileContentExtractor: actually read stream content; drop hard-coded "book.epub".
BREAKING: AskTextStream emits data: {"text":"..."}; AskStream emits data: {json}; both end with event: done.
791 lines
24 KiB
C#
791 lines
24 KiB
C#
using System;
|
|
using xModels.Dtos;
|
|
using xIdentityHelper;
|
|
using System.Threading;
|
|
using xAiModels.Models;
|
|
using xAiApi.Extensions;
|
|
using xAiApi.Interfaces;
|
|
using xCommons.Providers;
|
|
using xCommons.Extensions;
|
|
using xAiModels.Extensions;
|
|
using xAiModels.Models.Dtos;
|
|
using xExceptions.Constants;
|
|
using System.Threading.Tasks;
|
|
using xHttpService.Extensions;
|
|
using xCommons.Configurations;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Http;
|
|
using System.Collections.Generic;
|
|
using xIdentityService.Interfaces;
|
|
using Microsoft.Extensions.Logging;
|
|
using xIdentityService.Controllers;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
namespace xAiApi.Controllers
|
|
{
|
|
[Authorize]
|
|
[Route("[controller]")]
|
|
public abstract class XAiServiceControllerBase<TAiService> : XBaseIdentityApiV1Controller, IXAiServiceControllerBase
|
|
where TAiService : IXAiServiceBase
|
|
{
|
|
private readonly TAiService aiService;
|
|
|
|
protected XAiServiceControllerBase(
|
|
ILogger logger,
|
|
TAiService aiService,
|
|
XAppConfiguration appConfiguration,
|
|
IXIdentityProvider identityProvider,
|
|
XValidationProvider validationProvider
|
|
) : base(
|
|
logger,
|
|
appConfiguration,
|
|
identityProvider,
|
|
validationProvider
|
|
)
|
|
{
|
|
this.aiService = aiService;
|
|
}
|
|
|
|
//
|
|
#region Actions ...
|
|
/// <summary>
|
|
/// Ask Question and Get Response ...
|
|
/// </summary>
|
|
/// <param name="question"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("AskText")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task<ActionResult<string>> AskText(
|
|
[FromQuery] string question,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
try
|
|
{
|
|
//
|
|
// Validate ...
|
|
ValidationProvider.NotEmpty(question);
|
|
|
|
//
|
|
var result = await aiService.AskTextAsync(
|
|
prompt: question,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ask Question and Get Response Stream ...
|
|
/// </summary>
|
|
/// <param name="question"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("AskTextStream")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public virtual async Task AskTextStream(
|
|
[FromQuery] string question,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
// Validate (before Stream Starts -> Proper Http Error) ...
|
|
if (question.IsNullOrEmpty())
|
|
{
|
|
await WriteStreamValidationError();
|
|
return;
|
|
}
|
|
|
|
//
|
|
try
|
|
{
|
|
//
|
|
// Configure SSE Response ...
|
|
Response.PrepareSseResponse();
|
|
|
|
//
|
|
var enumerable = aiService.AskTextAsEnumerable(
|
|
prompt: question,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
// Format: data: {"text":"..."}\n\n
|
|
await foreach (var chunk in enumerable)
|
|
{
|
|
//
|
|
// Skip Empty Chunks ...
|
|
if (string.IsNullOrEmpty(chunk))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
await Response.WriteSseEventAsync(
|
|
data: new { text = chunk },
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
|
|
//
|
|
await Response.WriteSseDoneAsync(cancellationToken);
|
|
}
|
|
catch (Exception ex) when (ex.IsClientCancellation(cancellationToken))
|
|
{
|
|
// Client Disconnected ...
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
Logger.LogError(ex, "AskTextStream Failed");
|
|
if (!Response.HasStarted)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
await result.ExecuteResultAsync(ControllerContext);
|
|
return;
|
|
}
|
|
|
|
//
|
|
await Response.WriteSseErrorAsync(ex.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Write Validation Error for Streaming Endpoints (before Stream Starts) ...
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[NonAction]
|
|
protected async Task WriteStreamValidationError()
|
|
{
|
|
//
|
|
Response.StatusCode = StatusCodes.Status400BadRequest;
|
|
Response.ContentType = "application/json; charset=utf-8";
|
|
await Response.WriteAsync(XException.InvalidArgs.ToXError().ToJSON());
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Loaders ...
|
|
/// <summary>
|
|
/// Retrieve AI Projects ...
|
|
/// </summary>
|
|
/// <param name="includeDefaults"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Projects")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public async Task<ActionResult<IEnumerable<XAiProjectDto>>> LoadProjects(
|
|
[FromQuery] bool includeDefaults = false,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
try
|
|
{
|
|
//
|
|
var userInfo = await GetUserInfo();
|
|
var connectionId = GetConnectionId();
|
|
|
|
//
|
|
var result = await aiService.LoadProjects(
|
|
ownerId: userInfo.UserId,
|
|
connectionId: connectionId,
|
|
includeDefaults: includeDefaults,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve Specified AI Project's Conversations ...
|
|
/// </summary>
|
|
/// <param name="projectId"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Projects/{projectId}/Conversations")]
|
|
public async Task<ActionResult<IEnumerable<XAiConversationDto>>> LoadConversations(
|
|
[FromRoute] Guid projectId,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
try
|
|
{
|
|
//
|
|
// Validate ...
|
|
if (projectId.IsDefaultGuid())
|
|
{
|
|
XException.InvalidArgs.Throw();
|
|
}
|
|
|
|
//
|
|
var userInfo = await GetUserInfo();
|
|
var connectionId = GetConnectionId();
|
|
|
|
//
|
|
var result = await aiService.LoadConversations(
|
|
projectId: projectId,
|
|
connectionId: connectionId,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve Specified AI Conversation's Messages ...
|
|
/// </summary>
|
|
/// <param name="conversationId"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Conversations/{conversationId}/Messages")]
|
|
public async Task<ActionResult<IEnumerable<XAiMessageDto>>> LoadMessages(
|
|
[FromRoute] Guid conversationId,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
try
|
|
{
|
|
//
|
|
// Validate ...
|
|
if (conversationId.IsDefaultGuid())
|
|
{
|
|
XException.InvalidArgs.Throw();
|
|
}
|
|
|
|
//
|
|
var result = await aiService.LoadMessages(
|
|
conversationId: conversationId,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Queries ...
|
|
/// <summary>
|
|
/// Query Projects ...
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// </remarks>
|
|
/// <param name="query"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Projects/Query")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public async Task<ActionResult<XQueryResult<XAiProjectDto>>> QueryProjects(
|
|
[FromQuery] XQuery query,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
try
|
|
{
|
|
//
|
|
var userInfo = await GetUserInfo();
|
|
var connectionId = GetConnectionId();
|
|
|
|
//
|
|
var result = await aiService.QueryProjects(
|
|
query: query,
|
|
ownerId: userInfo.UserId,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Query Conversations ...
|
|
/// </summary>
|
|
/// <param name="projectId"></param>
|
|
/// <param name="query"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Projects/{projectId}/Conversations/Query")]
|
|
public async Task<ActionResult<XQueryResult<XAiConversationDto>>> QueryConversations(
|
|
[FromRoute] Guid projectId,
|
|
[FromQuery] XQuery query,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
try
|
|
{
|
|
//
|
|
var userInfo = await GetUserInfo();
|
|
var connectionId = GetConnectionId();
|
|
|
|
//
|
|
var result = await aiService.QueryConversations(
|
|
query: query,
|
|
projectId: projectId,
|
|
ownerId: userInfo.UserId,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Query Messages ...
|
|
/// </summary>
|
|
/// <param name="conversationId"></param>
|
|
/// <param name="query"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpGet("Conversations/{conversationId}/Messages/Query")]
|
|
public async Task<ActionResult<XQueryResult<XAiMessageDto>>> QueryMessages(
|
|
[FromRoute] Guid conversationId,
|
|
[FromQuery] XQuery query,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
try
|
|
{
|
|
//
|
|
var userInfo = await GetUserInfo();
|
|
var connectionId = GetConnectionId();
|
|
|
|
//
|
|
var result = await aiService.QueryMessages(
|
|
query: query,
|
|
ownerId: userInfo.UserId,
|
|
conversationId: conversationId,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Creators ...
|
|
/// <summary>
|
|
/// Create an AI Project ...
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Projects")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public async Task<ActionResult<XAiProjectDto>> CreateProject(
|
|
[FromBody] XAiProjectDto item,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
try
|
|
{
|
|
//
|
|
// Validate ...
|
|
if (item.IsNullOrDefault())
|
|
{
|
|
XException.InvalidArgs.Throw();
|
|
}
|
|
|
|
//
|
|
var userInfo = await GetUserInfo();
|
|
var connectionId = GetConnectionId();
|
|
|
|
//
|
|
// Update Required Params ...
|
|
item.OwnerId = userInfo.UserId;
|
|
if (!item.IsValidForAddOrUpdate())
|
|
{
|
|
XException.InvalidData.Throw();
|
|
}
|
|
|
|
//
|
|
var result = await aiService.CreateProject(
|
|
item: item,
|
|
ownerId: userInfo.UserId,
|
|
connectionId: connectionId,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Create an AI Conversation ...
|
|
/// </summary>
|
|
/// <param name="projectId"></param>
|
|
/// <param name="item"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
[HttpPost("Projects/{projectId}/Conversations")]
|
|
public async Task<ActionResult<XAiConversationDto>> CreateConversation(
|
|
[FromRoute] Guid projectId,
|
|
[FromBody] XAiConversationDto item,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
try
|
|
{
|
|
//
|
|
// Validate ...
|
|
if (projectId.IsDefaultGuid() ||
|
|
item.IsNullOrDefault())
|
|
{
|
|
XException.InvalidArgs.Throw();
|
|
}
|
|
|
|
//
|
|
var userInfo = await GetUserInfo();
|
|
var connectionId = GetConnectionId();
|
|
|
|
//
|
|
// Update Required Params ...
|
|
item.OwnerId = userInfo.UserId;
|
|
if (!item.IsValidForAddOrUpdate())
|
|
{
|
|
XException.InvalidData.Throw();
|
|
}
|
|
|
|
//
|
|
var result = await aiService.CreateConversation(
|
|
item: item,
|
|
projectId: projectId,
|
|
ownerId: userInfo.UserId,
|
|
connectionId: connectionId,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Content Extraction ...
|
|
/// <summary>
|
|
/// Extract Files Content ...
|
|
/// </summary>
|
|
/// <param name="files"></param>
|
|
/// <param name="extractors"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("ExtractContent")]
|
|
[Consumes("multipart/form-data")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public async Task<ActionResult<string>> ExtractContent(
|
|
[FromForm] IFormFileCollection files,
|
|
[FromForm] string extractors = "*",
|
|
CancellationToken cancellationToken = default
|
|
) {
|
|
//
|
|
try
|
|
{
|
|
//
|
|
// Validate ...
|
|
if (!files.HasChild())
|
|
{
|
|
XException.InvalidArgs.Throw();
|
|
}
|
|
|
|
//
|
|
var userInfo = await GetUserInfo();
|
|
var connectionId = GetConnectionId();
|
|
|
|
//
|
|
string[] extractorArr = null;
|
|
if (!extractors.IsNullOrEmpty())
|
|
{
|
|
extractorArr = [.. extractors.ParseListString<string>()];
|
|
}
|
|
|
|
//
|
|
var result = await aiService.ExtractContent(
|
|
files: files,
|
|
extractors: extractorArr,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Data Actions ...
|
|
/// <summary>
|
|
/// Ask Question and Get Response ...
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Ask")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public async Task<ActionResult<string>> Ask(
|
|
[FromBody] XAiResponseRequest request,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
try
|
|
{
|
|
//
|
|
// Validate ...
|
|
if (!request.IsValid())
|
|
{
|
|
XException.InvalidArgs.Throw();
|
|
}
|
|
|
|
//
|
|
var userInfo = await GetUserInfo();
|
|
var connectionId = GetConnectionId();
|
|
|
|
//
|
|
// TODO: Reading Fiels Form Collection and Attach it ...
|
|
var result = await aiService.AskAsync(
|
|
files: null,
|
|
prompt: request.Prompt,
|
|
ownerId: userInfo.UserId,
|
|
connectionId: connectionId,
|
|
projectId: request.ProjectId,
|
|
cancellationToken: cancellationToken,
|
|
conversationId: request.ConversationId
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ask Question and Get Response Stream ...
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("AskStream")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public async Task AskStream(
|
|
[FromBody] XAiResponseRequest request,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
// Validate (before Stream Starts -> Proper Http Error) ...
|
|
if (!request.IsValid())
|
|
{
|
|
await WriteStreamValidationError();
|
|
return;
|
|
}
|
|
|
|
//
|
|
try
|
|
{
|
|
//
|
|
var userInfo = await GetUserInfo();
|
|
var connectionId = GetConnectionId();
|
|
|
|
//
|
|
// Configure SSE Response ...
|
|
Response.PrepareSseResponse();
|
|
|
|
//
|
|
// TODO: Reading Fiels Form Collection and Attach it ...
|
|
var enumerable = aiService.AskAsEnumerable(
|
|
files: null,
|
|
prompt: request.Prompt,
|
|
ownerId: userInfo.UserId,
|
|
connectionId: connectionId,
|
|
projectId: request.ProjectId,
|
|
cancellationToken: cancellationToken,
|
|
conversationId: request.ConversationId
|
|
);
|
|
|
|
//
|
|
// Format: data: {json}\n\n
|
|
await foreach (var resp in enumerable)
|
|
{
|
|
//
|
|
// Skip Empty Responses ...
|
|
if (resp.IsNullOrDefault())
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
await Response.WriteSseEventAsync(
|
|
data: resp,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
|
|
//
|
|
await Response.WriteSseDoneAsync(cancellationToken);
|
|
}
|
|
catch (Exception ex) when (ex.IsClientCancellation(cancellationToken))
|
|
{
|
|
// Client Disconnected ...
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
Logger.LogError(ex, "AskStream Failed");
|
|
if (!Response.HasStarted)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
await result.ExecuteResultAsync(ControllerContext);
|
|
return;
|
|
}
|
|
|
|
//
|
|
await Response.WriteSseErrorAsync(ex.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ask Question with Files and Get Response ...
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("AskWithFiles")]
|
|
[Consumes("multipart/form-data")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public async Task<ActionResult<string>> AskWithFiles(
|
|
[FromForm] XAiResponseRequest request,
|
|
[FromForm] IFormFileCollection files,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
try
|
|
{
|
|
//
|
|
// Validate ...
|
|
if (!request.IsValid())
|
|
{
|
|
XException.InvalidArgs.Throw();
|
|
}
|
|
|
|
//
|
|
var userInfo = await GetUserInfo();
|
|
var connectionId = GetConnectionId();
|
|
|
|
//
|
|
var result = await aiService.AskAsync(
|
|
files: files,
|
|
userInfo: userInfo,
|
|
prompt: request.Prompt,
|
|
ownerId: userInfo.UserId,
|
|
connectionId: connectionId,
|
|
projectId: request.ProjectId,
|
|
cancellationToken: cancellationToken,
|
|
conversationId: request.ConversationId
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
} |