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.

LlavaInteractiveModeExecute.cs 1.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using LLama.Common;
  2. namespace LLama.Examples.Examples
  3. {
  4. public class LlavaInteractiveModeExecute
  5. {
  6. public static async Task Run()
  7. {
  8. string multiModalProj = UserSettings.GetMMProjPath();
  9. string modelPath = UserSettings.GetModelPath();
  10. string imagePath = UserSettings.GetImagePath();
  11. var prompt = (await File.ReadAllTextAsync("Assets/vicuna-llava-v16.txt")).Trim();
  12. var parameters = new ModelParams(modelPath)
  13. {
  14. ContextSize = 4096,
  15. Seed = 1337,
  16. GpuLayerCount = 5
  17. };
  18. using var model = LLamaWeights.LoadFromFile(parameters);
  19. using var context = model.CreateContext(parameters);
  20. // Llava Init
  21. using var clipModel = LLavaWeights.LoadFromFile(multiModalProj);
  22. var ex = new InteractiveExecutor(context, clipModel );
  23. ex.ImagePath = imagePath;
  24. Console.ForegroundColor = ConsoleColor.Yellow;
  25. Console.WriteLine("The executor has been enabled. In this example, the prompt is printed, the maximum tokens is set to 1024 and the context size is 4096. ");
  26. Console.ForegroundColor = ConsoleColor.White;
  27. Console.Write(prompt);
  28. var inferenceParams = new InferenceParams() { Temperature = 0.1f, AntiPrompts = new List<string> { "USER:" }, MaxTokens = 1024 };
  29. while (true)
  30. {
  31. await foreach (var text in ex.InferAsync(prompt, inferenceParams))
  32. {
  33. Console.Write(text);
  34. }
  35. Console.ForegroundColor = ConsoleColor.Green;
  36. prompt = Console.ReadLine();
  37. Console.ForegroundColor = ConsoleColor.White;
  38. }
  39. }
  40. }
  41. }