2023-06-27 19:17:53 +00:00
|
|
|
using BotSharp.Abstraction.MLTasks;
|
2023-06-27 23:36:50 +00:00
|
|
|
using LLama;
|
|
|
|
|
using LLama.Common;
|
2023-06-27 19:17:53 +00:00
|
|
|
|
|
|
|
|
namespace BotSharp.Core.Plugins.LLamaSharp;
|
|
|
|
|
|
|
|
|
|
public class TextEmbeddingProvider : ITextEmbedding
|
|
|
|
|
{
|
2023-06-27 23:36:50 +00:00
|
|
|
private readonly IServiceProvider _services;
|
2023-06-27 19:17:53 +00:00
|
|
|
public int Dimension => throw new NotImplementedException();
|
|
|
|
|
|
2023-06-27 23:36:50 +00:00
|
|
|
public TextEmbeddingProvider(IServiceProvider services)
|
2023-06-27 19:17:53 +00:00
|
|
|
{
|
2023-06-27 23:36:50 +00:00
|
|
|
_services = services;
|
2023-06-27 19:17:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float[] GetVector(string text)
|
|
|
|
|
{
|
2023-06-27 23:36:50 +00:00
|
|
|
var llama = _services.GetRequiredService<LlamaAiModel>();
|
|
|
|
|
|
|
|
|
|
var executor = new LLamaEmbedder(new ModelParams(llama.Settings.ModelPath));
|
|
|
|
|
|
|
|
|
|
return executor.GetEmbeddings(text);
|
2023-06-27 19:17:53 +00:00
|
|
|
}
|
|
|
|
|
}
|