使用本地 LLM 构建 Llama 3.1 8b Streamlit 聊天应用程序:使用 Ollama 的分

如何使用 Langchain、Ollama 和 Streamlit 构建 RAG 在本博客完成中,我们将指导您创建可在本地运行的 RAG 的过程。这个过程不仅会加深您对尖端语言如何计算机工作的理解,还将使您能够在自己的项目中实施它们无论您是希望将 RAG 集成到现有应用程序中,还是只是探索 NLP 的前沿领域,本教程都是您的入门之选。 阅读详情
AI摘要

本文介绍如何使用Llama3.18b模型和Ollama库构建Streamlit聊天应用,涵盖环境搭建、代码实现及大模型AI学习路径。

介绍

大型语言模型(LLMs)彻底改变了人工智能领域,提供了令人印象深刻的语言理解和生成能力。

图片

本文将指导您构建一个使用本地LLM的Streamlit聊天应用程序,特别是来自Meta的Llama 3.1 8b模型,通过Ollama库进行集成。

前提条件

在我们深入代码之前,请确保您已安装以下内容:

  • Python
  • Streamlit
  • Ollama

设置 Ollama 和下载 Llama 3.1 8b

首先,您需要安装 Ollama 并下载 Llama 3.1 8b 模型。打开命令行界面并执行以下命令:

在这里插入图片描述

创建 Modelfile

要创建一个与您的 Streamlit 应用无缝集成的自定义模型,请按照以下步骤操作:

  1. 在您的项目目录中,创建一个名为 Modelfile 的文件,不带任何扩展名。
  2. 在文本编辑器中打开 Modelfile,并添加以下内容:
model: llama3.1:8b

此文件指示 Ollama 使用 Llama 3.1 8b 模型。

代码

导入库和

零代码构建本地AI应用:Ollama+Streamlit实战指南 生成式AI应用(GenAI App)本质上是面向业务场景的智能自动化工具,其核心原理在于将大模型能力封装为可配置、可复用、低依赖的交互流程。技术价值不在于模型参数规模,而在于降低使用门槛——通过本地化部署、RAG知识增强与零代码前端,让具备办公软件操作能力的业务人员(Anyone)也能在数小时内交付可用工具。典型应用场景包括合同关键字段抽取、文档智能问答、营销文案批量生成等轻量级AI流水线。本文聚焦‘本地离线、双击即用’的工程实践路径,深度融合Ollama模型管理与Streamlit界面开发,提供从环境搭建 阅读详情

相关推荐

Ollama教程——生成内容API:利用Ollama的原生API进行AI应用开发

在深入探讨ollama的API接口之前,让我们先了解一下API接口的基本概念及其在软件开发中的作用。API,或称应用程序编程接口,是一套明确定义的通讯方法,允许不同软件应用之间交换数据和功能。它们是现代软件开发不可或缺的一部分,尤其是在构建模块化、可扩展和维护性强的系统时。在使用生成完成(Generate a Completion)API时,精确而具体的提示词将大大提高生成内容的相关性和质量。例如,在构建聊天机器人时,根据上下文和用户的具体问题设计提示词,能够使回答更加准确和自然。

walkskyer的博客 1万+

ollama streamlit或gradio 搭建简单聊天窗口

【代码】streamlit ollama搭建简单聊天窗口。

weixin_42357472的博客 788

使用 Ollama、Llama 3 和 Streamlit 构建您的本地 AI 聊天机器人:初学者教程。 在您的笔记本电脑上与 Llama 3 8B 聊天

隐私和安全怎么办?”是人工智能领域的一个大问题。GPT-4o 或 Claude 3.5 Sonnet 令人印象深刻且功能强大。但问题是…每次使用模型(通过 ChatGPT、Claude Chat 或 API)时,您都会向 OpenAI 或 Anthropic 服务器发送“某些内容”。对于想要利用人工智能的公司来说,“某些东西”通常是敏感数据,例如:客户信息,例如姓名、地址、社会保险号、出生日期。财务信息,例如信用卡号、银行账户详细信息。健康记录,例如私人诊断、治疗、药物。

iCloudEnd的博客 395

如何使用 Code Llama 构建您自己的 LLM 编码助手 ,使用 CodeLlama-7b-Instruct-hf 和 Streamlit 创建本地 LLM 聊天机器人

