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.

SaveAndLoadState.cs 1.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using LLama.OldVersion;
  7. namespace LLama.Examples.Old
  8. {
  9. [Obsolete("The entire LLama.OldVersion namespace will be removed")]
  10. public class SaveAndLoadState: IDisposable
  11. {
  12. LLama.OldVersion.LLamaModel _model;
  13. public SaveAndLoadState(string modelPath, string prompt)
  14. {
  15. _model = new LLama.OldVersion.LLamaModel(new LLamaParams(model: modelPath, n_ctx: 2048, n_predict: -1, top_k: 10000, instruct: true,
  16. repeat_penalty: 1.1f, n_batch: 256, temp: 0.2f)).WithPrompt(prompt);
  17. }
  18. public void Run(string question)
  19. {
  20. // Only run once here.
  21. Console.Write("\nUser:");
  22. Console.ForegroundColor = ConsoleColor.Green;
  23. Console.WriteLine(question);
  24. Console.ForegroundColor = ConsoleColor.White;
  25. var outputs = _model.Call(question);
  26. foreach (var output in outputs)
  27. {
  28. Console.Write(output);
  29. }
  30. }
  31. public void SaveState(string filename)
  32. {
  33. _model.SaveState(filename);
  34. Console.WriteLine("Saved state!");
  35. }
  36. public void LoadState(string filename)
  37. {
  38. _model.LoadState(filename);
  39. Console.WriteLine("Loaded state!");
  40. }
  41. public void Dispose()
  42. {
  43. _model.Dispose();
  44. }
  45. }
  46. }