Compare commits

..
1 Commits
Author SHA1 Message Date
saherelm 51dddb4b68 last ... 2026-11-01 18:11:26 +03:30
2 changed files with 30 additions and 14 deletions
+18 -7
View File
@@ -16,6 +16,7 @@ using xIdentityService.Interfaces;
using xIdentityService.Controllers; using xIdentityService.Controllers;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using xIdentityHelper;
namespace xAiApi.Controllers namespace xAiApi.Controllers
{ {
@@ -58,9 +59,10 @@ namespace xAiApi.Controllers
/// <returns></returns> /// <returns></returns>
[HttpPost("Ingest")] [HttpPost("Ingest")]
[Consumes("multipart/form-data")] [Consumes("multipart/form-data")]
[Authorize(Policy = XPolicies.EnabledAdmin)]
public async Task<ActionResult<XAiKnowledgeIngestResult>> Ingest( public async Task<ActionResult<XAiKnowledgeIngestResult>> Ingest(
[FromForm] IFormFileCollection files, [FromForm] IFormFileCollection files,
[FromForm] XAiKnowledgeScope scope = XAiKnowledgeScope.Global, [FromForm] XAiKnowledgeScope? scope = XAiKnowledgeScope.Global,
[FromForm] Guid? scopeId = null, [FromForm] Guid? scopeId = null,
[FromForm] string knowledgeType = null, [FromForm] string knowledgeType = null,
[FromForm] bool replaceExisting = true, [FromForm] bool replaceExisting = true,
@@ -114,8 +116,9 @@ namespace xAiApi.Controllers
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
[HttpGet("Documents")] [HttpGet("Documents")]
[Authorize(Policy = XPolicies.EnabledAdmin)]
public async Task<ActionResult<IList<XAiKnowledgeDocumentInfo>>> Documents( public async Task<ActionResult<IList<XAiKnowledgeDocumentInfo>>> Documents(
[FromQuery] XAiKnowledgeScope scope = XAiKnowledgeScope.User, [FromQuery] XAiKnowledgeScope? scope = XAiKnowledgeScope.Global,
[FromQuery] Guid? scopeId = null, [FromQuery] Guid? scopeId = null,
[FromQuery] string knowledgeType = null, [FromQuery] string knowledgeType = null,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
@@ -126,12 +129,13 @@ namespace xAiApi.Controllers
{ {
// //
var userInfo = await GetUserInfo(); var userInfo = await GetUserInfo();
var scopeIdentifier = BuildScope(scope, scopeId, knowledgeType);
// //
var result = await ragService.LoadDocumentsAsync( var result = await ragService.LoadDocumentsAsync(
userInfo: userInfo, userInfo: userInfo,
cancellationToken: cancellationToken, scope: scopeIdentifier,
scope: BuildScope(scope, scopeId, knowledgeType) cancellationToken: cancellationToken
); );
// //
@@ -154,9 +158,10 @@ namespace xAiApi.Controllers
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns>Count of Removed Vectors</returns> /// <returns>Count of Removed Vectors</returns>
[HttpDelete("Documents")] [HttpDelete("Documents")]
[Authorize(Policy = XPolicies.EnabledAdmin)]
public async Task<ActionResult<int>> DeleteDocument( public async Task<ActionResult<int>> DeleteDocument(
[FromQuery] string fileName, [FromQuery] string fileName,
[FromQuery] XAiKnowledgeScope scope = XAiKnowledgeScope.User, [FromQuery] XAiKnowledgeScope? scope = XAiKnowledgeScope.Global,
[FromQuery] Guid? scopeId = null, [FromQuery] Guid? scopeId = null,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
@@ -197,15 +202,21 @@ namespace xAiApi.Controllers
/// Build Scope Descriptor from Request Params ... /// Build Scope Descriptor from Request Params ...
/// </summary> /// </summary>
private XAiKnowledgeScopeDescriptor BuildScope( private XAiKnowledgeScopeDescriptor BuildScope(
XAiKnowledgeScope scope, XAiKnowledgeScope? scope,
Guid? scopeId, Guid? scopeId,
string knowledgeType string knowledgeType
) )
{ {
//
if (!scope.HasValue)
{
scope = XAiKnowledgeScope.Global;
}
// //
var result = new XAiKnowledgeScopeDescriptor var result = new XAiKnowledgeScopeDescriptor
{ {
Scope = scope, Scope = scope.Value,
ScopeId = scopeId, ScopeId = scopeId,
Type = knowledgeType, Type = knowledgeType,
}; };
+9 -4
View File
@@ -1342,23 +1342,28 @@ namespace xAiApi.Providers
// //
var contextBlock = BuildContextBlock(context); var contextBlock = BuildContextBlock(context);
var systemText = var systemText = introductionPrompt;
if (context.HasChild() &&
!contextBlock.IsNullOrEmpty())
{
//
systemText =
$"{introductionPrompt}{Environment.NewLine}{Environment.NewLine}" + $"{introductionPrompt}{Environment.NewLine}{Environment.NewLine}" +
$"{ragPrompt}{Environment.NewLine}{Environment.NewLine}" + $"{ragPrompt}{Environment.NewLine}{Environment.NewLine}" +
$"Context:{Environment.NewLine}{contextBlock}"; $"Context:{Environment.NewLine}{contextBlock}";
}
// //
// Apply Project Prompt as System Text ... // Apply Project Prompt as System Text ...
if (!project.IsNullOrDefault() && if (!project.IsNullOrDefault() &&
!project.Prompt.IsNullOrEmpty()) !project.Prompt.IsNullOrEmpty())
{ {
systemText += $"Project:{Environment.NewLine}{project.Prompt}"; systemText += $"{project.Prompt}{Environment.NewLine}";
} }
// //
// Add System Message ... // Add System Message ...
result result.Add(new ChatMessage(ChatRole.System, systemText));
.Add(new ChatMessage(ChatRole.System, systemText));
// //
// Attach Message ... // Attach Message ...