Compare commits
27
Commits
ad8ea9c1dd
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a228439a5 | ||
|
|
13cd0745c6 | ||
|
|
5bccce3475 | ||
|
|
cddf2650f5 | ||
|
|
fba69b274c | ||
|
|
0077008105 | ||
|
|
3dc54332c2 | ||
|
|
dab384ea37 | ||
|
|
f6a916fa83 | ||
|
|
5656ec07d5 | ||
|
|
c24c14eb74 | ||
|
|
b58f1dd736 | ||
|
|
31add513bc | ||
|
|
16fb715926 | ||
|
|
5307fe4d2f | ||
|
|
ae7f5920c1 | ||
|
|
97acf0a123 | ||
|
|
c7efdd5525 | ||
|
|
937e30dd9d | ||
|
|
c61f8aec98 | ||
|
|
a870d61e61 | ||
|
|
726d6ce827 | ||
|
|
fa1014bf20 | ||
|
|
ce4e5927dd | ||
|
|
51dddb4b68 | ||
|
|
ce5db9e349 | ||
|
|
c1173042d4 |
@@ -1,6 +1,7 @@
|
|||||||
#
|
#
|
||||||
bin/*
|
bin/*
|
||||||
obj/*
|
obj/*
|
||||||
|
Logs
|
||||||
|
|
||||||
#
|
#
|
||||||
Db/*
|
Db/*
|
||||||
|
|||||||
@@ -45,5 +45,11 @@ namespace xAiApi.Configurations
|
|||||||
/// RAG Configuration ...
|
/// RAG Configuration ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public XAiDocumentRAGDescriptor RAGDescriptor {get; set;} = new();
|
public XAiDocumentRAGDescriptor RAGDescriptor {get; set;} = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// DateTime Configuration ...
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public XDateTimeDescriptor DateTime { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,7 +16,7 @@ namespace xAiApi.Constants
|
|||||||
public const string XAiApiContentExtractionPromptName = "ContentExtraction";
|
public const string XAiApiContentExtractionPromptName = "ContentExtraction";
|
||||||
|
|
||||||
//
|
//
|
||||||
public const string XAiDefaultModelName = "Gemma";
|
public const string XAiDefaultModelName = "Arion";
|
||||||
public const string XAiEmbeddingModelName = "Embed";
|
public const string XAiEmbeddingModelName = "Embed";
|
||||||
public const string XAiDefaultVisionModelName = "Qwen";
|
public const string XAiDefaultVisionModelName = "Qwen";
|
||||||
public const string XAiDefaultThinkingModelName = "Qwen";
|
public const string XAiDefaultThinkingModelName = "Qwen";
|
||||||
|
|||||||
@@ -28,13 +28,12 @@ namespace xAiApi.Controllers
|
|||||||
/// Flow: Ingest Files -> SessionId -> Ask / AskStream -> Delete Session
|
/// Flow: Ingest Files -> SessionId -> Ask / AskStream -> Delete Session
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[Route("[controller]")]
|
|
||||||
public class ChatWithDocumentsController : XBaseIdentityApiV1Controller
|
public class ChatWithDocumentsController : XBaseIdentityApiV1Controller
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default AI Service ...
|
/// Default AI Service ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly IXDefaultAiService aiService;
|
private readonly IXAiService aiService;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Text Chunker Service ...
|
/// Text Chunker Service ...
|
||||||
@@ -62,8 +61,8 @@ namespace xAiApi.Controllers
|
|||||||
private readonly IXFileContentExtractor fileContentExtractor;
|
private readonly IXFileContentExtractor fileContentExtractor;
|
||||||
|
|
||||||
public ChatWithDocumentsController(
|
public ChatWithDocumentsController(
|
||||||
|
IXAiService aiService,
|
||||||
IXTextChunker textChunker,
|
IXTextChunker textChunker,
|
||||||
IXDefaultAiService aiService,
|
|
||||||
IXInMemoryVectorStore vectorStore,
|
IXInMemoryVectorStore vectorStore,
|
||||||
XAppConfiguration appConfiguration,
|
XAppConfiguration appConfiguration,
|
||||||
IXIdentityProvider identityProvider,
|
IXIdentityProvider identityProvider,
|
||||||
@@ -189,8 +188,8 @@ namespace xAiApi.Controllers
|
|||||||
// Embed in Batches ...
|
// Embed in Batches ...
|
||||||
var fileVectors = await EmbedChunks(
|
var fileVectors = await EmbedChunks(
|
||||||
chunks: chunks,
|
chunks: chunks,
|
||||||
mimeType: mimeType,
|
|
||||||
fileName: file.FileName,
|
fileName: file.FileName,
|
||||||
|
mimeType: mimeType,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -285,9 +284,10 @@ namespace xAiApi.Controllers
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Generate ...
|
// Generate ...
|
||||||
result.Answer = await aiService.AskWithContextAsync(
|
result.Answer = await aiService.AskTextByContextAsync(
|
||||||
prompt: request.Prompt,
|
|
||||||
context: context,
|
context: context,
|
||||||
|
userInfo: userInfo,
|
||||||
|
prompt: request.Prompt,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -367,9 +367,10 @@ namespace xAiApi.Controllers
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Stream Deltas ...
|
// Stream Deltas ...
|
||||||
var enumerable = aiService.AskWithContextAsEnumerable(
|
var enumerable = aiService.AskTextByContextAsEnumerable(
|
||||||
prompt: request.Prompt,
|
|
||||||
context: context,
|
context: context,
|
||||||
|
userInfo: userInfo,
|
||||||
|
prompt: request.Prompt,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
await foreach (var delta in enumerable)
|
await foreach (var delta in enumerable)
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
using xAiApi.Interfaces;
|
|
||||||
using xCommons.Providers;
|
|
||||||
using xCommons.Configurations;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using xIdentityService.Interfaces;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
|
|
||||||
namespace xAiApi.Controllers
|
|
||||||
{
|
|
||||||
[Authorize]
|
|
||||||
[Route("[controller]")]
|
|
||||||
public class DefaultEmbeddingController : XAiEmbeddingServiceControllerBase<IXAiEmbeddingService>
|
|
||||||
{
|
|
||||||
public DefaultEmbeddingController(
|
|
||||||
ILogger<DefaultEmbeddingController> logger,
|
|
||||||
IXAiEmbeddingService embeddingService,
|
|
||||||
XAppConfiguration appConfiguration,
|
|
||||||
IXIdentityProvider identityProvider,
|
|
||||||
XValidationProvider validationProvider
|
|
||||||
) : base(
|
|
||||||
logger: logger,
|
|
||||||
appConfiguration: appConfiguration,
|
|
||||||
identityProvider: identityProvider,
|
|
||||||
embeddingService: embeddingService,
|
|
||||||
validationProvider: validationProvider
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
using xAiApi.Interfaces;
|
|
||||||
using xCommons.Providers;
|
|
||||||
using xCommons.Configurations;
|
|
||||||
using xIdentityService.Interfaces;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace xAiApi.Controllers
|
|
||||||
{
|
|
||||||
public class DefaultThinkingAiController : XAiServiceControllerBase<IXDefaultThinkingAiService>
|
|
||||||
{
|
|
||||||
public DefaultThinkingAiController(
|
|
||||||
ILogger<DefaultThinkingAiController> logger,
|
|
||||||
IXDefaultThinkingAiService aiService,
|
|
||||||
XAppConfiguration appConfiguration,
|
|
||||||
IXIdentityProvider identityProvider,
|
|
||||||
XValidationProvider validationProvider
|
|
||||||
) : base(
|
|
||||||
logger,
|
|
||||||
aiService,
|
|
||||||
appConfiguration,
|
|
||||||
identityProvider,
|
|
||||||
validationProvider
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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
|
||||||
{
|
{
|
||||||
@@ -24,7 +25,6 @@ namespace xAiApi.Controllers
|
|||||||
/// Flow: Ingest Files -> Ask / AskStream (Retrieve from DB -> Generate) -> Documents / Delete
|
/// Flow: Ingest Files -> Ask / AskStream (Retrieve from DB -> Generate) -> Documents / Delete
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[Route("[controller]")]
|
|
||||||
public class KnowledgeController : XBaseIdentityApiV1Controller
|
public class KnowledgeController : XBaseIdentityApiV1Controller
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -58,9 +58,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 +115,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 +128,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 +157,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 +201,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,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,501 @@
|
|||||||
|
using System;
|
||||||
|
using xModels.Dtos;
|
||||||
|
using xIdentityHelper;
|
||||||
|
using System.Threading;
|
||||||
|
using xAiApi.Interfaces;
|
||||||
|
using xCommons.Providers;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xAiModels.Extensions;
|
||||||
|
using xAiModels.Models.Dtos;
|
||||||
|
using xExceptions.Constants;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using xCommons.Configurations;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using xIdentityService.Interfaces;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using xIdentityService.Controllers;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
|
namespace xAiApi.Controllers
|
||||||
|
{
|
||||||
|
[Authorize]
|
||||||
|
public class McpServersController : XBaseIdentityApiV1Controller
|
||||||
|
{
|
||||||
|
private readonly IXAiMcpServerProvider mcpServerProvider;
|
||||||
|
|
||||||
|
public McpServersController(
|
||||||
|
XAppConfiguration appConfiguration,
|
||||||
|
IXIdentityProvider identityProvider,
|
||||||
|
ILogger<McpServersController> logger,
|
||||||
|
XValidationProvider validationProvider,
|
||||||
|
IXAiMcpServerProvider mcpServerProvider
|
||||||
|
) : base(
|
||||||
|
logger,
|
||||||
|
appConfiguration,
|
||||||
|
identityProvider,
|
||||||
|
validationProvider
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.mcpServerProvider = mcpServerProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Provider ...
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve Specified MCP Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public virtual async Task<ActionResult<XAiMcpServerDto>> GetMcpServer(
|
||||||
|
[FromRoute] Guid id,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (!ModelState.IsValid || id.IsDefaultGuid())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
var connectionId = GetConnectionId();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await mcpServerProvider.GetMcpServer(
|
||||||
|
id: id,
|
||||||
|
userInfo: userInfo,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add MCP Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public virtual async Task<ActionResult<XAiMcpServerDto>> AddMcpServer(
|
||||||
|
[FromBody] XAiMcpServerDto item,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (!ModelState.IsValid || item.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
var connectionId = GetConnectionId();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await mcpServerProvider.AddMcpServer(
|
||||||
|
item: item,
|
||||||
|
userInfo: userInfo,
|
||||||
|
connectionId: connectionId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update Specified MCP Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPut("{id}")]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public virtual async Task<ActionResult<XAiMcpServerDto>> UpdateMcpServer(
|
||||||
|
[FromRoute] Guid id,
|
||||||
|
[FromBody] XAiMcpServerDto item,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (id.IsDefaultGuid() ||
|
||||||
|
!ModelState.IsValid ||
|
||||||
|
!item.IsValidForAddOrUpdate())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
var connectionId = GetConnectionId();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await mcpServerProvider.UpdateMcpServer(
|
||||||
|
id: id,
|
||||||
|
item: item,
|
||||||
|
userInfo: userInfo,
|
||||||
|
connectionId: connectionId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove Specified MCP Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public virtual async Task<ActionResult<XAiMcpServerDto>> RemoveMcpServer(
|
||||||
|
[FromRoute] Guid id,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (!ModelState.IsValid || id.IsDefaultGuid())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
var connectionId = GetConnectionId();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await mcpServerProvider.RemoveMcpServer(
|
||||||
|
id: id,
|
||||||
|
userInfo: userInfo,
|
||||||
|
connectionId: connectionId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enable Specified MCP Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("{id}/Enable")]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public virtual async Task<ActionResult<bool>> EnableMcpServer(
|
||||||
|
[FromRoute] Guid id,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (!ModelState.IsValid || id.IsDefaultGuid())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
var connectionId = GetConnectionId();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await mcpServerProvider.EnableMcpServer(
|
||||||
|
id: id,
|
||||||
|
userInfo: userInfo,
|
||||||
|
connectionId: connectionId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Disable Specified MCP Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("{id}/Disable")]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public virtual async Task<ActionResult<bool>> DisableMcpServer(
|
||||||
|
[FromRoute] Guid id,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (!ModelState.IsValid || id.IsDefaultGuid())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
var connectionId = GetConnectionId();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await mcpServerProvider.DisableMcpServer(
|
||||||
|
id: id,
|
||||||
|
userInfo: userInfo,
|
||||||
|
connectionId: connectionId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Toggle Specified MCP Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("{id}/Toggle")]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public virtual async Task<ActionResult<bool>> ToggleMcpServer(
|
||||||
|
[FromRoute] Guid id,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (!ModelState.IsValid || id.IsDefaultGuid())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
var connectionId = GetConnectionId();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await mcpServerProvider.ToggleMcpServer(
|
||||||
|
id: id,
|
||||||
|
userInfo: userInfo,
|
||||||
|
connectionId: connectionId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get all Registered MCP Servers by handling Ownership ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public virtual async Task<ActionResult<IEnumerable<XAiMcpServerDto>>> GetMcpServers(
|
||||||
|
[FromQuery] bool forceOwner = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
var connectionId = GetConnectionId();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await mcpServerProvider.GetAll(
|
||||||
|
userInfo: userInfo,
|
||||||
|
forceOwner: forceOwner,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Query Registered MCP Servers by handling Ownership ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="forceOwner"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("Query")]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public virtual async Task<ActionResult<XQueryResult<XAiMcpServerDto>>> QueryMcpServers(
|
||||||
|
[FromQuery] XQuery query,
|
||||||
|
[FromQuery] bool forceOwner = true,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
await ValidationProvider
|
||||||
|
.GroupValidationBuilder()
|
||||||
|
.AddNotNull(query)
|
||||||
|
.ValidateGroupAsync();
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
var connectionId = GetConnectionId();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await mcpServerProvider.Query(
|
||||||
|
query: query,
|
||||||
|
userInfo: userInfo,
|
||||||
|
forceOwner: forceOwner,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result.ToDynamicObject());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Refresh MCP Servers ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("Refresh")]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
||||||
|
public async Task<ActionResult> RefreshMcpServers(
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
|
||||||
|
//
|
||||||
|
await mcpServerProvider.RefreshAsync(
|
||||||
|
userInfo: userInfo,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok();
|
||||||
|
} catch(Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
using xAiApi.Interfaces;
|
using xAiApi.Interfaces;
|
||||||
using xCommons.Providers;
|
using xCommons.Providers;
|
||||||
using xCommons.Configurations;
|
using xCommons.Configurations;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using xIdentityService.Interfaces;
|
using xIdentityService.Interfaces;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
@@ -9,12 +8,11 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
namespace xAiApi.Controllers
|
namespace xAiApi.Controllers
|
||||||
{
|
{
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[Route("[controller]")]
|
public class XAiController : XAiServiceControllerBase<IXAiService>
|
||||||
public class DefaultAiController : XAiServiceControllerBase<IXDefaultAiService>
|
|
||||||
{
|
{
|
||||||
public DefaultAiController(
|
public XAiController(
|
||||||
ILogger<DefaultAiController> logger,
|
ILogger<XAiController> logger,
|
||||||
IXDefaultAiService aiService,
|
IXAiService aiService,
|
||||||
XAppConfiguration appConfiguration,
|
XAppConfiguration appConfiguration,
|
||||||
IXIdentityProvider identityProvider,
|
IXIdentityProvider identityProvider,
|
||||||
XValidationProvider validationProvider
|
XValidationProvider validationProvider
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Threading;
|
|
||||||
using xAiApi.Interfaces;
|
|
||||||
using xCommons.Providers;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using xCommons.Configurations;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
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 XAiEmbeddingServiceControllerBase<TEmbeddingService> : XBaseIdentityApiV1Controller, IXAiEmbeddingServiceControllerBase
|
|
||||||
where TEmbeddingService : IXAiEmbeddingServiceBase
|
|
||||||
{
|
|
||||||
private readonly TEmbeddingService embeddingService;
|
|
||||||
|
|
||||||
protected XAiEmbeddingServiceControllerBase(
|
|
||||||
ILogger logger,
|
|
||||||
XAppConfiguration appConfiguration,
|
|
||||||
IXIdentityProvider identityProvider,
|
|
||||||
XValidationProvider validationProvider,
|
|
||||||
TEmbeddingService embeddingService
|
|
||||||
) : base(
|
|
||||||
logger,
|
|
||||||
appConfiguration,
|
|
||||||
identityProvider,
|
|
||||||
validationProvider
|
|
||||||
)
|
|
||||||
{
|
|
||||||
this.embeddingService = embeddingService;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Request For Embedding Specified String ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="content"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[AllowAnonymous]
|
|
||||||
[HttpGet("Embedding")]
|
|
||||||
public async Task<ActionResult<float[]>> Embedding(
|
|
||||||
[FromQuery] string content,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate ...
|
|
||||||
ValidationProvider.NotEmpty(content);
|
|
||||||
|
|
||||||
//
|
|
||||||
var result = await embeddingService.Embedding(
|
|
||||||
content: content,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = GetExceptionActionResult(ex);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Request For Embedding Specified Batch ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="batch"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[AllowAnonymous]
|
|
||||||
[HttpGet("Embeddings")]
|
|
||||||
public async Task<ActionResult<IReadOnlyList<float[]>>> Embeddings(
|
|
||||||
[FromQuery] string[] batch,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate ...
|
|
||||||
ValidationProvider.NotZeroChilds(batch);
|
|
||||||
|
|
||||||
//
|
|
||||||
var result = await embeddingService.Embeddings(
|
|
||||||
batch: batch,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = GetExceptionActionResult(ex);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -24,8 +24,7 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
namespace xAiApi.Controllers
|
namespace xAiApi.Controllers
|
||||||
{
|
{
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[Route("[controller]")]
|
public abstract class XAiServiceControllerBase<TAiService> : XBaseIdentityApiV1Controller
|
||||||
public abstract class XAiServiceControllerBase<TAiService> : XBaseIdentityApiV1Controller, IXAiServiceControllerBase
|
|
||||||
where TAiService : IXAiServiceBase
|
where TAiService : IXAiServiceBase
|
||||||
{
|
{
|
||||||
private readonly TAiService aiService;
|
private readonly TAiService aiService;
|
||||||
@@ -68,9 +67,13 @@ namespace xAiApi.Controllers
|
|||||||
// Validate ...
|
// Validate ...
|
||||||
ValidationProvider.NotEmpty(question);
|
ValidationProvider.NotEmpty(question);
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
|
||||||
//
|
//
|
||||||
var result = await aiService.AskTextAsync(
|
var result = await aiService.AskTextAsync(
|
||||||
prompt: question,
|
prompt: question,
|
||||||
|
userInfo: userInfo,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -113,9 +116,13 @@ namespace xAiApi.Controllers
|
|||||||
// Configure SSE Response ...
|
// Configure SSE Response ...
|
||||||
Response.PrepareSseResponse();
|
Response.PrepareSseResponse();
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
|
||||||
//
|
//
|
||||||
var enumerable = aiService.AskTextAsEnumerable(
|
var enumerable = aiService.AskTextAsEnumerable(
|
||||||
prompt: question,
|
prompt: question,
|
||||||
|
userInfo: userInfo,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -162,16 +169,420 @@ namespace xAiApi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write Validation Error for Streaming Endpoints (before Stream Starts) ...
|
/// Ask a Question By Rag Retrive From Knowledge ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[NonAction]
|
[HttpGet("AskTextFromKnowledge")]
|
||||||
protected async Task WriteStreamValidationError()
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public virtual async Task<ActionResult<string>> AskTextFromKnowledge(
|
||||||
|
[FromQuery] XAiResponseRequest request,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
Response.StatusCode = StatusCodes.Status400BadRequest;
|
try
|
||||||
Response.ContentType = "application/json; charset=utf-8";
|
{
|
||||||
await Response.WriteAsync(XException.InvalidArgs.ToXError().ToJSON());
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (!request.IsValid())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
var connectionId = GetConnectionId();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await aiService.AskTextFromKnowledgeAsync(
|
||||||
|
topK: request.TopK,
|
||||||
|
userInfo: userInfo,
|
||||||
|
type: request.Type,
|
||||||
|
prompt: request.Prompt,
|
||||||
|
minScore: request.MinScore,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ask a Question By Rag Retrive From Knowledge and Stream Response ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("AskTextFromKnowledgeStream")]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public virtual async Task AskTextFromKnowledgeStream(
|
||||||
|
[FromQuery] 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();
|
||||||
|
|
||||||
|
//
|
||||||
|
var enumerable = aiService.AskTextFromKnowledgeAsEnumerable(
|
||||||
|
topK: request.TopK,
|
||||||
|
userInfo: userInfo,
|
||||||
|
type: request.Type,
|
||||||
|
prompt: request.Prompt,
|
||||||
|
minScore: request.MinScore,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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 and Get Response ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("Ask")]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public virtual 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();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await aiService.AskAsync(
|
||||||
|
files: null,
|
||||||
|
topK: request.TopK,
|
||||||
|
userInfo: userInfo,
|
||||||
|
type: request.Type,
|
||||||
|
prompt: request.Prompt,
|
||||||
|
minScore: request.MinScore,
|
||||||
|
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 virtual 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();
|
||||||
|
|
||||||
|
//
|
||||||
|
var enumerable = aiService.AskAsEnumerable(
|
||||||
|
files: null,
|
||||||
|
topK: request.TopK,
|
||||||
|
userInfo: userInfo,
|
||||||
|
type: request.Type,
|
||||||
|
prompt: request.Prompt,
|
||||||
|
minScore: request.MinScore,
|
||||||
|
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 virtual 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,
|
||||||
|
topK: request.TopK,
|
||||||
|
userInfo: userInfo,
|
||||||
|
type: request.Type,
|
||||||
|
prompt: request.Prompt,
|
||||||
|
minScore: request.MinScore,
|
||||||
|
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 with Files and Get Response Stream ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("AskWithFilesStream")]
|
||||||
|
[Consumes("multipart/form-data")]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public virtual async Task AskWithFilesStream(
|
||||||
|
[FromForm] XAiResponseRequest request,
|
||||||
|
[FromForm] IFormFileCollection files,
|
||||||
|
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();
|
||||||
|
|
||||||
|
//
|
||||||
|
var enumerable = aiService.AskAsEnumerable(
|
||||||
|
files: files,
|
||||||
|
topK: request.TopK,
|
||||||
|
userInfo: userInfo,
|
||||||
|
type: request.Type,
|
||||||
|
prompt: request.Prompt,
|
||||||
|
minScore: request.MinScore,
|
||||||
|
connectionId: connectionId,
|
||||||
|
extractFileContents: false,
|
||||||
|
addFilesToKnowledge: false,
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -225,7 +636,7 @@ namespace xAiApi.Controllers
|
|||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
[HttpGet("Projects/{projectId}/Conversations")]
|
[HttpGet("Projects/{projectId}/Conversations")]
|
||||||
public async Task<ActionResult<IEnumerable<XAiConversationDto>>> LoadConversations(
|
public async Task<ActionResult<IEnumerable<XAiConversationDto>>> LoadConversations(
|
||||||
[FromRoute] Guid projectId,
|
[FromRoute] Guid? projectId,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -233,12 +644,44 @@ namespace xAiApi.Controllers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Validate ...
|
var userInfo = await GetUserInfo();
|
||||||
if (projectId.IsDefaultGuid())
|
var connectionId = GetConnectionId();
|
||||||
{
|
|
||||||
XException.InvalidArgs.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await aiService.LoadConversations(
|
||||||
|
projectId: projectId,
|
||||||
|
ownerId: userInfo.UserId,
|
||||||
|
connectionId: connectionId,
|
||||||
|
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/Conversations")]
|
||||||
|
public async Task<ActionResult<IEnumerable<XAiConversationDto>>> LoadProjectConversations(
|
||||||
|
[FromQuery] Guid? projectId,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var userInfo = await GetUserInfo();
|
var userInfo = await GetUserInfo();
|
||||||
var connectionId = GetConnectionId();
|
var connectionId = GetConnectionId();
|
||||||
@@ -246,6 +689,7 @@ namespace xAiApi.Controllers
|
|||||||
//
|
//
|
||||||
var result = await aiService.LoadConversations(
|
var result = await aiService.LoadConversations(
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
ownerId: userInfo.UserId,
|
||||||
connectionId: connectionId,
|
connectionId: connectionId,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
@@ -270,7 +714,7 @@ namespace xAiApi.Controllers
|
|||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
[HttpGet("Conversations/{conversationId}/Messages")]
|
[HttpGet("Conversations/{conversationId}/Messages")]
|
||||||
public async Task<ActionResult<IEnumerable<XAiMessageDto>>> LoadMessages(
|
public async Task<ActionResult<IEnumerable<XAiMessageDto>>> LoadMessages(
|
||||||
[FromRoute] Guid conversationId,
|
[FromRoute] Guid? conversationId,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -278,14 +722,52 @@ namespace xAiApi.Controllers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Validate ...
|
var userInfo = await GetUserInfo();
|
||||||
if (conversationId.IsDefaultGuid())
|
var connectionId = GetConnectionId();
|
||||||
{
|
|
||||||
XException.InvalidArgs.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
var result = await aiService.LoadMessages(
|
var result = await aiService.LoadMessages(
|
||||||
|
ownerId: userInfo.UserId,
|
||||||
|
connectionId: connectionId,
|
||||||
|
conversationId: conversationId,
|
||||||
|
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/Messages")]
|
||||||
|
public async Task<ActionResult<IEnumerable<XAiMessageDto>>> LoadConversationMessages(
|
||||||
|
[FromQuery] Guid? conversationId,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
var connectionId = GetConnectionId();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await aiService.LoadMessages(
|
||||||
|
ownerId: userInfo.UserId,
|
||||||
|
connectionId: connectionId,
|
||||||
conversationId: conversationId,
|
conversationId: conversationId,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
@@ -540,6 +1022,63 @@ namespace xAiApi.Controllers
|
|||||||
return result;
|
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/Conversations")]
|
||||||
|
public async Task<ActionResult<XAiConversationDto>> CreateProjectConversation(
|
||||||
|
[FromQuery] Guid? projectId,
|
||||||
|
[FromBody] XAiConversationDto 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.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
|
#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -556,9 +1095,10 @@ namespace xAiApi.Controllers
|
|||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
public async Task<ActionResult<string>> ExtractContent(
|
public async Task<ActionResult<string>> ExtractContent(
|
||||||
[FromForm] IFormFileCollection files,
|
[FromForm] IFormFileCollection files,
|
||||||
[FromForm] string extractors = "*",
|
[FromForm] string extractors = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -599,192 +1139,18 @@ namespace xAiApi.Controllers
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
#region Data Actions ...
|
#region Non Actions ...
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ask Question and Get Response ...
|
/// Write Validation Error for Streaming Endpoints (before Stream Starts) ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("Ask")]
|
[NonAction]
|
||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
protected async Task WriteStreamValidationError()
|
||||||
public async Task<ActionResult<string>> Ask(
|
|
||||||
[FromBody] XAiResponseRequest request,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
try
|
Response.StatusCode = StatusCodes.Status400BadRequest;
|
||||||
{
|
Response.ContentType = "application/json; charset=utf-8";
|
||||||
//
|
await Response.WriteAsync(XException.InvalidArgs.ToXError().ToJSON());
|
||||||
// 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.Value,
|
|
||||||
cancellationToken: cancellationToken,
|
|
||||||
conversationId: request.ConversationId.Value
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
// 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
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ namespace xAiApi.DI
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
source.AddScoped<IXDefaultAiService, XDefaultAiService>();
|
source.AddScoped<IXAiService, XAiService>();
|
||||||
source.AddScoped<IXDefaultThinkingAiService, XDefaultThinkingAiService>();
|
source.AddScoped<IXDefaultThinkingAiService, XDefaultThinkingAiService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using xDataService.Db;
|
||||||
using xAiApi.Constants;
|
using xAiApi.Constants;
|
||||||
using xAiModels.Providers;
|
using xAiModels.Providers;
|
||||||
using xDataService.Configuration;
|
using xTagService.Providers;
|
||||||
using xDataService.Db;
|
|
||||||
using xDataService.Providers;
|
using xDataService.Providers;
|
||||||
using xFileService.Providers;
|
using xFileService.Providers;
|
||||||
using xStringService.Providers;
|
using xStringService.Providers;
|
||||||
using xTagService.Providers;
|
using xDataService.Configuration;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace xAiApi.Database
|
namespace xAiApi.Database
|
||||||
{
|
{
|
||||||
@@ -41,6 +41,7 @@ namespace xAiApi.Database
|
|||||||
nameof(XAiVectorEntityRegisterar),
|
nameof(XAiVectorEntityRegisterar),
|
||||||
nameof(XAiMessageEntityRegisterar),
|
nameof(XAiMessageEntityRegisterar),
|
||||||
nameof(XAiProjectEntityRegisterar),
|
nameof(XAiProjectEntityRegisterar),
|
||||||
|
nameof(XAiMcpServerEntityRegisterar),
|
||||||
nameof(XAiConversationEntityRegisterar),
|
nameof(XAiConversationEntityRegisterar),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -73,9 +73,7 @@ namespace xAiApi.Extensions
|
|||||||
var result =
|
var result =
|
||||||
!source.IsNullOrDefault() &&
|
!source.IsNullOrDefault() &&
|
||||||
!source.Prompt.IsNullOrEmpty() &&
|
!source.Prompt.IsNullOrEmpty() &&
|
||||||
!source.SessionId.IsDefaultGuid() &&
|
!source.SessionId.IsDefaultGuid();
|
||||||
source.TopK.HasValue && source.TopK.Value > 0 &&
|
|
||||||
source.MinScore.HasValue && source.MinScore.Value >= -1f && source.MinScore.Value <= 1f;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
@@ -327,5 +325,27 @@ namespace xAiApi.Extensions
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public static IList<AITool> ToAITools(this IList<XAiMcpToolDefinition> source)
|
||||||
|
// {
|
||||||
|
// //
|
||||||
|
// var result = new List<AITool>();
|
||||||
|
|
||||||
|
// //
|
||||||
|
// foreach (var tool in source)
|
||||||
|
// {
|
||||||
|
// //
|
||||||
|
// var declaration = AIFunctionFactory.CreateDeclaration(
|
||||||
|
// name: tool.Name,
|
||||||
|
// jsonSchema: tool.InputSchema,
|
||||||
|
// description: tool.Description
|
||||||
|
// );
|
||||||
|
|
||||||
|
// //
|
||||||
|
// result.Add(declaration);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// //
|
||||||
|
// return result;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,11 @@
|
|||||||
|
using System.Linq;
|
||||||
using xIdentityHelper;
|
using xIdentityHelper;
|
||||||
|
using xAiApi.Providers;
|
||||||
|
using xAiApi.Interfaces;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
using xCommons.Authorization;
|
using xCommons.Authorization;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using xIdentityService.Interfaces;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.HttpOverrides;
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
@@ -11,6 +15,17 @@ namespace xAiApi.Extensions
|
|||||||
{
|
{
|
||||||
public static class XProgramExtensions
|
public static class XProgramExtensions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Register MCP Server Provider ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
public static void AddXAiMcpServerProvider(
|
||||||
|
this IServiceCollection source
|
||||||
|
)
|
||||||
|
{
|
||||||
|
source.AddScoped<IXAiMcpServerProvider, XAiMcpServerProvider>();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Register Authorization Policies
|
/// Register Authorization Policies
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -22,6 +37,7 @@ namespace xAiApi.Extensions
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
var policyHandler = services.GetRegisteredService<IXPolicyHandler>();
|
||||||
services.AddAuthorization(options =>
|
services.AddAuthorization(options =>
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -35,6 +51,26 @@ namespace xAiApi.Extensions
|
|||||||
{
|
{
|
||||||
var policyDescriptor = policiesEnumerator.Current;
|
var policyDescriptor = policiesEnumerator.Current;
|
||||||
options.AddPolicy(policyDescriptor.Key, policyDescriptor.Value);
|
options.AddPolicy(policyDescriptor.Key, policyDescriptor.Value);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Add Policy to Policy Handler ...
|
||||||
|
if (!policyHandler.IsNull())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Check Policy is RequiredRole Policy ...
|
||||||
|
var roleRequirements = policyDescriptor.Value.Requirements
|
||||||
|
.OfType<RequiredRolesRequirement>()
|
||||||
|
.FirstOrDefault();
|
||||||
|
if (!roleRequirements.IsNull() &&
|
||||||
|
roleRequirements.Roles.HasChild())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
policyHandler.AddPolicy(
|
||||||
|
policy: policyDescriptor.Key.ToNormalString(),
|
||||||
|
requiredRoles: roleRequirements.Roles.Select(r => r.ToNormalString())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,8 +85,32 @@ namespace xAiApi.Extensions
|
|||||||
{
|
{
|
||||||
while (policiesEnumerator.MoveNext())
|
while (policiesEnumerator.MoveNext())
|
||||||
{
|
{
|
||||||
|
//
|
||||||
var policyDescriptor = policiesEnumerator.Current;
|
var policyDescriptor = policiesEnumerator.Current;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Add Policy to Authorization ...
|
||||||
options.AddPolicy(policyDescriptor.Key, policyDescriptor.Value);
|
options.AddPolicy(policyDescriptor.Key, policyDescriptor.Value);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Add Policy to Policy Handler ...
|
||||||
|
if (!policyHandler.IsNull())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Check Policy is RequiredRole Policy ...
|
||||||
|
var roleRequirements = policyDescriptor.Value.Requirements
|
||||||
|
.OfType<RequiredRolesRequirement>()
|
||||||
|
.FirstOrDefault();
|
||||||
|
if (!roleRequirements.IsNull() &&
|
||||||
|
roleRequirements.Roles.HasChild())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
policyHandler.AddPolicy(
|
||||||
|
policy: policyDescriptor.Key.ToNormalString(),
|
||||||
|
requiredRoles: roleRequirements.Roles.Select(r => r.ToNormalString())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace xAiApi.Interfaces
|
|
||||||
{
|
|
||||||
public interface IXAiEmbeddingServiceControllerBase
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Request For Embedding Specified String ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="content"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("Embedding")]
|
|
||||||
Task<ActionResult<float[]>> Embedding(
|
|
||||||
[FromQuery] string content,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Request For Embedding Specified Batch ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="batch"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("Embeddings")]
|
|
||||||
Task<ActionResult<IReadOnlyList<float[]>>> Embeddings(
|
|
||||||
[FromQuery] string[] batch,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,228 @@
|
|||||||
|
using System;
|
||||||
|
using xModels.Dtos;
|
||||||
|
using System.Threading;
|
||||||
|
using xAiModels.Models.Dtos;
|
||||||
|
using xIdentityModels.Models;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using ModelContextProtocol.Client;
|
||||||
|
using Microsoft.Extensions.AI;
|
||||||
|
|
||||||
|
namespace xAiApi.Interfaces
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// MCP Manager / Provider ...
|
||||||
|
/// </summary>
|
||||||
|
public interface IXAiMcpServerProvider
|
||||||
|
{
|
||||||
|
//
|
||||||
|
#region Manager ...
|
||||||
|
/// <summary>
|
||||||
|
/// Get a List Of Available Tools which Provided using registered Mcp Servers ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="forceOwner"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IList<AITool>> GetAvailableToolsAsync(
|
||||||
|
bool forceOwner = false,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test Specified Mcp Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="server"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<string> TestServerAsync(
|
||||||
|
XAiMcpServerDto server,
|
||||||
|
string connectionId = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Force Refresh Mcp Servers ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task RefreshAsync(
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Actions ...
|
||||||
|
/// <summary>
|
||||||
|
/// Add an Mcp Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XAiMcpServerDto> AddMcpServer(
|
||||||
|
XAiMcpServerDto item,
|
||||||
|
string connectionId = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get an Mcp Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XAiMcpServerDto> GetMcpServer(
|
||||||
|
Guid id,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update Specified Mcp Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XAiMcpServerDto> UpdateMcpServer(
|
||||||
|
Guid id,
|
||||||
|
XAiMcpServerDto item,
|
||||||
|
string connectionId = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove Specified Mcp Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XAiMcpServerDto> RemoveMcpServer(
|
||||||
|
Guid id,
|
||||||
|
string connectionId = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Disable Specified Mcp Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<bool> DisableMcpServer(
|
||||||
|
Guid id,
|
||||||
|
string connectionId = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enable Specified Mcp Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<bool> EnableMcpServer(
|
||||||
|
Guid id,
|
||||||
|
string connectionId = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Toggle Specified Mcp Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<bool> ToggleMcpServer(
|
||||||
|
Guid id,
|
||||||
|
string connectionId = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve all Mcp Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="forceOwner"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<XAiMcpServerDto>> GetAll(
|
||||||
|
bool forceOwner = false,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Find Specified Mcp Server ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="forceOwner"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XAiMcpServerDto> FindOne(
|
||||||
|
Expression<Func<XAiMcpServer, bool>> predicate,
|
||||||
|
bool forceOwner = false,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Find a Collection of Specified Mcp Servers ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <param name="forceOwner"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<XAiMcpServerDto>> FindMany(
|
||||||
|
Expression<Func<XAiMcpServer, bool>> predicate,
|
||||||
|
bool forceOwner = false,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Query Registered Mcp Servers ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="forceOwner"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XQueryResult<XAiMcpServerDto>> Query(
|
||||||
|
XQuery query,
|
||||||
|
bool forceOwner = false,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -67,12 +67,14 @@ namespace xAiApi.Interfaces
|
|||||||
/// <param name="fileName"></param>
|
/// <param name="fileName"></param>
|
||||||
/// <param name="scope">Target Scope (Null = User Scope)</param>
|
/// <param name="scope">Target Scope (Null = User Scope)</param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns>Count of Removed Vectors</returns>
|
/// <returns>Count of Removed Vectors</returns>
|
||||||
Task<int> RemoveDocumentAsync(
|
Task<int> RemoveDocumentAsync(
|
||||||
string fileName,
|
string fileName,
|
||||||
XAiKnowledgeScopeDescriptor scope = null,
|
XAiKnowledgeScopeDescriptor scope = null,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
namespace xAiApi.Interfaces
|
||||||
|
{
|
||||||
|
public interface IXAiService : IXAiServiceBase
|
||||||
|
{ }
|
||||||
|
}
|
||||||
+123
-81
@@ -32,10 +32,12 @@ namespace xAiApi.Interfaces
|
|||||||
/// Base Method for Communicate with LLM ...
|
/// Base Method for Communicate with LLM ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="prompt"></param>
|
/// <param name="prompt"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<string> AskTextAsync(
|
Task<string> AskTextAsync(
|
||||||
string prompt,
|
string prompt,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -43,61 +45,142 @@ namespace xAiApi.Interfaces
|
|||||||
/// Base Method for Communicate with LLM ...
|
/// Base Method for Communicate with LLM ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="prompt"></param>
|
/// <param name="prompt"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IAsyncEnumerable<string> AskTextAsEnumerable(
|
IAsyncEnumerable<string> AskTextAsEnumerable(
|
||||||
string prompt,
|
string prompt,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Prepare a Message History List for LLM Communication based on Prompt ...
|
/// Ask a Question By Providing Vector Search Result ...
|
||||||
/// </summary>
|
|
||||||
/// <param name="prompt"></param>
|
|
||||||
/// <param name="forcePrompt"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
IList<ChatMessage> GetHistory(
|
|
||||||
string prompt = null,
|
|
||||||
bool forcePrompt = true
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prepare a Message History List for LLM Communication based on Prompt ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message"></param>
|
|
||||||
/// <param name="forceMessage"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
IList<ChatMessage> GetHistory(
|
|
||||||
ChatMessage message = null,
|
|
||||||
bool forceMessage = true
|
|
||||||
);
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Context Actions ...
|
|
||||||
/// <summary>
|
|
||||||
/// Ask a Question using Provided Context Chunks (RAG) without Persisting ...
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="prompt"></param>
|
/// <param name="prompt"></param>
|
||||||
/// <param name="context"></param>
|
/// <param name="context"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<string> AskWithContextAsync(
|
Task<string> AskTextByContextAsync(
|
||||||
string prompt,
|
string prompt,
|
||||||
IEnumerable<XAiVectorSearchResult> context,
|
IList<XAiVectorSearchResult> context = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ask a Question using Provided Context Chunks (RAG) and Stream Response ...
|
/// Ask a Question By By Providing Vector Search Result and Stream Response ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="prompt"></param>
|
/// <param name="prompt"></param>
|
||||||
/// <param name="context"></param>
|
/// <param name="context"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IAsyncEnumerable<string> AskWithContextAsEnumerable(
|
IAsyncEnumerable<string> AskTextByContextAsEnumerable(
|
||||||
string prompt,
|
string prompt,
|
||||||
IEnumerable<XAiVectorSearchResult> context,
|
IList<XAiVectorSearchResult> context = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ask a Question By Rag Retrive From Knowledge ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="prompt"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
/// <param name="topK"></param>
|
||||||
|
/// <param name="minScore"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<string> AskTextFromKnowledgeAsync(
|
||||||
|
string prompt,
|
||||||
|
string type = null,
|
||||||
|
int? topK = null,
|
||||||
|
float? minScore = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ask a Question By Rag Retrive From Knowledge and Stream Response ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="prompt"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
/// <param name="topK"></param>
|
||||||
|
/// <param name="minScore"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
IAsyncEnumerable<string> AskTextFromKnowledgeAsEnumerable(
|
||||||
|
string prompt,
|
||||||
|
string type = null,
|
||||||
|
int? topK = null,
|
||||||
|
float? minScore = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ask a Question as Prompt and Retrieve Response ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="prompt"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
/// <param name="topK"></param>
|
||||||
|
/// <param name="minScore"></param>
|
||||||
|
/// <param name="projectId"></param>
|
||||||
|
/// <param name="conversationId"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="extractFileContents"></param>
|
||||||
|
/// <param name="addFilesToKnowledge"></param>
|
||||||
|
/// <param name="files"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XAiMessageDto> AskAsync(
|
||||||
|
string prompt,
|
||||||
|
string type = null,
|
||||||
|
int? topK = null,
|
||||||
|
float? minScore = null,
|
||||||
|
Guid? projectId = null,
|
||||||
|
Guid? conversationId = null,
|
||||||
|
string connectionId = null,
|
||||||
|
bool extractFileContents = false,
|
||||||
|
bool addFilesToKnowledge = true,
|
||||||
|
IFormFileCollection files = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ask a Question as Prompt and Retrieve Response as Async Enumerable ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="prompt"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
/// <param name="topK"></param>
|
||||||
|
/// <param name="minScore"></param>
|
||||||
|
/// <param name="projectId"></param>
|
||||||
|
/// <param name="conversationId"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <param name="extractFileContents"></param>
|
||||||
|
/// <param name="addFilesToKnowledge"></param>
|
||||||
|
/// <param name="files"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
IAsyncEnumerable<XAiResonseMessage> AskAsEnumerable(
|
||||||
|
string prompt,
|
||||||
|
string type = null,
|
||||||
|
int? topK = null,
|
||||||
|
float? minScore = null,
|
||||||
|
Guid? projectId = null,
|
||||||
|
Guid? conversationId = null,
|
||||||
|
string connectionId = null,
|
||||||
|
bool extractFileContents = false,
|
||||||
|
bool addFilesToKnowledge = true,
|
||||||
|
IFormFileCollection files = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
#endregion
|
#endregion
|
||||||
@@ -123,11 +206,13 @@ namespace xAiApi.Interfaces
|
|||||||
/// Load Conversations of Specified AI Project ...
|
/// Load Conversations of Specified AI Project ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="projectId"></param>
|
/// <param name="projectId"></param>
|
||||||
|
/// <param name="ownerId"></param>
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<XAiConversationDto>> LoadConversations(
|
Task<IEnumerable<XAiConversationDto>> LoadConversations(
|
||||||
Guid projectId,
|
Guid? projectId,
|
||||||
|
string ownerId = null,
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
@@ -136,10 +221,14 @@ namespace xAiApi.Interfaces
|
|||||||
/// Load Messages of Specified Conversation ...
|
/// Load Messages of Specified Conversation ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="conversationId"></param>
|
/// <param name="conversationId"></param>
|
||||||
|
/// <param name="ownerId"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<XAiMessageDto>> LoadMessages(
|
Task<IEnumerable<XAiMessageDto>> LoadMessages(
|
||||||
Guid conversationId,
|
Guid? conversationId,
|
||||||
|
string ownerId = null,
|
||||||
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
#endregion
|
#endregion
|
||||||
@@ -218,7 +307,7 @@ namespace xAiApi.Interfaces
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<XAiConversationDto> CreateConversation(
|
Task<XAiConversationDto> CreateConversation(
|
||||||
string ownerId,
|
string ownerId,
|
||||||
Guid projectId,
|
Guid? projectId,
|
||||||
XAiConversationDto item,
|
XAiConversationDto item,
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
@@ -240,52 +329,5 @@ namespace xAiApi.Interfaces
|
|||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//
|
|
||||||
#region Data Actions ...
|
|
||||||
/// <summary>
|
|
||||||
/// Ask a Question as Prompt and Retrieve Response ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="prompt"></param>
|
|
||||||
/// <param name="ownerId"></param>
|
|
||||||
/// <param name="projectId"></param>
|
|
||||||
/// <param name="conversationId"></param>
|
|
||||||
/// <param name="connectionId"></param>
|
|
||||||
/// <param name="files"></param>
|
|
||||||
/// <param name="userInfo"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<XAiMessageDto> AskAsync(
|
|
||||||
string prompt,
|
|
||||||
string ownerId,
|
|
||||||
Guid? projectId,
|
|
||||||
Guid? conversationId,
|
|
||||||
string connectionId = null,
|
|
||||||
IFormFileCollection files = null,
|
|
||||||
XUserClaimsInfoDto userInfo = null,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Ask a Question as Prompt and Retrieve Response as Async Enumerable ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="prompt"></param>
|
|
||||||
/// <param name="ownerId"></param>
|
|
||||||
/// <param name="projectId"></param>
|
|
||||||
/// <param name="conversationId"></param>
|
|
||||||
/// <param name="connectionId"></param>
|
|
||||||
/// <param name="files"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
IAsyncEnumerable<XAiResonseMessage> AskAsEnumerable(
|
|
||||||
string prompt,
|
|
||||||
string ownerId,
|
|
||||||
Guid projectId,
|
|
||||||
Guid conversationId,
|
|
||||||
string connectionId = null,
|
|
||||||
IFormFileCollection files = null,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,214 +0,0 @@
|
|||||||
using System;
|
|
||||||
using xModels.Dtos;
|
|
||||||
using System.Threading;
|
|
||||||
using xAiModels.Models;
|
|
||||||
using xAiModels.Models.Dtos;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace xAiApi.Interfaces
|
|
||||||
{
|
|
||||||
public interface IXAiServiceControllerBase
|
|
||||||
{
|
|
||||||
//
|
|
||||||
#region Actions ...
|
|
||||||
/// <summary>
|
|
||||||
/// Ask Question and Get Response ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="question"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("AskText")]
|
|
||||||
Task<ActionResult<string>> AskText(
|
|
||||||
[FromQuery] string question,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Ask Question and Get Response Stream ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="question"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("AskTextStream")]
|
|
||||||
Task AskTextStream(
|
|
||||||
[FromQuery] string question,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Loaders ...
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieve AI Projects ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="includeDefaults"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("Projects")]
|
|
||||||
Task<ActionResult<IEnumerable<XAiProjectDto>>> LoadProjects(
|
|
||||||
[FromQuery] bool includeDefaults = false,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieve Specified AI Project's Conversations ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="projectId"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("Projects/{projectId}/Conversations")]
|
|
||||||
Task<ActionResult<IEnumerable<XAiConversationDto>>> LoadConversations(
|
|
||||||
[FromRoute] Guid projectId,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieve Specified AI Conversation's Messages ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="conversationId"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("Conversations/{conversationId}/Messages")]
|
|
||||||
Task<ActionResult<IEnumerable<XAiMessageDto>>> LoadMessages(
|
|
||||||
[FromRoute] Guid conversationId,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Queries ...
|
|
||||||
/// <summary>
|
|
||||||
/// Query Projects ...
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// </remarks>
|
|
||||||
/// <param name="query"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("Projects/Query")]
|
|
||||||
Task<ActionResult<XQueryResult<XAiProjectDto>>> QueryProjects(
|
|
||||||
[FromQuery] XQuery query,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Query Conversations ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="projectId"></param>
|
|
||||||
/// <param name="query"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("Projects/{projectId}/Conversations/Query")]
|
|
||||||
Task<ActionResult<XQueryResult<XAiConversationDto>>> QueryConversations(
|
|
||||||
[FromRoute] Guid projectId,
|
|
||||||
[FromQuery] XQuery query,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Query Messages ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="conversationId"></param>
|
|
||||||
/// <param name="query"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("Conversations/{conversationId}/Messages/Query")]
|
|
||||||
Task<ActionResult<XQueryResult<XAiMessageDto>>> QueryMessages(
|
|
||||||
[FromRoute] Guid conversationId,
|
|
||||||
[FromQuery] XQuery query,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Creators ...
|
|
||||||
/// <summary>
|
|
||||||
/// Create an AI Project ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="item"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPost("Projects")]
|
|
||||||
Task<ActionResult<XAiProjectDto>> CreateProject(
|
|
||||||
[FromBody] XAiProjectDto item,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Create an AI Conversation ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="projectId"></param>
|
|
||||||
/// <param name="item"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPost("Projects/{projectId}/Conversations")]
|
|
||||||
Task<ActionResult<XAiConversationDto>> CreateConversation(
|
|
||||||
[FromRoute] Guid projectId,
|
|
||||||
[FromBody] XAiConversationDto item,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
#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")]
|
|
||||||
Task<ActionResult<string>> ExtractContent(
|
|
||||||
[FromForm] IFormFileCollection files,
|
|
||||||
[FromForm] string extractors = null,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Data Actions ...
|
|
||||||
/// <summary>
|
|
||||||
/// Ask Question and Get Response ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPost("Ask")]
|
|
||||||
Task<ActionResult<string>> Ask(
|
|
||||||
[FromBody] XAiResponseRequest request,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Ask Question and Get Response Stream ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPost("AskStream")]
|
|
||||||
Task AskStream(
|
|
||||||
[FromBody] XAiResponseRequest request,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <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")]
|
|
||||||
Task<ActionResult<string>> AskWithFiles(
|
|
||||||
[FromForm] XAiResponseRequest request,
|
|
||||||
[FromForm] IFormFileCollection files,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
namespace xAiApi.Interfaces
|
|
||||||
{
|
|
||||||
public interface IXDefaultAiService : IXAiServiceBase
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
@@ -106,7 +106,7 @@ namespace xAiApi.Middlewares
|
|||||||
var tokenModel = await context.RetrieveTokensAsXTokenResponse();
|
var tokenModel = await context.RetrieveTokensAsXTokenResponse();
|
||||||
var isAuthenticated =
|
var isAuthenticated =
|
||||||
//
|
//
|
||||||
(!apiKey.IsNullOrEmpty()) |
|
(!apiKey.IsNullOrEmpty()) ||
|
||||||
//
|
//
|
||||||
(!tokenModel.IsNull() && !tokenModel.AccessToken.IsNullOrEmpty())
|
(!tokenModel.IsNull() && !tokenModel.AccessToken.IsNullOrEmpty())
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
namespace xAiApi.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Describe an Mcp Server for Seeding ...
|
||||||
|
/// </summary>
|
||||||
|
public class XAiMcpServerDescriptor
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string OwnerId { get; set; }
|
||||||
|
public string Headers { get; set; }
|
||||||
|
public string Endpoint { get; set; }
|
||||||
|
public string Description { get; set; }
|
||||||
|
public bool Enabled { get; set; } = true;
|
||||||
|
public int TimeoutSeconds { get; set; } = 30;
|
||||||
|
public string EnvironmentVariables { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
namespace xAiApi.Models
|
||||||
|
{
|
||||||
|
public class XDateTimeDescriptor
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Adding Current DateTime to Prompt ...
|
||||||
|
/// </summary>
|
||||||
|
public bool InjectIntoSystemPrompt { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Time Zone ...
|
||||||
|
/// </summary>
|
||||||
|
public string DefaultTimezone { get; set; } = "Asia/Tehran";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Georgian Date Format ...
|
||||||
|
/// </summary>
|
||||||
|
public string GregorianFormat { get; set; } = "yyyy-MM-dd HH:mm:ss";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Include Persian Calendar ...
|
||||||
|
/// </summary>
|
||||||
|
public bool IncludePersianCalendar { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Include Day of Week ...
|
||||||
|
/// </summary>
|
||||||
|
public bool IncludeDayOfWeek { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Include Unix Timestamp ...
|
||||||
|
/// </summary>
|
||||||
|
public bool IncludeUnixTimestamp { get; set; } = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
using xAiModels.Models.Dtos;
|
||||||
|
using Microsoft.Extensions.AI;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace xAiApi.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// a Shared Context Between Actions for Generation ...
|
||||||
|
/// </summary>
|
||||||
|
public class XPreparedChatContext
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Specified Related Project, if Exists ...
|
||||||
|
/// </summary>
|
||||||
|
public XAiProjectDto Project { get; set; } = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specified Related Conversation, if Exists ...
|
||||||
|
/// </summary>
|
||||||
|
public XAiConversationDto Conversation { get; set; } = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specified Message History, if Exists ...
|
||||||
|
/// </summary>
|
||||||
|
public IList<ChatMessage> History { get; set; } = [];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specified Vector Search Conext, if Exists ...
|
||||||
|
/// </summary>
|
||||||
|
public IList<XAiVectorSearchResult> Context { get; set; } = [];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specified Persisted Prompt, if Exists ...
|
||||||
|
/// </summary>
|
||||||
|
public XAiMessageDto PersistedPromptMessage { get; set; } = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-1
@@ -1,4 +1,5 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
|
using xLoggingService.DI;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
@@ -19,10 +20,13 @@ namespace xAiApi
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
var result = Host.CreateDefaultBuilder(args)
|
var result = Host.CreateDefaultBuilder(args)
|
||||||
|
.ConfigureLogging(logging =>
|
||||||
|
logging.AddXTelemetryLogger())
|
||||||
.ConfigureWebHostDefaults(webBuilder =>
|
.ConfigureWebHostDefaults(webBuilder =>
|
||||||
{
|
{
|
||||||
webBuilder.UseStartup<Startup>();
|
webBuilder.UseStartup<Startup>();
|
||||||
});
|
})
|
||||||
|
.AddXTelemetry();
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"launchUrl": "weatherforecast",
|
"launchUrl": "weatherforecast",
|
||||||
"applicationUrl": "https://localhost:6001;http://localhost:6000",
|
"applicationUrl": "https://localhost:6001;http://localhost:6000;https://0.0.0.0:6001;",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
}
|
||||||
|
|||||||
+1053
-571
File diff suppressed because it is too large
Load Diff
@@ -84,7 +84,7 @@ namespace xAiApi.Providers
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
using var generator = GetEmbeddingGenerator();
|
var generator = GetEmbeddingGenerator();
|
||||||
|
|
||||||
//
|
//
|
||||||
GeneratedEmbeddings<Embedding<float>> response = null;
|
GeneratedEmbeddings<Embedding<float>> response = null;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
+192
-129
@@ -18,6 +18,7 @@ using Microsoft.AspNetCore.Http;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using xAiApi.Interfaces.Extractors;
|
using xAiApi.Interfaces.Extractors;
|
||||||
|
using xFileService.Models.Dtos;
|
||||||
|
|
||||||
namespace xAiApi.Providers
|
namespace xAiApi.Providers
|
||||||
{
|
{
|
||||||
@@ -127,149 +128,181 @@ namespace xAiApi.Providers
|
|||||||
var existingDocuments = await LoadDocumentNames(scopePrefix, cancellationToken);
|
var existingDocuments = await LoadDocumentNames(scopePrefix, cancellationToken);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
// Loop through Files ...
|
||||||
foreach (var file in files)
|
foreach (var file in files)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
XFileDto uploadedFile = null;
|
||||||
|
|
||||||
//
|
//
|
||||||
if (file.IsNull() || file.Length == 0)
|
try
|
||||||
{
|
|
||||||
result.SkippedFiles.Add(file?.FileName ?? "(null)");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Size Limit ...
|
|
||||||
if (rag.MaxFileSizeBytes > 0 && file.Length > rag.MaxFileSizeBytes)
|
|
||||||
{
|
|
||||||
result.SkippedFiles.Add(file.FileName);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
var fileName = NormalizeFileName(file.FileName);
|
|
||||||
if (fileName.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
result.SkippedFiles.Add(file.FileName);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Documents per Scope Limit (Global Unlimited; Re-Ingest of Existing Doc Allowed) ...
|
|
||||||
var isNewDocument = !existingDocuments.Contains(fileName);
|
|
||||||
if (
|
|
||||||
isNewDocument &&
|
|
||||||
scope.Scope != XAiKnowledgeScope.Global &&
|
|
||||||
rag.MaxDocumentsPerScope > 0 &&
|
|
||||||
existingDocuments.Count >= rag.MaxDocumentsPerScope
|
|
||||||
)
|
|
||||||
{
|
|
||||||
result.SkippedFiles.Add(file.FileName);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
var mimeType = file.ContentType?.ToLowerInvariant() ?? string.Empty;
|
|
||||||
if (!fileContentExtractor.CanExtract(mimeType))
|
|
||||||
{
|
|
||||||
result.SkippedFiles.Add(file.FileName);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
var text = await ExtractText(file, mimeType, cancellationToken);
|
|
||||||
if (text.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
result.SkippedFiles.Add(file.FileName);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Chunk with Scoped Source => Identifier = "{scopePrefix}{fileName}#{index}" ...
|
|
||||||
var chunks = textChunker.Chunk(text, $"{scopePrefix}{fileName}");
|
|
||||||
if (!chunks.HasChild())
|
|
||||||
{
|
|
||||||
result.SkippedFiles.Add(file.FileName);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Handle File Save ...
|
|
||||||
var uploadedFile = await fileProvider.Upload(
|
|
||||||
file: file,
|
|
||||||
userInfo: userInfo,
|
|
||||||
connectionId: connectionId,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Add Reference File to Prompt Message ...
|
|
||||||
if (scope.ScopeId.HasValue)
|
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
await fileProvider.AddReference(
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
|
//
|
||||||
|
if (file.IsNull() || file.Length == 0)
|
||||||
|
{
|
||||||
|
result.SkippedFiles.Add(file?.FileName ?? "(null)");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Size Limit ...
|
||||||
|
if (rag.MaxFileSizeBytes > 0 && file.Length > rag.MaxFileSizeBytes)
|
||||||
|
{
|
||||||
|
result.SkippedFiles.Add(file.FileName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var fileName = NormalizeFileName(file.FileName);
|
||||||
|
if (fileName.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
result.SkippedFiles.Add(file.FileName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Documents per Scope Limit (Global Unlimited; Re-Ingest of Existing Doc Allowed) ...
|
||||||
|
var isNewDocument = !existingDocuments.Contains(fileName);
|
||||||
|
if (
|
||||||
|
isNewDocument &&
|
||||||
|
scope.Scope != XAiKnowledgeScope.Global &&
|
||||||
|
rag.MaxDocumentsPerScope > 0 &&
|
||||||
|
existingDocuments.Count >= rag.MaxDocumentsPerScope
|
||||||
|
)
|
||||||
|
{
|
||||||
|
result.SkippedFiles.Add(file.FileName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var mimeType = file.ContentType?.ToLowerInvariant() ?? string.Empty;
|
||||||
|
if (!fileContentExtractor.CanExtract(mimeType))
|
||||||
|
{
|
||||||
|
result.SkippedFiles.Add(file.FileName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var text = await ExtractText(file, mimeType, cancellationToken);
|
||||||
|
if (text.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
result.SkippedFiles.Add(file.FileName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Chunk with Scoped Source => Identifier = "{scopePrefix}{fileName}#{index}" ...
|
||||||
|
var chunks = textChunker.Chunk(text, $"{scopePrefix}{fileName}");
|
||||||
|
if (!chunks.HasChild())
|
||||||
|
{
|
||||||
|
result.SkippedFiles.Add(file.FileName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle File Save ...
|
||||||
|
uploadedFile = await fileProvider.Upload(
|
||||||
|
file: file,
|
||||||
userInfo: userInfo,
|
userInfo: userInfo,
|
||||||
id: uploadedFile.Id,
|
|
||||||
connectionId: connectionId,
|
connectionId: connectionId,
|
||||||
cancellationToken: cancellationToken,
|
cancellationToken: cancellationToken
|
||||||
providedFor: scope.Scope.GetStringValue(),
|
);
|
||||||
forProvidedId: scope.ScopeId.Value.ToString()
|
|
||||||
|
//
|
||||||
|
// Add Reference File to Prompt Message ...
|
||||||
|
if (
|
||||||
|
!uploadedFile.IsNullOrDefault() &&
|
||||||
|
scope.ScopeId.HasValue &&
|
||||||
|
!uploadedFile.Id.IsDefaultGuid()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
await fileProvider.AddReference(
|
||||||
|
userInfo: userInfo,
|
||||||
|
id: uploadedFile.Id,
|
||||||
|
connectionId: connectionId,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
providedFor: scope.Scope.GetStringValue(),
|
||||||
|
forProvidedId: scope.ScopeId.Value.ToString()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Embed in Batches ...
|
||||||
|
var vectors = await EmbedChunks(
|
||||||
|
scope: scope,
|
||||||
|
chunks: chunks,
|
||||||
|
fileName: fileName,
|
||||||
|
mimeType: mimeType,
|
||||||
|
type: knowledgeType,
|
||||||
|
ownerId: userInfo.UserId,
|
||||||
|
ingestedAtUtc: ingestedAtUtc,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Remove Stale Vectors of Same Document ...
|
||||||
|
if (replaceExisting)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result.ReplacedCount += await dataProvider.RemoveVectorsAsync(
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
identifierPrefix: GetDocumentChunkPrefix(scopePrefix, fileName)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Store ...
|
||||||
|
var storedCount = await dataProvider.UpsertVectorsAsync(
|
||||||
|
items: vectors,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
existingDocuments.Add(fileName);
|
||||||
|
result.FilesCount++;
|
||||||
|
result.ChunksCount += storedCount;
|
||||||
|
result.Documents.Add(new XAiKnowledgeDocumentInfo
|
||||||
|
{
|
||||||
|
FileName = fileName,
|
||||||
|
MimeType = mimeType,
|
||||||
|
Type = knowledgeType,
|
||||||
|
Scope = scope.Scope,
|
||||||
|
ScopeId = scope.ScopeId,
|
||||||
|
ChunksCount = storedCount,
|
||||||
|
OwnerId = userInfo.UserId,
|
||||||
|
IngestedAtUtc = ingestedAt,
|
||||||
|
});
|
||||||
|
|
||||||
|
//
|
||||||
|
logger.LogInformation(
|
||||||
|
"Knowledge: Ingested {FileName} into {Scope}:{ScopeId} by {OwnerId} with {Chunks} Chunks",
|
||||||
|
fileName, scope.Scope, scope.ScopeId, userInfo.UserId, storedCount
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
//
|
|
||||||
// Embed in Batches ...
|
|
||||||
var vectors = await EmbedChunks(
|
|
||||||
scope: scope,
|
|
||||||
chunks: chunks,
|
|
||||||
fileName: fileName,
|
|
||||||
mimeType: mimeType,
|
|
||||||
type: knowledgeType,
|
|
||||||
ownerId: userInfo.UserId,
|
|
||||||
ingestedAtUtc: ingestedAtUtc,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Remove Stale Vectors of Same Document ...
|
|
||||||
if (replaceExisting)
|
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
result.ReplacedCount += await dataProvider.RemoveVectorsAsync(
|
logger.LogError(ex, "Ingesting Failed ...");
|
||||||
cancellationToken: cancellationToken,
|
|
||||||
identifierPrefix: GetDocumentChunkPrefix(scopePrefix, fileName)
|
//
|
||||||
);
|
// Removing Uploaded File if Chuncking Failed ...
|
||||||
|
if (!uploadedFile.IsNullOrDefault() &&
|
||||||
|
!uploadedFile.Id.IsDefaultGuid()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
await fileProvider.Remove(
|
||||||
|
id: uploadedFile.Id,
|
||||||
|
userInfo: userInfo,
|
||||||
|
connectionId: connectionId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// Store ...
|
|
||||||
var storedCount = await dataProvider.UpsertVectorsAsync(
|
|
||||||
items: vectors,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
existingDocuments.Add(fileName);
|
|
||||||
result.FilesCount++;
|
|
||||||
result.ChunksCount += storedCount;
|
|
||||||
result.Documents.Add(new XAiKnowledgeDocumentInfo
|
|
||||||
{
|
|
||||||
FileName = fileName,
|
|
||||||
MimeType = mimeType,
|
|
||||||
Type = knowledgeType,
|
|
||||||
Scope = scope.Scope,
|
|
||||||
ScopeId = scope.ScopeId,
|
|
||||||
ChunksCount = storedCount,
|
|
||||||
OwnerId = userInfo.UserId,
|
|
||||||
IngestedAtUtc = ingestedAt,
|
|
||||||
});
|
|
||||||
|
|
||||||
//
|
|
||||||
logger.LogInformation(
|
|
||||||
"Knowledge: Ingested {FileName} into {Scope}:{ScopeId} by {OwnerId} with {Chunks} Chunks",
|
|
||||||
fileName, scope.Scope, scope.ScopeId, userInfo.UserId, storedCount
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -447,12 +480,14 @@ namespace xAiApi.Providers
|
|||||||
/// <param name="fileName"></param>
|
/// <param name="fileName"></param>
|
||||||
/// <param name="scope"></param>
|
/// <param name="scope"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns>Count of Removed Vectors</returns>
|
/// <returns>Count of Removed Vectors</returns>
|
||||||
public async Task<int> RemoveDocumentAsync(
|
public async Task<int> RemoveDocumentAsync(
|
||||||
string fileName,
|
string fileName,
|
||||||
XAiKnowledgeScopeDescriptor scope = null,
|
XAiKnowledgeScopeDescriptor scope = null,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -474,6 +509,34 @@ namespace xAiApi.Providers
|
|||||||
cancellationToken: cancellationToken,
|
cancellationToken: cancellationToken,
|
||||||
identifierPrefix: GetDocumentChunkPrefix(GetScopePrefix(scope, userInfo), normalizedFileName)
|
identifierPrefix: GetDocumentChunkPrefix(GetScopePrefix(scope, userInfo), normalizedFileName)
|
||||||
);
|
);
|
||||||
|
if (result > 0)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Remove Files using ...
|
||||||
|
var file = await fileProvider.FindOne(
|
||||||
|
x => x.FileName
|
||||||
|
.Equals(
|
||||||
|
fileName,
|
||||||
|
StringComparison.InvariantCultureIgnoreCase) &&
|
||||||
|
x.OwnerId
|
||||||
|
.Equals(
|
||||||
|
userInfo.UserId,
|
||||||
|
StringComparison.InvariantCultureIgnoreCase),
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!file.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
await fileProvider.Remove(
|
||||||
|
id: file.Id,
|
||||||
|
userInfo: userInfo,
|
||||||
|
connectionId: connectionId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -8,14 +8,15 @@ using xAiApi.Interfaces.Extractors;
|
|||||||
|
|
||||||
namespace xAiApi.Providers
|
namespace xAiApi.Providers
|
||||||
{
|
{
|
||||||
public class XDefaultAiService : XAIServiceBase, IXDefaultAiService
|
public class XAiService : XAIServiceBase, IXAiService
|
||||||
{
|
{
|
||||||
public XDefaultAiService(
|
public XAiService(
|
||||||
IXAiRAGService ragProvider,
|
IXAiRAGService ragProvider,
|
||||||
IXAiDataProvider dataProvider,
|
IXAiDataProvider dataProvider,
|
||||||
ILogger<XDefaultAiService> logger,
|
ILogger<XAiService> logger,
|
||||||
XAiApiConfiguration configuration,
|
XAiApiConfiguration configuration,
|
||||||
XValidationProvider validationProvider,
|
XValidationProvider validationProvider,
|
||||||
|
IXAiMcpServerProvider mcpServerProvider,
|
||||||
IXFileContentExtractor fileContentExtractor
|
IXFileContentExtractor fileContentExtractor
|
||||||
) : base(
|
) : base(
|
||||||
ragProvider,
|
ragProvider,
|
||||||
@@ -23,6 +24,7 @@ namespace xAiApi.Providers
|
|||||||
logger,
|
logger,
|
||||||
configuration,
|
configuration,
|
||||||
validationProvider,
|
validationProvider,
|
||||||
|
mcpServerProvider,
|
||||||
fileContentExtractor,
|
fileContentExtractor,
|
||||||
XAiApiConstants.XAiDefaultModelName
|
XAiApiConstants.XAiDefaultModelName
|
||||||
)
|
)
|
||||||
@@ -17,6 +17,7 @@ namespace xAiApi.Providers
|
|||||||
ILogger<XAIServiceBase> logger,
|
ILogger<XAIServiceBase> logger,
|
||||||
XAiApiConfiguration configuration,
|
XAiApiConfiguration configuration,
|
||||||
XValidationProvider validationProvider,
|
XValidationProvider validationProvider,
|
||||||
|
IXAiMcpServerProvider mcpServerProvider,
|
||||||
IXFileContentExtractor fileContentExtractor,
|
IXFileContentExtractor fileContentExtractor,
|
||||||
ReasoningEffort effort = ReasoningEffort.Medium,
|
ReasoningEffort effort = ReasoningEffort.Medium,
|
||||||
ReasoningOutput output = ReasoningOutput.Full
|
ReasoningOutput output = ReasoningOutput.Full
|
||||||
@@ -26,6 +27,7 @@ namespace xAiApi.Providers
|
|||||||
logger,
|
logger,
|
||||||
configuration,
|
configuration,
|
||||||
validationProvider,
|
validationProvider,
|
||||||
|
mcpServerProvider,
|
||||||
fileContentExtractor,
|
fileContentExtractor,
|
||||||
XAiApiConstants.XAiDefaultThinkingModelName
|
XAiApiConstants.XAiDefaultThinkingModelName
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -174,11 +174,37 @@ namespace xAiApi.Providers
|
|||||||
//
|
//
|
||||||
session = null;
|
session = null;
|
||||||
XAiDocumentSession found;
|
XAiDocumentSession found;
|
||||||
if (!sessions.TryGetValue(sessionId, out found) || !OwnerMatches(found, ownerId)) return false;
|
if (!sessions.TryGetValue(sessionId, out found))
|
||||||
if (found.IsExpired(DateTime.UtcNow)) { sessions.TryRemove(sessionId, out found); return false; }
|
{
|
||||||
found.LastAccessAtUtc = DateTime.UtcNow;
|
return false;
|
||||||
session = found;
|
}
|
||||||
return true;
|
|
||||||
|
//
|
||||||
|
lock (found.SyncRoot)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XAiDocumentSession current;
|
||||||
|
if (!sessions.TryGetValue(sessionId, out current) ||
|
||||||
|
!ReferenceEquals(current, found))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!OwnerMatches(found, ownerId))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (found.IsExpired(DateTime.UtcNow))
|
||||||
|
{
|
||||||
|
//
|
||||||
|
sessions.TryRemove(sessionId, out found);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
found.LastAccessAtUtc = DateTime.UtcNow;
|
||||||
|
session = found;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Remove(
|
public bool Remove(
|
||||||
|
|||||||
+32
-1
@@ -3,6 +3,7 @@ using System.IO;
|
|||||||
using xAiApi.DI;
|
using xAiApi.DI;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using xAiModels.DI;
|
using xAiModels.DI;
|
||||||
|
using xAiService.DI;
|
||||||
using xTagService.DI;
|
using xTagService.DI;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using xAiApi.Database;
|
using xAiApi.Database;
|
||||||
@@ -14,6 +15,7 @@ using Newtonsoft.Json;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using xAiApi.Extensions;
|
using xAiApi.Extensions;
|
||||||
using xStringService.DI;
|
using xStringService.DI;
|
||||||
|
using xLoggingService.DI;
|
||||||
using xStorageService.DI;
|
using xStorageService.DI;
|
||||||
using xIdentityService.DI;
|
using xIdentityService.DI;
|
||||||
using xDataService.Models;
|
using xDataService.Models;
|
||||||
@@ -69,6 +71,10 @@ namespace xAiApi
|
|||||||
services.AddXAppConfiguration(Configuration);
|
services.AddXAppConfiguration(Configuration);
|
||||||
var appConfiguration = services.GetRegisteredService<XAppConfiguration>();
|
var appConfiguration = services.GetRegisteredService<XAppConfiguration>();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register Logging Service ...
|
||||||
|
services.AddXLoggingService(Configuration);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Register Allowed Origins ...
|
// Register Allowed Origins ...
|
||||||
services.AddXCors(appConfiguration.AllowedOrigins);
|
services.AddXCors(appConfiguration.AllowedOrigins);
|
||||||
@@ -184,6 +190,10 @@ namespace xAiApi
|
|||||||
// Register XAiApi Configuration ...
|
// Register XAiApi Configuration ...
|
||||||
services.AddXAiApiConfiguration(Configuration);
|
services.AddXAiApiConfiguration(Configuration);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register MCP Server Provider ...
|
||||||
|
services.AddXAiMcpServerProvider();
|
||||||
|
|
||||||
//
|
//
|
||||||
// Register File Content Extractor Services ...
|
// Register File Content Extractor Services ...
|
||||||
services.AddXAiFileContentExtractors();
|
services.AddXAiFileContentExtractors();
|
||||||
@@ -196,6 +206,10 @@ namespace xAiApi
|
|||||||
// Register Chat With Documents Services (Text Chunker + In-Memory Vector Store) ...
|
// Register Chat With Documents Services (Text Chunker + In-Memory Vector Store) ...
|
||||||
services.AddXAiChatWithDocuments();
|
services.AddXAiChatWithDocuments();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register XAiMcpClient ...
|
||||||
|
services.AddXAiMcpClient();
|
||||||
|
|
||||||
//
|
//
|
||||||
// Persistent RAG (Knowledge over XAiVector Table) ...
|
// Persistent RAG (Knowledge over XAiVector Table) ...
|
||||||
services.AddXRagService();
|
services.AddXRagService();
|
||||||
@@ -205,7 +219,10 @@ namespace xAiApi
|
|||||||
services.AddXAiServices();
|
services.AddXAiServices();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
public void Configure(
|
||||||
|
IApplicationBuilder app,
|
||||||
|
IWebHostEnvironment env
|
||||||
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
@@ -222,6 +239,10 @@ namespace xAiApi
|
|||||||
app.UseHsts();
|
app.UseHsts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Setting Environment in App Confiuration ...
|
||||||
|
app.AddEnvironmentToXAppConfiguration(env.EnvironmentName);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Force Https Redirection ...
|
// Force Https Redirection ...
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
@@ -250,6 +271,13 @@ namespace xAiApi
|
|||||||
// Using Routing ...
|
// Using Routing ...
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Using Request Logging ...
|
||||||
|
if (!isDevelopmentEnvironment)
|
||||||
|
{
|
||||||
|
app.UseXRequestLogger();
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Use xIdentityService (Authentication) ...
|
// Use xIdentityService (Authentication) ...
|
||||||
app.UseXIdentityService();
|
app.UseXIdentityService();
|
||||||
@@ -306,3 +334,6 @@ namespace xAiApi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
{
|
{
|
||||||
"AllowedOrigins": [
|
"AllowedOrigins": [
|
||||||
|
"http://127.0.0.1:5500",
|
||||||
"http://localhost:5000",
|
"http://localhost:5000",
|
||||||
"https://localhost:5001",
|
"https://localhost:5001",
|
||||||
"http://api.saherelm.ir",
|
"http://api.saherelm.ir",
|
||||||
"https://api.saherelm.ir",
|
"https://api.saherelm.ir",
|
||||||
"http://api.saherelmhub.ir",
|
"http://api.saherelmhub.ir",
|
||||||
|
"http://192.168.11.29:5173",
|
||||||
|
"http://192.168.11.29:5174",
|
||||||
"https://api.saherelmhub.ir"
|
"https://api.saherelmhub.ir"
|
||||||
],
|
],
|
||||||
"IdentityServiceConfiguration": {
|
"IdentityServiceConfiguration": {
|
||||||
@@ -37,9 +40,16 @@
|
|||||||
},
|
},
|
||||||
"AiApiConfiguration": {
|
"AiApiConfiguration": {
|
||||||
"Models": [
|
"Models": [
|
||||||
|
{
|
||||||
|
"Name": "Arion",
|
||||||
|
"Provider": "OpenAI",
|
||||||
|
"LLM": "claude-fable-5-1",
|
||||||
|
"Url": "https://arionhub.pro/v1",
|
||||||
|
"ApiKey": "sk-AKJGD8J9gOCrQgc5oWPGtRGUo25PnnQGnMoipzdliYHa3otZ"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"ApiKey": "",
|
"ApiKey": "",
|
||||||
"Name": "Gemma",
|
"Name": "Gemma_BKP",
|
||||||
"LLM": "gemma3:1b",
|
"LLM": "gemma3:1b",
|
||||||
"Provider": "OpenAI",
|
"Provider": "OpenAI",
|
||||||
"Url": "http://178.131.88.93:1112/v1"
|
"Url": "http://178.131.88.93:1112/v1"
|
||||||
@@ -130,6 +140,14 @@
|
|||||||
"MetadataMimeType": "mimeType",
|
"MetadataMimeType": "mimeType",
|
||||||
"PromptName": "ChatWithDocuments",
|
"PromptName": "ChatWithDocuments",
|
||||||
"MetadataChunkIndex": "chunkIndex"
|
"MetadataChunkIndex": "chunkIndex"
|
||||||
|
},
|
||||||
|
"DateTime": {
|
||||||
|
"IncludeDayOfWeek": true,
|
||||||
|
"IncludeUnixTimestamp": false,
|
||||||
|
"InjectIntoSystemPrompt": true,
|
||||||
|
"IncludePersianCalendar": true,
|
||||||
|
"DefaultTimezone": "Asia/Tehran",
|
||||||
|
"GregorianFormat": "yyyy-MM-dd HH:mm:ss"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
"DefaultLanguage": "fa-IR",
|
"DefaultLanguage": "fa-IR",
|
||||||
"XPoweredValue": "SaherElmITCenter",
|
"XPoweredValue": "SaherElmITCenter",
|
||||||
"WelcomeMessage": "Welcome to xSaherElm Project's AI API",
|
"WelcomeMessage": "Welcome to xSaherElm Project's AI API",
|
||||||
|
"DefaultCacheTtlMinutes": 10,
|
||||||
"AllowedOrigins": [
|
"AllowedOrigins": [
|
||||||
"http://api.saherelm.ir",
|
"http://api.saherelm.ir",
|
||||||
"https://api.saherelm.ir",
|
"https://api.saherelm.ir",
|
||||||
@@ -18,6 +19,9 @@
|
|||||||
"Name": "Hadi Khazaee Asl",
|
"Name": "Hadi Khazaee Asl",
|
||||||
"Email": "hadi_khazaee_asl@yahoo.com",
|
"Email": "hadi_khazaee_asl@yahoo.com",
|
||||||
"Url": "https://www.saherelm.ir"
|
"Url": "https://www.saherelm.ir"
|
||||||
|
},
|
||||||
|
"DefaultValues": {
|
||||||
|
"version": "1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"HttpServiceConfiguration": {
|
"HttpServiceConfiguration": {
|
||||||
@@ -48,6 +52,38 @@
|
|||||||
"BaseRoute": "hubs",
|
"BaseRoute": "hubs",
|
||||||
"AddSupportMessageProtocol": true
|
"AddSupportMessageProtocol": true
|
||||||
},
|
},
|
||||||
|
"LoggingServiceConfiguration": {
|
||||||
|
"Enabled": true,
|
||||||
|
"MinimumLevel": "Information",
|
||||||
|
"Queue": {
|
||||||
|
"Enabled": true,
|
||||||
|
"Capacity": 10000,
|
||||||
|
"ShutdownTimeoutSeconds": 10
|
||||||
|
},
|
||||||
|
"File": {
|
||||||
|
"Enabled": true,
|
||||||
|
"Directory": "./Logs",
|
||||||
|
"FileName": "xAiApi-.log",
|
||||||
|
"Format": "Json",
|
||||||
|
"MinimumLevel": "Information",
|
||||||
|
"RetainedFileCountLimit": 30
|
||||||
|
},
|
||||||
|
"Database": {
|
||||||
|
"Enabled": false,
|
||||||
|
"TableName": "XLogs",
|
||||||
|
"AutoCreateTable": true,
|
||||||
|
"MinimumLevel": "Warning",
|
||||||
|
"Provider": "Microsoft.Data.Sqlite",
|
||||||
|
"ConnectionString": "Filename=./Db/XLogs.db"
|
||||||
|
},
|
||||||
|
"Event": {
|
||||||
|
"Enabled": false,
|
||||||
|
"Sender": "xAiApi",
|
||||||
|
"MinimumLevel": "Error",
|
||||||
|
"Topic": "application-logs",
|
||||||
|
"Action": "ApplicationLogCreated"
|
||||||
|
}
|
||||||
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
|
|||||||
+3
-2
@@ -7,7 +7,6 @@
|
|||||||
<Authors>Hadi Khazaee Asl</Authors>
|
<Authors>Hadi Khazaee Asl</Authors>
|
||||||
<Company>SaherElm IT Center</Company>
|
<Company>SaherElm IT Center</Company>
|
||||||
<PackageId>xSaherElm.xAiApi</PackageId>
|
<PackageId>xSaherElm.xAiApi</PackageId>
|
||||||
<!-- <TargetFramework>net8.0</TargetFramework> -->
|
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
|
||||||
<Description>
|
<Description>
|
||||||
@@ -18,8 +17,8 @@
|
|||||||
<PackageIcon>icon.png</PackageIcon>
|
<PackageIcon>icon.png</PackageIcon>
|
||||||
|
|
||||||
<!-- Fix Duplicate TargetFramework Issue -->
|
<!-- Fix Duplicate TargetFramework Issue -->
|
||||||
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<!-- Icon Handling -->
|
<!-- Icon Handling -->
|
||||||
@@ -41,6 +40,7 @@
|
|||||||
<ProjectReference Include="../Modules/xHttpService/xHttpService.csproj" />
|
<ProjectReference Include="../Modules/xHttpService/xHttpService.csproj" />
|
||||||
<ProjectReference Include="../Modules/xFileService/xFileService.csproj" />
|
<ProjectReference Include="../Modules/xFileService/xFileService.csproj" />
|
||||||
<ProjectReference Include="../Modules/xStorageService/xStorageService.csproj" />
|
<ProjectReference Include="../Modules/xStorageService/xStorageService.csproj" />
|
||||||
|
<ProjectReference Include="..\Modules\xLoggingService\xLoggingService.csproj" />
|
||||||
<ProjectReference Include="../Modules/xIdentityHelper/xIdentityHelper.csproj" />
|
<ProjectReference Include="../Modules/xIdentityHelper/xIdentityHelper.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
@@ -57,6 +57,7 @@
|
|||||||
<PackageReference Include="RtfPipe" Version="2.0.7677.4303" />
|
<PackageReference Include="RtfPipe" Version="2.0.7677.4303" />
|
||||||
<PackageReference Include="HtmlAgilityPack" Version="1.13.0" />
|
<PackageReference Include="HtmlAgilityPack" Version="1.13.0" />
|
||||||
<PackageReference Include="Whisper.net.Runtime" Version="1.9.1" />
|
<PackageReference Include="Whisper.net.Runtime" Version="1.9.1" />
|
||||||
|
<PackageReference Include="ModelContextProtocol" Version="2.3.1" />
|
||||||
<PackageReference Include="OfficeIMO.PowerPoint" Version="3.5.1" />
|
<PackageReference Include="OfficeIMO.PowerPoint" Version="3.5.1" />
|
||||||
<PackageReference Include="OfficeIMO.OpenDocument" Version="3.5.1" />
|
<PackageReference Include="OfficeIMO.OpenDocument" Version="3.5.1" />
|
||||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.5.1" />
|
<PackageReference Include="DocumentFormat.OpenXml" Version="3.5.1" />
|
||||||
|
|||||||
Reference in New Issue
Block a user