using xCommons.Extensions;
using System.Collections.Generic;
namespace xAiModels.Extensions
{
public static class XEmbeddingExtensions
{
///
/// Converts String to Embeddings JSON ...
///
///
///
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();
if (!result.HasChild())
{
result = [];
}
//
return result;
}
///
/// Converts to Meta Data Representation ...
///
///
///
public static Dictionary AsMetadat(this string source)
{
//
// Validate ...
if (source.IsNullOrEmpty()) {
return [];
}
//
// JSON is expected to be like: [0.12, 0.34, ...] ...
var result = source.FromJSON>();
if (!result.HasChild())
{
result = [];
}
//
return result;
}
}
}