«

C#开源项目:私有化部署LLama推理大模型

WAP站长网 发布于 阅读:38 SEO教程


推荐一个C#大模型推理开源项目,让你轻松驾驭私有化部署!

01 项目简介

LLama是Meta发布的一个免费开源的大模型,是一个有着上百亿数量级参数的大语言模型,支持CPU和GPU两种方式。

而LLamaSharp就是针对llama.cpp封装的C#版本,让方便我们基于C#开发应用,让我们不需要自己编译llama.cpp。它的性能接近llama.cpp,支持Windows、Linux和MAC。

02 项目结构

该项目提供了多种Web、WebAPI、控制台等多个Demo版本。

03 使用方法

1、安装依赖

Install-Package LLamaSharp 

2、演示源码

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<string> { "User:" } })) { Console.Write(text); } prompt = Console.ReadLine(); } // 保存会话 session.SaveSession("SavedSessionPath"); 

3、效果

04 项目地址

https://github.com/SciSharp/LLamaSharp

更多开源项目: https://github.com/bianchenglequ/NetCodeTop

- End -

推荐阅读

Helix Toolkit:为.NET开发者带来的3D视觉盛宴

10个基于.Net开发的Windows开源软件项目

毁掉一个程序员的6个方法

推荐10个.Net通用权限管理开源项目

基于.NET的强大文件格式开源转换工具

llamapromptcodechat开源项目windows大模型gitwebgpugithubats模型推理createcpu文件格式mmolinux程序员免费开源开源软件unit3d视觉权限管理prompts提示词转换工具mac开发者llm语言模型api大语言模型url