BotSharp/src/Plugins/BotSharp.Plugin.MetaAI/Providers/fastTextEmbeddingProvider.cs

28 lines
662 B
C#
Raw Normal View History

2023-06-17 13:32:39 +00:00
using BotSharp.Abstraction.MLTasks;
using BotSharp.Plugin.MetaAI.Settings;
using FastText.NetWrapper;
namespace BotSharp.Plugin.MetaAI.Providers;
public class fastTextEmbeddingProvider : ITextEmbedding
{
private FastTextWrapper _fastText;
private readonly fastTextSetting _settings;
public fastTextEmbeddingProvider(fastTextSetting settings)
{
_settings = settings;
_fastText = new FastTextWrapper();
if (!_fastText.IsModelReady())
{
_fastText.LoadModel(settings.ModelPath);
}
}
public float[] GetVector(string text)
{
return _fastText.GetSentenceVector(text);
}
}