diff --git a/Controllers/KnowledgeController.cs b/Controllers/KnowledgeController.cs index 4c8fd07..66d45a0 100644 --- a/Controllers/KnowledgeController.cs +++ b/Controllers/KnowledgeController.cs @@ -16,6 +16,7 @@ using xIdentityService.Interfaces; using xIdentityService.Controllers; using Microsoft.Extensions.Logging; using Microsoft.AspNetCore.Authorization; +using xIdentityHelper; namespace xAiApi.Controllers { @@ -58,9 +59,10 @@ namespace xAiApi.Controllers /// [HttpPost("Ingest")] [Consumes("multipart/form-data")] + [Authorize(Policy = XPolicies.EnabledAdmin)] public async Task> Ingest( [FromForm] IFormFileCollection files, - [FromForm] XAiKnowledgeScope scope = XAiKnowledgeScope.Global, + [FromForm] XAiKnowledgeScope? scope = XAiKnowledgeScope.Global, [FromForm] Guid? scopeId = null, [FromForm] string knowledgeType = null, [FromForm] bool replaceExisting = true, @@ -114,8 +116,9 @@ namespace xAiApi.Controllers /// /// [HttpGet("Documents")] + [Authorize(Policy = XPolicies.EnabledAdmin)] public async Task>> Documents( - [FromQuery] XAiKnowledgeScope scope = XAiKnowledgeScope.User, + [FromQuery] XAiKnowledgeScope? scope = XAiKnowledgeScope.Global, [FromQuery] Guid? scopeId = null, [FromQuery] string knowledgeType = null, CancellationToken cancellationToken = default @@ -126,12 +129,13 @@ namespace xAiApi.Controllers { // var userInfo = await GetUserInfo(); + var scopeIdentifier = BuildScope(scope, scopeId, knowledgeType); // var result = await ragService.LoadDocumentsAsync( userInfo: userInfo, - cancellationToken: cancellationToken, - scope: BuildScope(scope, scopeId, knowledgeType) + scope: scopeIdentifier, + cancellationToken: cancellationToken ); // @@ -154,9 +158,10 @@ namespace xAiApi.Controllers /// /// Count of Removed Vectors [HttpDelete("Documents")] + [Authorize(Policy = XPolicies.EnabledAdmin)] public async Task> DeleteDocument( [FromQuery] string fileName, - [FromQuery] XAiKnowledgeScope scope = XAiKnowledgeScope.User, + [FromQuery] XAiKnowledgeScope? scope = XAiKnowledgeScope.Global, [FromQuery] Guid? scopeId = null, CancellationToken cancellationToken = default ) @@ -197,15 +202,21 @@ namespace xAiApi.Controllers /// Build Scope Descriptor from Request Params ... /// private XAiKnowledgeScopeDescriptor BuildScope( - XAiKnowledgeScope scope, + XAiKnowledgeScope? scope, Guid? scopeId, string knowledgeType ) { + // + if (!scope.HasValue) + { + scope = XAiKnowledgeScope.Global; + } + // var result = new XAiKnowledgeScopeDescriptor { - Scope = scope, + Scope = scope.Value, ScopeId = scopeId, Type = knowledgeType, }; diff --git a/Providers/XAIServiceBase.cs b/Providers/XAIServiceBase.cs index 2e174da..1ab04ff 100644 --- a/Providers/XAIServiceBase.cs +++ b/Providers/XAIServiceBase.cs @@ -1342,23 +1342,28 @@ namespace xAiApi.Providers // var contextBlock = BuildContextBlock(context); - var systemText = - $"{introductionPrompt}{Environment.NewLine}{Environment.NewLine}" + - $"{ragPrompt}{Environment.NewLine}{Environment.NewLine}" + - $"Context:{Environment.NewLine}{contextBlock}"; + var systemText = introductionPrompt; + if (context.HasChild() && + !contextBlock.IsNullOrEmpty()) + { + // + systemText = + $"{introductionPrompt}{Environment.NewLine}{Environment.NewLine}" + + $"{ragPrompt}{Environment.NewLine}{Environment.NewLine}" + + $"Context:{Environment.NewLine}{contextBlock}"; + } // // Apply Project Prompt as System Text ... if (!project.IsNullOrDefault() && !project.Prompt.IsNullOrEmpty()) { - systemText += $"Project:{Environment.NewLine}{project.Prompt}"; + systemText += $"{project.Prompt}{Environment.NewLine}"; } // // Add System Message ... - result - .Add(new ChatMessage(ChatRole.System, systemText)); + result.Add(new ChatMessage(ChatRole.System, systemText)); // // Attach Message ...