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.3 kB

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