首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

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

推荐一个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 { "User:" } })) { Console.Write(text); } prompt = Console.ReadLine();}

// 保存会话session.SaveSession("SavedSessionPath");

3、效果

04

项目地址

https://github.com/SciSharp/LLamaSharp

  • 发表于:
  • 原文链接https://page.om.qq.com/page/O2w2WAhInGz-tSeZNA1oAsCA0
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券