You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

LLamaSharpTextCompletion.cs 1.1 kB

123456789101112131415161718192021222324252627
  1. using LLama;
  2. using LLama.Abstractions;
  3. using Microsoft.SemanticKernel.AI.TextCompletion;
  4. namespace LLamaSharp.SemanticKernel.TextCompletion;
  5. public sealed class LLamaSharpTextCompletion : ITextCompletion
  6. {
  7. public ILLamaExecutor executor;
  8. public LLamaSharpTextCompletion(ILLamaExecutor executor)
  9. {
  10. this.executor = executor;
  11. }
  12. public async Task<IReadOnlyList<ITextResult>> GetCompletionsAsync(string text, CompleteRequestSettings requestSettings, CancellationToken cancellationToken = default)
  13. {
  14. var result = executor.InferAsync(text, requestSettings.ToLLamaSharpInferenceParams(), cancellationToken);
  15. return await Task.FromResult(new List<ITextResult> { new LLamaTextResult(result) }.AsReadOnly()).ConfigureAwait(false);
  16. }
  17. public async IAsyncEnumerable<ITextStreamingResult> GetStreamingCompletionsAsync(string text, CompleteRequestSettings requestSettings, CancellationToken cancellationToken = default)
  18. {
  19. var result = executor.InferAsync(text, requestSettings.ToLLamaSharpInferenceParams(), cancellationToken);
  20. yield return new LLamaTextResult(result);
  21. }
  22. }