LLaMA C#/.NET 库 是 AI Skill Hub 本期精选AI工具之一。已获得 3.7k 颗 GitHub Star,综合评分 7.5 分,整体质量较高。我们推荐使用将其纳入你的 AI 工具库,帮助提升工作效率。
LLaMA C#/.NET 库 是一款基于 C# 开发的开源工具,专注于 chatbot、gpt、llama 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
LLaMA C#/.NET 库 是一款基于 C# 开发的开源工具,专注于 chatbot、gpt、llama 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
# 克隆仓库 git clone https://github.com/SciSharp/LLamaSharp cd LLamaSharp # 查看安装说明 cat README.md # 按 README 完成环境依赖安装后即可使用
# 查看帮助 llamasharp --help # 基本运行 llamasharp [options] <input> # 详细使用说明请查阅文档 # https://github.com/SciSharp/LLamaSharp
# llamasharp 配置说明 # 查看配置选项 llamasharp --config-example > config.yml # 常见配置项 # output_dir: ./output # log_level: info # workers: 4 # 环境变量(覆盖配置文件) export LLAMASHARP_CONFIG="/path/to/config.yml"
LLamaSharp is a cross-platform library to run 🦙LLaMA model (and others) on your local device. Based on llama.cpp, inference with LLamaSharp is efficient on both CPU and GPU. With the higher-level APIs and RAG support, it's convenient to deploy LLMs (Large Language Models) in your application with LLamaSharp.
Please star the repo to show your support for this project!🤗
---
<details> <summary>Table of Contents</summary> <ul> <li><a href="#Documentation">Documentation</a></li> <li><a href="#Console Demo">Console Demo</a></li> <li><a href="#Integrations & Examples">Integrations & Examples</a></li> <li><a href="#Get started">Get started</a></li> <li><a href="#FAQ">FAQ</a></li> <li><a href="#Contributing">Contributing</a></li> <li><a href="#Join the community">Join the community</a></li> <li><a href="#Star history">Star history</a></li> <li><a href="#Contributor wall of fame">Contributor wall of fame</a></li> <li><a href="#Map of LLamaSharp and llama.cpp versions">Map of LLamaSharp and llama.cpp versions</a></li> </ul> </details>
To gain high performance, LLamaSharp interacts with native libraries compiled from c++, these are called backends. We provide backend packages for Windows, Linux and Mac with CPU, CUDA, Metal and Vulkan. You don't need to compile any c++, just install the backend packages.
If no published backend matches your device, please open an issue to let us know. If compiling c++ code is not difficult for you, you could also follow this guide to compile a backend and run LLamaSharp with it.
PM> Install-Package LLamaSharp
LLamaSharp.Backend.Cpu: Pure CPU for Windows, Linux & Mac. Metal (GPU) support for Mac.LLamaSharp.Backend.Cuda11: CUDA 11 for Windows & Linux.LLamaSharp.Backend.Cuda12: CUDA 12 for Windows & Linux.LLamaSharp.Backend.Vulkan: Vulkan for Windows & Linux.net6.0 or higher yet), which is based on Microsoft kernel-memory integration.There are integrations for the following libraries, making it easier to develop your APP. Integrations for semantic-kernel and kernel-memory are developed in the LLamaSharp repository, while others are developed in their own repositories.
The following examples show how to build APPs with LLamaSharp.

Here is a simple example to chat with a bot based on a LLM in LLamaSharp. Please replace the model path with yours.
using LLama;
using LLama.Common;
using LLama.Sampling;
string modelPath = @"<Your Model Path>"; // change it to your own model path.
var parameters = new ModelParams(modelPath)
{
ContextSize = 1024, // The longest length of chat as memory.
GpuLayerCount = 5 // How many layers to offload to GPU. Please adjust it according to your GPU memory.
};
using var model = LLamaWeights.LoadFromFile(parameters);
using var context = model.CreateContext(parameters);
var executor = new InteractiveExecutor(context);
// Add chat histories as prompt to tell AI how to act.
var chatHistory = new ChatHistory();
chatHistory.AddMessage(AuthorRole.System, "Transcript of a dialog, where the User interacts with an Assistant named Bob. Bob is helpful, kind, honest, good at writing, and never fails to answer the User's requests immediately and with precision.");
chatHistory.AddMessage(AuthorRole.User, "Hello, Bob.");
chatHistory.AddMessage(AuthorRole.Assistant, "Hello. How may I help you today?");
ChatSession session = new(executor, chatHistory);
InferenceParams inferenceParams = new InferenceParams()
{
MaxTokens = 256, // No more than 256 tokens should appear in answer. Remove it if antiprompt is enough for control.
AntiPrompts = new List<string> { "User:" }, // Stop generation once antiprompts appear.
SamplingPipeline = new DefaultSamplingPipeline(),
};
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("The chat session has started.\nUser: ");
Console.ForegroundColor = ConsoleColor.Green;
string userInput = Console.ReadLine() ?? "";
while (userInput != "exit")
{
await foreach ( // Generate the response streamingly.
var text
in session.ChatAsync(
new ChatHistory.Message(AuthorRole.User, userInput),
inferenceParams))
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write(text);
}
Console.ForegroundColor = ConsoleColor.Green;
userInput = Console.ReadLine() ?? "";
}
For more examples, please refer to LLamaSharp.Examples.
| LLaMA | Multimodal |
![]() |
![]() |
GpuLayerCount > 0 when loading the model weight. NativeLibraryConfig.All.WithLogCallback(delegate (LLamaLogLevel level, string message) { Console.Write($"{level}: {message}"); } )
Firstly, due to the large size of LLM models, it requires more time to generate output than other models, especially when you are using models larger than 30B parameters.
To see if that's a LLamaSharp performance issue, please follow the two tips below.
GpuLayerCount as large as possible.Generally, there are two possible cases for this problem:
Please set anti-prompt or max-length when executing the inference.
该库提供了一个高效的本地 LLM 运行解决方案,适用于聊天机器人和 GPT 等应用,值得推荐
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
✅ MIT 协议 — 最宽松的开源协议之一,可自由商用、修改、分发,仅需保留版权声明。
经综合评估,LLaMA C#/.NET 库 在AI工具赛道中表现稳健,质量良好。如果你已有明确的使用需求,可以直接上手体验;如果还在评估阶段,建议对比同类工具后再做决策。
| 原始名称 | LLamaSharp |
| Topics | chatbotgptllamac# |
| GitHub | https://github.com/SciSharp/LLamaSharp |
| License | MIT |
| 语言 | C# |
收录时间:2026-05-24 · 更新时间:2026-05-24 · License:MIT · AI Skill Hub 不对第三方内容的准确性作法律背书。