Compare commits
1
Commits
efaf71d962
...
aac3eb92c1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aac3eb92c1 |
@@ -652,6 +652,56 @@ namespace xAiApi.Controllers
|
|||||||
await Response.Body.FlushAsync();
|
await Response.Body.FlushAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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")]
|
||||||
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ using System.Threading;
|
|||||||
using xAiModels.Models;
|
using xAiModels.Models;
|
||||||
using xAiModels.Models.Dtos;
|
using xAiModels.Models.Dtos;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using xIdentityModels.Models;
|
||||||
using Microsoft.Extensions.AI;
|
using Microsoft.Extensions.AI;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -87,7 +88,7 @@ namespace xAiApi.Interfaces
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
#region Data Provider Based Actions ...
|
#region Loaders ...
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Load AI Projects ...
|
/// Load AI Projects ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -126,7 +127,10 @@ namespace xAiApi.Interfaces
|
|||||||
Guid conversationId,
|
Guid conversationId,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Queries ...
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Query Projects ...
|
/// Query Projects ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -169,7 +173,10 @@ namespace xAiApi.Interfaces
|
|||||||
XQuery query,
|
XQuery query,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Creators ...
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create an AI Project ...
|
/// Create an AI Project ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -201,7 +208,10 @@ namespace xAiApi.Interfaces
|
|||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Data Actions ...
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ask a Question as Prompt and Retrieve Response ...
|
/// Ask a Question as Prompt and Retrieve Response ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -211,6 +221,7 @@ namespace xAiApi.Interfaces
|
|||||||
/// <param name="conversationId"></param>
|
/// <param name="conversationId"></param>
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="files"></param>
|
/// <param name="files"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<XAiMessageDto> AskAsync(
|
Task<XAiMessageDto> AskAsync(
|
||||||
@@ -220,6 +231,7 @@ namespace xAiApi.Interfaces
|
|||||||
Guid conversationId,
|
Guid conversationId,
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
IFormFileCollection files = null,
|
IFormFileCollection files = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using xAiModels.Models.Dtos;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
namespace xAiApi.Interfaces
|
namespace xAiApi.Interfaces
|
||||||
{
|
{
|
||||||
@@ -176,6 +177,20 @@ namespace xAiApi.Interfaces
|
|||||||
[FromBody] XAiResponseRequest request,
|
[FromBody] XAiResponseRequest request,
|
||||||
CancellationToken cancellationToken = default
|
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
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+218
-158
@@ -15,11 +15,14 @@ using xCommons.Extensions;
|
|||||||
using xAiModels.Constants;
|
using xAiModels.Constants;
|
||||||
using xAiModels.Interfaces;
|
using xAiModels.Interfaces;
|
||||||
using xAiModels.Extensions;
|
using xAiModels.Extensions;
|
||||||
|
using xAiService.Constants;
|
||||||
using xAiApi.Configurations;
|
using xAiApi.Configurations;
|
||||||
using xExceptions.Constants;
|
using xExceptions.Constants;
|
||||||
using xAiModels.Models.Dtos;
|
using xAiModels.Models.Dtos;
|
||||||
using xAiService.Extensions;
|
using xAiService.Extensions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using xIdentityModels.Models;
|
||||||
|
using xFileService.Interfaces;
|
||||||
using Microsoft.Extensions.AI;
|
using Microsoft.Extensions.AI;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -44,12 +47,14 @@ namespace xAiApi.Providers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public XAiModelDescriptor Descriptor { get; }
|
public XAiModelDescriptor Descriptor { get; }
|
||||||
|
|
||||||
|
private readonly IXFileProvider fileProvider;
|
||||||
private readonly IXAiDataProvider dataProvider;
|
private readonly IXAiDataProvider dataProvider;
|
||||||
private readonly ILogger<XAIServiceBase> logger;
|
private readonly ILogger<XAIServiceBase> logger;
|
||||||
private readonly XAiApiConfiguration configuration;
|
private readonly XAiApiConfiguration configuration;
|
||||||
private readonly XValidationProvider validationProvider;
|
private readonly XValidationProvider validationProvider;
|
||||||
|
|
||||||
protected XAIServiceBase(
|
protected XAIServiceBase(
|
||||||
|
IXFileProvider fileProvider,
|
||||||
IXAiDataProvider dataProvider,
|
IXAiDataProvider dataProvider,
|
||||||
ILogger<XAIServiceBase> logger,
|
ILogger<XAIServiceBase> logger,
|
||||||
XAiApiConfiguration configuration,
|
XAiApiConfiguration configuration,
|
||||||
@@ -59,6 +64,7 @@ namespace xAiApi.Providers
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
this.fileProvider = fileProvider;
|
||||||
this.dataProvider = dataProvider;
|
this.dataProvider = dataProvider;
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
this.validationProvider = validationProvider;
|
this.validationProvider = validationProvider;
|
||||||
@@ -347,7 +353,7 @@ namespace xAiApi.Providers
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
#region Data Provider Based Actions ...
|
#region Loaders ...
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Load AI Projects ...
|
/// Load AI Projects ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -422,8 +428,6 @@ namespace xAiApi.Providers
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Load Conversations of Specified AI Project ...
|
/// Load Conversations of Specified AI Project ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -483,7 +487,153 @@ namespace xAiApi.Providers
|
|||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Queries ...
|
||||||
|
/// <summary>
|
||||||
|
/// Query Projects ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ownerId"></param>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XQueryResult<XAiProjectDto>> QueryProjects(
|
||||||
|
string ownerId,
|
||||||
|
XQuery query,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (ownerId.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await dataProvider.QueryProjects(
|
||||||
|
query: query,
|
||||||
|
ownerId: ownerId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Query Conversations ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ownerId"></param>
|
||||||
|
/// <param name="projectId"></param>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XQueryResult<XAiConversationDto>> QueryConversations(
|
||||||
|
string ownerId,
|
||||||
|
Guid projectId,
|
||||||
|
XQuery query,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (ownerId.IsNullOrEmpty() ||
|
||||||
|
projectId.IsDefaultGuid())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Project ...
|
||||||
|
var project = await dataProvider.GetProject(
|
||||||
|
id: projectId,
|
||||||
|
fillConversations: false,
|
||||||
|
fillConversationMessages: false,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
if (project.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Owner ...
|
||||||
|
if (ownerId != project.OwnerId)
|
||||||
|
{
|
||||||
|
XException.NotAllowed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await dataProvider.QueryConversations(
|
||||||
|
query: query,
|
||||||
|
ownerId: ownerId,
|
||||||
|
projectId: projectId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Query Messages ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ownerId"></param>
|
||||||
|
/// <param name="conversationId"></param>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XQueryResult<XAiMessageDto>> QueryMessages(
|
||||||
|
string ownerId,
|
||||||
|
Guid conversationId,
|
||||||
|
XQuery query,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (ownerId.IsNullOrEmpty() ||
|
||||||
|
conversationId.IsDefaultGuid())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Conversation ...
|
||||||
|
var conversation = await dataProvider.GetConversation(
|
||||||
|
id: conversationId,
|
||||||
|
fillMessages: false,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
if (conversation.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.NotFound.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Owner ...
|
||||||
|
if (ownerId != conversation.OwnerId)
|
||||||
|
{
|
||||||
|
XException.NotAllowed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await dataProvider.QueryMessages(
|
||||||
|
query: query,
|
||||||
|
ownerId: ownerId,
|
||||||
|
conversationId: conversationId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Creators ...
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create an AI Project ...
|
/// Create an AI Project ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -540,7 +690,10 @@ namespace xAiApi.Providers
|
|||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Data Actions ...
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ask a Question as Prompt and Retrieve Response ...
|
/// Ask a Question as Prompt and Retrieve Response ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -550,6 +703,7 @@ namespace xAiApi.Providers
|
|||||||
/// <param name="conversationId"></param>
|
/// <param name="conversationId"></param>
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="files"></param>
|
/// <param name="files"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<XAiMessageDto> AskAsync(
|
public async Task<XAiMessageDto> AskAsync(
|
||||||
@@ -559,6 +713,7 @@ namespace xAiApi.Providers
|
|||||||
Guid conversationId,
|
Guid conversationId,
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
IFormFileCollection files = null,
|
IFormFileCollection files = null,
|
||||||
|
XUserClaimsInfoDto userInfo = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -638,8 +793,26 @@ namespace xAiApi.Providers
|
|||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
// TODO: Parse Files ...
|
// Upload Files ...
|
||||||
// for Attached them into Prompt Message ...
|
IEnumerable<xFileService.Models.Dtos.XFileDto> uploadedFiles = null;
|
||||||
|
if (files.HasChild())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate User Info ...
|
||||||
|
if (userInfo.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Upload Files ...
|
||||||
|
uploadedFiles = await fileProvider.Upload(
|
||||||
|
files: files,
|
||||||
|
userInfo: userInfo,
|
||||||
|
connectionId: connectionId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Handle Memory ...
|
// Handle Memory ...
|
||||||
@@ -660,21 +833,55 @@ namespace xAiApi.Providers
|
|||||||
ConversationId = conversationId,
|
ConversationId = conversationId,
|
||||||
ConversationTitle = conversation.Title
|
ConversationTitle = conversation.Title
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Attached Uploaded File Id's as Meta Data ...
|
||||||
|
if (uploadedFiles.HasChild())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var fileIds = uploadedFiles.Select(f => f.Id).ToList();
|
||||||
|
promptMessage.MetaDatas = new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ XAiServiceConstants.XMetaDataFileIdsIdentifier, fileIds }
|
||||||
|
}.ToJSON();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Save Prompt Message ...
|
||||||
promptMessage = await dataProvider.AddMessage(
|
promptMessage = await dataProvider.AddMessage(
|
||||||
item: promptMessage,
|
item: promptMessage,
|
||||||
connectionId: connectionId,
|
connectionId: connectionId,
|
||||||
conversationId: conversationId,
|
conversationId: conversationId,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
promptMessage = await dataProvider.Enrich(
|
|
||||||
source: promptMessage,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Attach Uploaded Files ...
|
// Since Prompt Message Has Id now, we can Attach Uploaded Files to it ...
|
||||||
|
IList<AIContent> fileContents = null;
|
||||||
|
if (uploadedFiles.HasChild())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
foreach (var uf in uploadedFiles)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
await fileProvider.AddReference(
|
||||||
|
id: uf.Id,
|
||||||
|
userInfo: userInfo,
|
||||||
|
connectionId: connectionId,
|
||||||
|
forProvidedId: promptMessage.Id,
|
||||||
|
cancellationToken: cancellationToken,
|
||||||
|
providedFor: XAiServiceConstants.XAiMessageFilesIdentifier
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// TODO: Extract File Contents ...
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Converts to ChatMessage ...
|
||||||
var promptChatMessage = promptMessage
|
var promptChatMessage = promptMessage
|
||||||
.ToChatMessages();
|
.ToChatMessages(fileContents);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Ask Questions From LLM ...
|
// Ask Questions From LLM ...
|
||||||
@@ -701,10 +908,6 @@ namespace xAiApi.Providers
|
|||||||
conversationId: conversationId,
|
conversationId: conversationId,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
result = await dataProvider.Enrich(
|
|
||||||
source: result,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
@@ -904,149 +1107,6 @@ namespace xAiApi.Providers
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//
|
|
||||||
#region Query ...
|
|
||||||
/// <summary>
|
|
||||||
/// Query Projects ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ownerId"></param>
|
|
||||||
/// <param name="query"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task<XQueryResult<XAiProjectDto>> QueryProjects(
|
|
||||||
string ownerId,
|
|
||||||
XQuery query,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate ...
|
|
||||||
if (ownerId.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
XException.InvalidArgs.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
var result = await dataProvider.QueryProjects(
|
|
||||||
query: query,
|
|
||||||
ownerId: ownerId,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Query Conversations ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ownerId"></param>
|
|
||||||
/// <param name="projectId"></param>
|
|
||||||
/// <param name="query"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task<XQueryResult<XAiConversationDto>> QueryConversations(
|
|
||||||
string ownerId,
|
|
||||||
Guid projectId,
|
|
||||||
XQuery query,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate ...
|
|
||||||
if (ownerId.IsNullOrEmpty() ||
|
|
||||||
projectId.IsDefaultGuid())
|
|
||||||
{
|
|
||||||
XException.InvalidArgs.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve Project ...
|
|
||||||
var project = await dataProvider.GetProject(
|
|
||||||
id: projectId,
|
|
||||||
fillConversations: false,
|
|
||||||
fillConversationMessages: false,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
if (project.IsNullOrDefault())
|
|
||||||
{
|
|
||||||
XException.NotFound.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Owner ...
|
|
||||||
if (ownerId != project.OwnerId)
|
|
||||||
{
|
|
||||||
XException.NotAllowed.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
var result = await dataProvider.QueryConversations(
|
|
||||||
query: query,
|
|
||||||
ownerId: ownerId,
|
|
||||||
projectId: projectId,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Query Messages ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ownerId"></param>
|
|
||||||
/// <param name="conversationId"></param>
|
|
||||||
/// <param name="query"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task<XQueryResult<XAiMessageDto>> QueryMessages(
|
|
||||||
string ownerId,
|
|
||||||
Guid conversationId,
|
|
||||||
XQuery query,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate ...
|
|
||||||
if (ownerId.IsNullOrEmpty() ||
|
|
||||||
conversationId.IsDefaultGuid())
|
|
||||||
{
|
|
||||||
XException.InvalidArgs.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve Conversation ...
|
|
||||||
var conversation = await dataProvider.GetConversation(
|
|
||||||
id: conversationId,
|
|
||||||
fillMessages: false,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
if (conversation.IsNullOrDefault())
|
|
||||||
{
|
|
||||||
XException.NotFound.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Owner ...
|
|
||||||
if (ownerId != conversation.OwnerId)
|
|
||||||
{
|
|
||||||
XException.NotAllowed.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
var result = await dataProvider.QueryMessages(
|
|
||||||
query: query,
|
|
||||||
ownerId: ownerId,
|
|
||||||
conversationId: conversationId,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Base Dispose Action ...
|
/// Base Dispose Action ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ using xAiModels.Interfaces;
|
|||||||
using xAiApi.Configurations;
|
using xAiApi.Configurations;
|
||||||
using xExceptions.Constants;
|
using xExceptions.Constants;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using xFileService.Interfaces;
|
||||||
using Microsoft.Extensions.AI;
|
using Microsoft.Extensions.AI;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
@@ -28,15 +29,17 @@ namespace xAiApi.Providers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class XAiEmbeddingServiceBase : XAIServiceBase, IXAiEmbeddingServiceBase
|
public abstract class XAiEmbeddingServiceBase : XAIServiceBase, IXAiEmbeddingServiceBase
|
||||||
{
|
{
|
||||||
|
private readonly IXFileProvider fileProvider;
|
||||||
private readonly XAiModelDescriptor descriptor;
|
private readonly XAiModelDescriptor descriptor;
|
||||||
private readonly ILogger<XAiEmbeddingServiceBase> logger;
|
private readonly ILogger<XAiEmbeddingServiceBase> logger;
|
||||||
|
|
||||||
protected XAiEmbeddingServiceBase(
|
protected XAiEmbeddingServiceBase(
|
||||||
|
IXFileProvider fileProvider,
|
||||||
IXAiDataProvider dataProvider,
|
IXAiDataProvider dataProvider,
|
||||||
XAiApiConfiguration configuration,
|
XAiApiConfiguration configuration,
|
||||||
ILogger<XAiEmbeddingServiceBase> logger,
|
ILogger<XAiEmbeddingServiceBase> logger,
|
||||||
string embeddingModelName = XAiApiConstants.XAiEmbeddingModelName
|
string embeddingModelName = XAiApiConstants.XAiEmbeddingModelName
|
||||||
) : base(dataProvider, logger, configuration, null)
|
) : base(fileProvider, dataProvider, logger, configuration, null)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Prepare Embedding Model Descriptor ...
|
// Prepare Embedding Model Descriptor ...
|
||||||
@@ -46,6 +49,8 @@ namespace xAiApi.Providers
|
|||||||
XException.InvalidConfiguration.Throw();
|
XException.InvalidConfiguration.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.fileProvider = fileProvider;
|
||||||
|
|
||||||
//
|
//
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using xAiApi.Interfaces;
|
|||||||
using xCommons.Providers;
|
using xCommons.Providers;
|
||||||
using xAiModels.Interfaces;
|
using xAiModels.Interfaces;
|
||||||
using xAiApi.Configurations;
|
using xAiApi.Configurations;
|
||||||
|
using xFileService.Interfaces;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace xAiApi.Providers
|
namespace xAiApi.Providers
|
||||||
@@ -10,11 +11,13 @@ namespace xAiApi.Providers
|
|||||||
public class XDefaultAiService : XAIServiceBase, IXDefaultAiService
|
public class XDefaultAiService : XAIServiceBase, IXDefaultAiService
|
||||||
{
|
{
|
||||||
public XDefaultAiService(
|
public XDefaultAiService(
|
||||||
|
IXFileProvider fileProvider,
|
||||||
IXAiDataProvider dataProvider,
|
IXAiDataProvider dataProvider,
|
||||||
ILogger<XDefaultAiService> logger,
|
ILogger<XDefaultAiService> logger,
|
||||||
XAiApiConfiguration configuration,
|
XAiApiConfiguration configuration,
|
||||||
XValidationProvider validationProvider
|
XValidationProvider validationProvider
|
||||||
) : base(
|
) : base(
|
||||||
|
fileProvider,
|
||||||
dataProvider,
|
dataProvider,
|
||||||
logger,
|
logger,
|
||||||
configuration,
|
configuration,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using xAiApi.Constants;
|
|||||||
using xAiApi.Interfaces;
|
using xAiApi.Interfaces;
|
||||||
using xAiModels.Interfaces;
|
using xAiModels.Interfaces;
|
||||||
using xAiApi.Configurations;
|
using xAiApi.Configurations;
|
||||||
|
using xFileService.Interfaces;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace xAiApi.Providers
|
namespace xAiApi.Providers
|
||||||
@@ -9,10 +10,12 @@ namespace xAiApi.Providers
|
|||||||
public class XDefaultEmbeddingService : XAiEmbeddingServiceBase, IXDefaultEmbeddingService
|
public class XDefaultEmbeddingService : XAiEmbeddingServiceBase, IXDefaultEmbeddingService
|
||||||
{
|
{
|
||||||
public XDefaultEmbeddingService(
|
public XDefaultEmbeddingService(
|
||||||
|
IXFileProvider fileProvider,
|
||||||
IXAiDataProvider dataProvider,
|
IXAiDataProvider dataProvider,
|
||||||
XAiApiConfiguration configuration,
|
XAiApiConfiguration configuration,
|
||||||
ILogger<XDefaultEmbeddingService> logger
|
ILogger<XDefaultEmbeddingService> logger
|
||||||
) : base(
|
) : base(
|
||||||
|
fileProvider,
|
||||||
dataProvider,
|
dataProvider,
|
||||||
configuration,
|
configuration,
|
||||||
logger,
|
logger,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using xCommons.Providers;
|
|||||||
using xAiModels.Interfaces;
|
using xAiModels.Interfaces;
|
||||||
using xAiApi.Configurations;
|
using xAiApi.Configurations;
|
||||||
using Microsoft.Extensions.AI;
|
using Microsoft.Extensions.AI;
|
||||||
|
using xFileService.Interfaces;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace xAiApi.Providers
|
namespace xAiApi.Providers
|
||||||
@@ -11,6 +12,7 @@ namespace xAiApi.Providers
|
|||||||
public class XDefaultThinkingAiService : XAIServiceBase, IXDefaultThinkingAiService
|
public class XDefaultThinkingAiService : XAIServiceBase, IXDefaultThinkingAiService
|
||||||
{
|
{
|
||||||
public XDefaultThinkingAiService(
|
public XDefaultThinkingAiService(
|
||||||
|
IXFileProvider fileProvider,
|
||||||
IXAiDataProvider dataProvider,
|
IXAiDataProvider dataProvider,
|
||||||
ILogger<XAIServiceBase> logger,
|
ILogger<XAIServiceBase> logger,
|
||||||
XAiApiConfiguration configuration,
|
XAiApiConfiguration configuration,
|
||||||
@@ -18,6 +20,7 @@ namespace xAiApi.Providers
|
|||||||
ReasoningEffort effort = ReasoningEffort.Medium,
|
ReasoningEffort effort = ReasoningEffort.Medium,
|
||||||
ReasoningOutput output = ReasoningOutput.Full
|
ReasoningOutput output = ReasoningOutput.Full
|
||||||
) : base(
|
) : base(
|
||||||
|
fileProvider,
|
||||||
dataProvider,
|
dataProvider,
|
||||||
logger,
|
logger,
|
||||||
configuration,
|
configuration,
|
||||||
|
|||||||
Reference in New Issue
Block a user