Make projectId Nullable in Data Provider and Remove Api Configuration

- IXAiDataProvider.GetDefaultConversation: projectId changed from Guid to Guid?;
- XAiDataProvider.GetDefaultConversation / HasDefaultConversation /
  CreateDefaultConversation: adapt to Guid? (use !projectId.HasValue instead of
  projectId.IsNull(); resolve project via projectId.Value);
- XAiDataProvider: conversation lookup predicate fixed to
  x.ProjectId == project.Id (was x.ProjectId == projectId);
- XEmbeddingExtensions: add ToEmbedding(this ReadOnlyMemory<float>) to persist
  embeddings as JSON;
- XAiDataProvider: use item.Embedding.ToEmbedding() instead of ToJSON() when
  upserting vectors;
- XAiModelsExtensions: rename GetDafualtProject -> GetDafaultProject (typo fix);
- Remove Configurations/XAiApiConfiguration.cs and
  Extensions/XAiApiConfigurationExtensions.cs (Api configuration does not belong
  to the models module).
BREAKING: XAiApiConfiguration / XAiApiConfigurationExtensions removed from
          xAiModels; GetDafualtProject renamed to GetDafaultProject.
This commit is contained in:
2026-11-02 16:37:27 +03:30
parent c4b7e86174
commit 9e7710e345
6 changed files with 41 additions and 89 deletions
-28
View File
@@ -1,28 +0,0 @@
using xAiModels.Models;
using xAiModels.Constants;
namespace xAiModels.Configurations
{
public class XAiApiConfiguration
{
/// <summary>
/// Model Providers ...
/// </summary>
public XAiModelDescriptor[] Models { get; set; } = [];
/// <summary>
/// Each User must Has a Default Project, this is Title Resource Identifier ...
/// </summary>
public string DefaultProjectTitleResource { get; set; } = XAiModelsConstants.DefaultXAiProjectTitleResourceID;
/// <summary>
/// Each User must Has a Default Project, this is Description Resource Identifier ...
/// </summary>
public string DefaultProjectDescriptionResource { get; set; } = XAiModelsConstants.DefaultXAiProjectDescriptionResourceID;
/// <summary>
/// Each User must Has a Default Conversation, this is Title Resource Identifier ... ...
/// </summary>
public string DefaultConversationTitleResource { get; set; } = XAiModelsConstants.DefaultXAiConversationTitleResourceID;
}
}
@@ -1,42 +0,0 @@
using System.Linq;
using xAiModels.Models;
using xCommons.Extensions;
using xAiModels.Configurations;
namespace xAiModels.Extensions
{
public static class XAiApiConfigurationExtensions
{
/// <summary>
/// Validate Api Configuration ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static bool IsValid(this XAiApiConfiguration source)
{
return
!source.IsNullOrDefault() &&
source.Models.HasChild();
}
/// <summary>
/// Retrieve Default Model Descriptor ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static XAiModelDescriptor GetDefaultModel(this XAiApiConfiguration source)
{
//
XAiModelDescriptor result = null;
//
if (source.IsValid())
{
result = source.Models.First();
}
//
return result;
}
}
}
+1 -1
View File
@@ -339,7 +339,7 @@ namespace xAiModels.Extensions
/// <param name="source"></param>
/// <param name="ownerId"></param>
/// <returns></returns>
public static Guid GetDafualtProject(
public static Guid GetDafaultProject(
this IEnumerable<XAiProjectDto> source,
string ownerId
)
+23 -1
View File
@@ -1,3 +1,4 @@
using System;
using xCommons.Extensions;
namespace xAiModels.Extensions
@@ -13,7 +14,8 @@ namespace xAiModels.Extensions
{
//
// Validate ...
if (source.IsNullOrEmpty()) {
if (source.IsNullOrEmpty())
{
return [];
}
@@ -28,5 +30,25 @@ namespace xAiModels.Extensions
//
return result;
}
/// <summary>
/// Converts ReadOnly Memory to Embedding Representation ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static string ToEmbedding(this ReadOnlyMemory<float> source)
{
//
var result = string.Empty;
//
if (!source.IsNull() && !source.IsEmpty)
{
result = source.ToArray().ToJSON();
}
//
return result;
}
}
}
+1 -1
View File
@@ -197,7 +197,7 @@ namespace xAiModels.Interfaces
/// <returns></returns>
Task<XAiConversationDto> GetDefaultConversation(
string ownerId,
Guid projectId,
Guid? projectId,
string connectionId = null,
CancellationToken cancellationToken = default
);
+16 -16
View File
@@ -1009,7 +1009,7 @@ namespace xAiModels.Providers
/// <returns></returns>
public async Task<XAiConversationDto> GetDefaultConversation(
string ownerId,
Guid projectId,
Guid? projectId,
string connectionId = null,
CancellationToken cancellationToken = default
)
@@ -1024,8 +1024,8 @@ namespace xAiModels.Providers
//
// Prepare Project ...
XAiProjectDto project = null;
if (projectId.IsNull() ||
projectId.IsDefaultGuid()
if (!projectId.HasValue ||
projectId.Value.IsDefaultGuid()
)
{
//
@@ -1039,7 +1039,7 @@ namespace xAiModels.Providers
{
//
project = await projectRepositoryService.GetAsync(
id: projectId,
id: projectId.Value,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken
@@ -1093,7 +1093,7 @@ namespace xAiModels.Providers
var result = await conversationRepositoryService.FindOneAsync(
cancellationToken: cancellationToken,
predicate: x =>
x.ProjectId == projectId &&
x.ProjectId == project.Id &&
x.Title == resource.ResourceTitle
);
@@ -1533,7 +1533,7 @@ namespace xAiModels.Providers
{
//
exists.Text = item.Text;
exists.Embedding = item.Embedding.ToJSON();
exists.Embedding = item.Embedding.ToEmbedding();
exists.Type = item.Type.IsNullOrEmpty() ? exists.Type : item.Type;
exists.Metadata = item.Metadata.IsNullOrDefault() ? exists.Metadata : item.Metadata.ToJSON();
toUpdate.Add(exists);
@@ -1547,7 +1547,7 @@ namespace xAiModels.Providers
Type = item.Type,
Identifier = item.Identifier,
Metadata = item.Metadata.ToJSON(),
Embedding = item.Embedding.ToJSON(),
Embedding = item.Embedding.ToEmbedding(),
Id = item.Id.IsDefaultGuid() ? Guid.NewGuid() : item.Id,
});
}
@@ -2057,7 +2057,7 @@ namespace xAiModels.Providers
/// <returns></returns>
private async Task<bool> HasDefaultConversation(
string ownerId,
Guid projectId,
Guid? projectId,
string connectionId = null,
CancellationToken cancellationToken = default
)
@@ -2073,8 +2073,8 @@ namespace xAiModels.Providers
//
// Prepare Project ...
XAiProjectDto project = null;
if (projectId.IsNull() ||
projectId.IsDefaultGuid()
if (!projectId.HasValue ||
projectId.Value.IsDefaultGuid()
)
{
//
@@ -2088,7 +2088,7 @@ namespace xAiModels.Providers
{
//
project = await projectRepositoryService.GetAsync(
id: projectId,
id: projectId.Value,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken
@@ -2124,7 +2124,7 @@ namespace xAiModels.Providers
var defaultConversation = await conversationRepositoryService.FindOneAsync(
cancellationToken: cancellationToken,
predicate: x =>
x.ProjectId == projectId &&
x.ProjectId == project.Id &&
x.Title == resource.ResourceTitle
);
result = !defaultConversation.IsNullOrDefault();
@@ -2143,7 +2143,7 @@ namespace xAiModels.Providers
/// <returns></returns>
private async Task CreateDefaultConversation(
string ownerId,
Guid projectId,
Guid? projectId,
string connectionId = null,
CancellationToken cancellationToken = default
)
@@ -2162,8 +2162,8 @@ namespace xAiModels.Providers
//
// Prepare Project ...
XAiProjectDto project = null;
if (projectId.IsNull() ||
projectId.IsDefaultGuid()
if (!projectId.HasValue ||
projectId.Value.IsDefaultGuid()
)
{
//
@@ -2177,7 +2177,7 @@ namespace xAiModels.Providers
{
//
project = await projectRepositoryService.GetAsync(
id: projectId,
id: projectId.Value,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken