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.

KernelMemory.cs 1.6 kB

2 years ago
2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using LLamaSharp.KernelMemory;
  7. using Microsoft.KernelMemory;
  8. using Microsoft.KernelMemory.Handlers;
  9. namespace LLama.Examples.NewVersion
  10. {
  11. public class KernelMemory
  12. {
  13. public static async Task Run()
  14. {
  15. Console.WriteLine("Example from: https://github.com/microsoft/kernel-memory/blob/main/examples/101-using-core-nuget/Program.cs");
  16. Console.Write("Please input your model path: ");
  17. var modelPath = Console.ReadLine();
  18. var memory = new KernelMemoryBuilder()
  19. .WithLLamaSharpDefaults(new LLamaSharpConfig(modelPath))
  20. .With(new TextPartitioningOptions
  21. {
  22. MaxTokensPerParagraph = 300,
  23. MaxTokensPerLine = 100,
  24. OverlappingTokens = 30
  25. })
  26. .BuildServerlessClient();
  27. await memory.ImportDocumentAsync(@"./Assets/sample-SK-Readme.pdf", steps: Constants.PipelineWithoutSummary);
  28. var question = "What's Semantic Kernel?";
  29. Console.WriteLine($"\n\nQuestion: {question}");
  30. var answer = await memory.AskAsync(question);
  31. Console.WriteLine($"\nAnswer: {answer.Result}");
  32. Console.WriteLine("\n\n Sources:\n");
  33. foreach (var x in answer.RelevantSources)
  34. {
  35. Console.WriteLine($" - {x.SourceName} - {x.Link} [{x.Partitions.First().LastUpdate:D}]");
  36. }
  37. }
  38. }
  39. }