- 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.
54 lines
1.3 KiB
C#
54 lines
1.3 KiB
C#
using System;
|
|
using xCommons.Extensions;
|
|
|
|
namespace xAiModels.Extensions
|
|
{
|
|
public static class XEmbeddingExtensions
|
|
{
|
|
/// <summary>
|
|
/// Converts String to Embeddings JSON ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <returns></returns>
|
|
public static float[] AsEmbedding(this string source)
|
|
{
|
|
//
|
|
// Validate ...
|
|
if (source.IsNullOrEmpty())
|
|
{
|
|
return [];
|
|
}
|
|
|
|
//
|
|
// JSON is expected to be like: [0.12, 0.34, ...] ...
|
|
var result = source.FromJSON<float[]>();
|
|
if (!result.HasChild())
|
|
{
|
|
result = [];
|
|
}
|
|
|
|
//
|
|
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;
|
|
}
|
|
}
|
|
} |