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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Kernel memory
  2. ```cs
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using LLamaSharp.KernelMemory;
  9. using Microsoft.KernelMemory;
  10. using Microsoft.KernelMemory.Configuration;
  11. using Microsoft.KernelMemory.Handlers;
  12. public class KernelMemory
  13. {
  14. public static async Task Run()
  15. {
  16. Console.WriteLine("Example from: https://github.com/microsoft/kernel-memory/blob/main/examples/101-using-core-nuget/Program.cs");
  17. Console.Write("Please input your model path: ");
  18. var modelPath = Console.ReadLine();
  19. var searchClientConfig = new SearchClientConfig
  20. {
  21. MaxMatchesCount = 1,
  22. AnswerTokens = 100,
  23. };
  24. var memory = new KernelMemoryBuilder()
  25. .WithLLamaSharpDefaults(new LLamaSharpConfig(modelPath)
  26. {
  27. DefaultInferenceParams = new Common.InferenceParams
  28. {
  29. AntiPrompts = new List<string> { "\n\n" }
  30. }
  31. })
  32. .WithSearchClientConfig(searchClientConfig)
  33. .With(new TextPartitioningOptions
  34. {
  35. MaxTokensPerParagraph = 300,
  36. MaxTokensPerLine = 100,
  37. OverlappingTokens = 30
  38. })
  39. .Build();
  40. await memory.ImportDocumentAsync(@"./Assets/sample-SK-Readme.pdf", steps: Constants.PipelineWithoutSummary);
  41. var question = "What's Semantic Kernel?";
  42. Console.WriteLine($"\n\nQuestion: {question}");
  43. var answer = await memory.AskAsync(question);
  44. Console.WriteLine($"\nAnswer: {answer.Result}");
  45. Console.WriteLine("\n\n Sources:\n");
  46. foreach (var x in answer.RelevantSources)
  47. {
  48. Console.WriteLine($" - {x.SourceName} - {x.Link} [{x.Partitions.First().LastUpdate:D}]");
  49. }
  50. }
  51. }
  52. ```