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 2.0 kB

2 years ago
2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using LLamaSharp.KernelMemory;
  2. using Microsoft.KernelMemory;
  3. using Microsoft.KernelMemory.Configuration;
  4. namespace LLama.Examples.Examples
  5. {
  6. public class KernelMemory
  7. {
  8. public static async Task Run()
  9. {
  10. string modelPath = UserSettings.GetModelPath();
  11. Console.ForegroundColor = ConsoleColor.Yellow;
  12. Console.WriteLine("This example is from : \n" +
  13. "https://github.com/microsoft/kernel-memory/blob/main/examples/101-using-core-nuget/Program.cs");
  14. var searchClientConfig = new SearchClientConfig
  15. {
  16. MaxMatchesCount = 1,
  17. AnswerTokens = 100,
  18. };
  19. var memory = new KernelMemoryBuilder()
  20. .WithLLamaSharpDefaults(new LLamaSharpConfig(modelPath)
  21. {
  22. DefaultInferenceParams = new Common.InferenceParams
  23. {
  24. AntiPrompts = new List<string> { "\n\n" }
  25. }
  26. })
  27. .WithSearchClientConfig(searchClientConfig)
  28. .With(new TextPartitioningOptions
  29. {
  30. MaxTokensPerParagraph = 300,
  31. MaxTokensPerLine = 100,
  32. OverlappingTokens = 30
  33. })
  34. .Build();
  35. await memory.ImportDocumentAsync(@"./Assets/sample-SK-Readme.pdf", steps: Constants.PipelineWithoutSummary);
  36. var question = "What's Semantic Kernel?";
  37. Console.WriteLine($"\n\nQuestion: {question}");
  38. var answer = await memory.AskAsync(question);
  39. Console.WriteLine($"\nAnswer: {answer.Result}");
  40. Console.WriteLine("\n\n Sources:\n");
  41. foreach (var x in answer.RelevantSources)
  42. {
  43. Console.WriteLine($" - {x.SourceName} - {x.Link} [{x.Partitions.First().LastUpdate:D}]");
  44. }
  45. }
  46. }
  47. }