Code Llama 是由 Meta AI 创建的一个特殊的代码法学硕士系列,最初于 2023 年 8 月发布。从基础模型 Llama 2(类似于 GPT-4 的仅解码器的 Transformer 模型)开始,Meta AI 使用 500B 个令牌的训练数据(主要是代码)进行了进一步训练。之后,Code Llama 又推出了三个不同版本、四种不同尺寸。Code Llama 模型可免费用于研究和商业用途。代码骆驼Code Llama 是代码生成的基础模型。

iCloudEnd的博客 831

本地部署开源大模型的完整教程LangChain + Streamlit+ Llama

本地部署开源大模型的完整教程LangChain + Streamlit+ Llama

西门子Industrial Copilot实战:5个工业场景下的AI效率提升案例

本文通过五个工业场景实战案例,深入解析西门子Industrial Copilot如何将工业智能转化为实际生产力。从自动化配置、预测性维护到能源优化与人机交互,这位AI助手显著缩短工程周期、提升设备可用率并降低运营成本,展示了其在工业领域系统化、工程化的落地价值。

3c4x5z6v7b的博客 924

nnU-Net v2实战:从零开始配置环境与训练自定义医学影像数据集

本文详细介绍了nnU-Net v2在医学影像分割中的实战应用,从环境配置到自定义数据集训练的全流程。重点讲解了Python 3.9+环境搭建、PyTorch安装技巧、医学影像数据预处理规范,以及五折交叉验证训练方法,帮助开发者快速掌握这一先进的医学影像分析工具。

weixin_28718487的博客 352

从零开始用飞牛fnas搭建集成DeepSeek-R1的远程AI工作台

从零开始用飞牛fnas搭建集成DeepSeek-R1的远程AI工作台

AI+全栈,AI+应用,实操落地,前沿技术 3802

从零开始学华为设备:手把手教你用ENSP搭建OSPF实验环境(附拓扑文件)

本文详细介绍了如何使用华为ENSP模拟器从零开始搭建OSPF多区域网络实验环境,包括拓扑规划、设备配置、OSPF参数优化及故障排查技巧。通过实战案例和配置示例,帮助网络工程师快速掌握华为设备的OSPF协议配置,提升企业网络环境中的实战能力。

weixin_29305313的博客 283

高通ISP模块全解析:从Raw到JPEG的18个关键处理步骤(附避坑指南)

本文全面解析高通ISP模块从Raw到JPEG的18个关键处理步骤,涵盖原始数据预处理、色彩科学处理链、画质增强与降噪等核心环节。通过实战调优经验,揭示ISP架构中的技术原理与工程实践要点,帮助开发者避免常见问题,提升移动影像处理质量。

weixin_30399155的博客 355

Tessent MBIST SDC

主要是两个PROC,tessent_constrain_${design_name}_mentor_ijtag_non_modal和tessent_constrain_${design_name}_mentor_memory_bist_modal。其中,Memory/MBIST controller/MEM Interface可以从func_clk_1来(用func_clk_1和func_clk_2的高频时钟),如图中红色线。其中,SIB和BAP用ijtag_tck的clock,如图绿色线。

po_poo的博客 1985

uniapp - [微信小程序 | 安卓苹果app] 详细实现接入天地图完整流程,提供显示地图、IP 属地定位 / 用户定位的城市名称、用户定位的经纬度超多功能(复制运行示例代码,详细注释及常见问题)

uni-app,微信小程序,安卓app,苹果app,App端,支付宝小程序,nvue,天地图,国家天地图api,接入使用天地图,uniApp小程序端接入天地图,uniapp安卓苹果app端接入天地图,微信小程序平台如何引入天地图,天地图Api使用教程,如何在uniapp里集成天地图,使用天地图获取当前定位,天地图api教程,天地图官方文档,天地图详细使用教程,Uniapp项目如何使用天地图,项目引入天地图配置及使用教程,使用天地图获取用户定位,天地图获取用户当前位置信息(经纬度),如何通过天地图拿到用户定位

🏆 前端领域优质创作者 1万+

使用ChatGPT工具阅读文献的实战教程

本文介绍核心内容为使用ChatGPT工具阅读文献,希望对学习和使用ChatGPT的同学们有所帮助。为了兼顾质量和速度,本专栏的更新频率为一周一到两更。 文章目录 1. 前言 2. 实战教程 2.1 下载工具并登录 2.2 提取文献中的关键信息

herosunly的博客 15万+

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: 基于大模型 Prompt + LangChain 架构的 AI 翻译系统全流程解析
下一篇: 详解Graph Embedding经典方法:算法原理、代码实现与应用样例
普通网友
博客等级 码龄3年 4490粉丝 309原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值