using LLama.Common;
using LLama;
string modelPath = "..\\LLama.Unittest\\Models\\llama-2-7b-chat.Q4_0.gguf";
var prompt = " I want a C # function to do binary search of an array , please show me the code."; //提示词
// 加载模型
var parameters = new ModelParams(modelPath)
{ ContextSize = 1024,
Seed = 1337,
GpuLayerCount = 5
};
using var model = LLamaWeights.LoadFromFile(parameters);
// 初始化聊天会话
using var context = model.CreateContext(parameters);
var ex = new InteractiveExecutor(context);
ChatSession session = new ChatSession(ex);
// 显示提示
Console.WriteLine();
Console.Write(prompt);
// 循环运行推理以与LLM聊天
while (prompt != "stop")
{ foreach (var text in session.Chat(prompt, new InferenceParams() { Temperature = 0.6f, AntiPrompts = new List { "User:" } })) { Console.Write(text);
}
prompt = Console.ReadLine();
}
// 保存会话
session.SaveSession("SavedSessionPath");