利用 Llama 3.1模型 + Dify开源LLM应用开发平台,在你的Windows环境中搭建一套AI工作流

1. 什么是Ollama?

image-20241012175128004

Ollama 是一种可以学习和回答问题的 AI 模型,它能够进行自然语言交互,类似于人类对话。它具备一些独特的功能,如:

  1. 自主学习: Ollama 可以通过自身的学习过程改善其回答质量和知识范围。
  2. 无限回复: Ollama 能够不断地回答问题,无论你问多少个,直到你满意为止。
  3. 自然语言: Ollama 支持多种语言,包括英语、西班牙语等,你可以与它进行母语对话。

2. 什么是Dify?

Dify是一个开源的LLM应用程序开发平台。Dify直观的界面结合了人工智能工作流程、RAG管道、代理功能、模型管理、可观察性功能等,让您快速从原型进入生产。

3. 下载Ollama

下载链接:https://ollama.com

image-20241012170904054

image-20241012170949264

4. 安装Ollama

打开安装包,安装Ollama。

image-20240814172442161

5. Ollama Model library模型库

Ollama supports a list of models available on ollama.com/library

Here are some example models that can be downloaded:

ModelParametersSizeDownload
Llama 3.18B4.7GBollama run llama3.1
Llama 3.170B40GBollama run llama3.1:70b
Llama 3.1405B231GBollama run llama3.1:405b
Phi 3 Mini3.8B2.3GBollama run phi3
Phi 3 Medium14B7.9GBollama run phi3:medium
Gemma 22B1.6GBollama run gemma2:2b
Gemma 29B5.5GBollama run gemma2
Gemma 227B16GBollama run gemma2:27b
Mistral7B4.1GBollama run mistral
Moondream 21.4B829MBollama run moondream
Neural Chat7B4.1GBollama run neural-chat
Starling7B4.1GBollama run starling-lm
Code Llama7B3.8GBollama run codellama
Llama 2 Uncensored7B3.8GBollama run llama2-uncensored
LLaVA7B4.5GBollama run llava
Solar10.7B6.1GBollama run solar

Note:You should have at least 8 GB of RAM available to run the 7B models, 16 GB to run the 13B models, and 32 GB to run the 33B models.

6. 本地部署Llama 3.1模型

To run and chat with Llama 3.1:

ollama run llama3.1:8b

image-20240814171432310

Start ollama

C:\Users\xyb>ollama serve

image-20241012180127996

List models on your computer

C:\Users\xyb>ollama list
NAME            ID              SIZE    MODIFIED
llama3.1:8b     91ab477bec9d    4.7 GB  8 weeks ago

Show model information

C:\Users\xyb>ollama show llama3.1:8b
  Model
        arch                    llama
        parameters              8.0B
        quantization            Q4_0
        context length          131072
        embedding length        4096

  Parameters
        stop    "<|start_header_id|>"
        stop    "<|end_header_id|>"
        stop    "<|eot_id|>"

  License
        LLAMA 3.1 COMMUNITY LICENSE AGREEMENT
        Llama 3.1 Version Release Date: July 23, 2024

ollama -h

C:\Users\xyb>ollama -h
Large language model runner

Usage:
  ollama [flags]
  ollama [command]

Available Commands:
  serve       Start ollama
  create      Create a model from a Modelfile
  show        Show information for a model
  run         Run a model
  pull        Pull a model from a registry
  push        Push a model to a registry
  list        List models
  ps          List running models
  cp          Copy a model
  rm          Remove a model
  help        Help about any command

Flags:
  -h, --help      help for ollama
  -v, --version   Show version information

Use "ollama [command] --help" for more information about a command.

7. 安装Docker Desktop

在Windows 环境下,安装Docker Desktop。

image-20241012174905791

8. 使用Docker-Compose部署Dify

进入 Dify 源代码的 docker 目录,执行一键启动命令:

cd dify/docker

cp .env.example .env

docker compose up -d

输入过程如下:

C:\dify\docker>docker-compose up  -d
[+] Running 11/11
 ✔ Network docker_default             Created                     0.1s
 ✔ Network docker_ssrf_proxy_network  Created                     0.0s
 ✔ Container docker-web-1             Started                     1.4s
 ✔ Container docker-weaviate-1        Started                     1.2s
 ✔ Container docker-ssrf_proxy-1      Started                     1.9s
 ✔ Container docker-sandbox-1         Started                     1.9s
 ✔ Container docker-redis-1           Started                     1.4s
 ✔ Container docker-db-1              Started                     1.7s
 ✔ Container docker-worker-1          Started                     2.6s
 ✔ Container docker-api-1             Started                     2.8s
 ✔ Container docker-nginx-1           Started                     3.7s

启动完成后,你的 docker 里就会看到这个:

在这里插入图片描述
image-20241012120722598

也可以在Docker-Compose中查看到已启动的容器。

image-20240818150320373

9. 注册Dify账号

打开浏览器,输入http://127.0.0.1

设置管理员账户。输入邮箱、用户名、密码。

image-20241012163648495

填写完成后,点击设置。

image-20240815093239830

跳转至登录揭秘那,输入邮箱和密码完成登录。

image-20240815093327170

至此,我们利用Docker Compose 在Windows本地环境中,完成Dify的搭建部署工作。

image-20240815093356383

10. 集成本地部署的 Llama 3.1模型

  • 点击设置

image-20240815093653323

  • 选择模型提供商Ollama

image-20240815093813927

填写如下参数信息。

!!!注意!!!:模型名称和基础URL要填写正确,否则会添加失败报错。

image-20240818145633535

  • 添加成功。

image-20240818144324916

  • 我们也可以输入以下地址,验证所添加的ollama模型是否已启动。

image-20241012172323267

11. 集成智谱AI大模型

  • 获取智谱 AI API Key

获取链接:智谱AI开放平台

image-20240818145757305

2e0556xxxxxxxxxxxxxxxxxxxxxxxxxxxE6of

image-20241012164255172

image-20241012164336131

image-20241012164440679

12. 添加Dify团队成员

image-20241012164545813

image-20241012164614694

http://127.0.0.1/activate?email=xxxxxxxx@outlook.com&token=34aa37d7-7d9a-4b64-9ed6-d0372380ad7f

image-20241012165623216

image-20241012165659255

13. 导入DSL - 小红书文案生成脚本

  • 导入DSL

image-20241012170623745

  • 小红书文案生成脚本工作流如下:

image-20240815093458359

  • 输入关键字

image-20241012174128200

  • 输出结果

image-20241012174037311

  • 生成内容如下:
标题:
1. 🌟【日常美学】🌼 这样的小确幸,让你幸福感爆棚!🍵📖✨
2. 💖【生活小秘诀】🌸 发现日常中的小美好,幸福感瞬间up!📸
3. 🌿【限量版生活】🌼 每天都是独一无二的美好!🍵📖✨
4. 📖【生活美学】🌸 一本好书,一杯香茗,幸福感满满!💖
5. 🌼【小确幸分享】🍵 这样的小日常,让你心情大好!📸
6. ✨【日常小美好】🌸 发现生活中的小确幸,幸福感飙升!📖
7. 🍵【生活小确幸】🌼 一杯香茗,一束鲜花,幸福感满满!💖
8. 📸【记录美好】🌸 每天都是限量版,用心发现小确幸!✨
9. 💖【生活美学】🌼 这样的小日常,幸福感瞬间up!🍵📖
10. 🌿【小确幸日常】🌸 一本好书,一束鲜花,幸福感爆棚!✨
11. 🌼【日常小秘诀】🍵 发现生活中的小美好,幸福感大增!💖
12. 📖【限量版日常】🌸 每天都是独一无二的美好!📸✨
13. ✨【生活小确幸】🌼 一杯香茗,一本好书,幸福感满满!🍵
14. 🍵【日常美学】🌸 这样的小确幸,让你心情大好!💖
15. 📸【小确幸分享】🌼 发现日常中的小美好,幸福感飙升!📖
16. 💖【记录美好】🌸 每天都是限量版,用心发现小确幸!🌿✨
17. 🌿【生活小美好】🌼 一本好书,一束鲜花,幸福感满满!🍵
18. 🌼【日常小确幸】🍵 这样的小日常,幸福感瞬间up!📸💖
19. 📖【小确幸日常】🌸 发现生活中的小美好,幸福感大增!✨
20. ✨【限量版生活】🌼 每天都是独一无二的美好!🍵📖💖
文案:
🌿🌸【生活小确幸】🍵 每天都是限量版,用心发现生活中的小美好!📖 一杯香茗,🌼 一本好书,简单日常也能闪闪发光✨。分享我的生活小秘诀,幸福感瞬间up up!📸 记录每一刻,生活美学,从心开始💖。你也有这样的小确幸吗?快来评论区分享吧!🌟🌿

#生活美学 #小确幸 #日常分享 #幸福感 #记录美好 #限量版生活

14. 所遇问题

C:\Users\xyb>ollama serve
Error: listen tcp :11434: bind: An attempt was made to access a socket in a way forbidden by its access permissions.

C:\Users\xyb>ollama run llama3.1:8b
Error: could not connect to ollama app, is it running?

需要关闭本地环境中的代理。

An error occurred during credentials validation: HTTPConnectionPool(host='127.0.0.1', port=11434): Max retries exceeded with url: /api/chat (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7eff701373d0>: Failed to establish a new connection: [Errno 111] Connection refused'))

An error occurred during credentials validation: HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/chat (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7eff70136260>: Failed to establish a new connection: [Errno 111] Connection refused'))

填写Ollama模型名称和基础URL信息有误导致的。

image-20240815115529322

image-20240815115533417

An error occurred during credentials validation: API request failed with status code 404: {"error":"model \"Llama 3.1\" not found, try pulling it first"}

image-20240818132217486

15. 参考链接

1️⃣https://mp.weixin.qq.com/s/jAX7uI_gjV4e7nzgb_rkrQ

2️⃣https://github.com/langgenius/dify

3️⃣Windows preview · Ollama Blog

4️⃣llama3.1:8b

5️⃣Download Ollama on Windows

6️⃣ollama/ollama: Get up and running with Llama 3.1, Mistral, Gemma 2, and other large language models.

Dify 教程二:使用本地大模型 | Coder 小站 (ihsxu.com)

github.com/langgenius/dify)

3️⃣Windows preview · Ollama Blog

4️⃣llama3.1:8b

5️⃣Download Ollama on Windows

6️⃣ollama/ollama: Get up and running with Llama 3.1, Mistral, Gemma 2, and other large language models.

在JAVA环境下开发基于Llama 2模型的聊天机器人,首先需要确保你熟悉JAVA编程语言,特别是其面向对象的概念以及网络和多线程处理的能力。Llama 2模型可以作为机器人的核心NLP引擎,通过JAVA调用相应的API或者服务来实现语言理解功能。 参考资源链接:[Llama 2开源模型AI聊天机器人:Organic LlamaBot](https://wenku.csdn.net/doc/uqdvgdm6hx) 技术实现步骤可以分为以下几个关键部分: 1. 环境搭建:首先需要设置好JAVA开发环境,如安装JDK和配置环境变量。接着,创建一个新的JAVA项目,并配置相关的构建工具如Maven或Gradle。 2. Llama 2模型集成:你需要下载Llama 2的源代码或构建好的模型文件,并在JAVA项目中加载它。如果Llama 2提供了API接口或SDK,可以直接通过网络请求与模型进行交互。 3. 接口设计:设计一个用户接口,可以是命令行界面,也可以是图形用户界面(GUI),甚至是一个Web服务。这个接口负责接收用户的输入,并将处理后的请求发送给Llama 2模型。 4. 消息处理:实现一个消息处理机制,它将用户输入进行预处理(如分词、去停用词等),然后将处理后的内容传给Llama 2模型进行语言理解和生成响应。 5. 响应生成:从Llama 2模型获取到响应后,需要将其格式化和适配成用户界面上的输出格式。 6. 测试与优化:对聊天机器人进行测试,确保其可以正确理解和响应各种输入。根据测试结果,对聊天机器人进行调优和功能扩展。 7. 用户界面开发:根据需求开发简洁且直观的用户界面,确保用户能够方便地与机器人交流。 通过上述步骤,你将能够构建一个基础的人工智能聊天机器人。当然,为了更好地理解和掌握JAVA语言与Llama 2开源模型的结合使用,推荐你参考《Llama 2开源模型AI聊天机器人:Organic LlamaBot》一书。该书不仅涉及理论知识,还包括实践案例和代码实现,能够帮助开发者深入理解整个开发过程。 在学习和实践了上述基本框架后,如果你希望进一步提升你的聊天机器人项目,可以探索更多开源项目和资源,如GreenGrowthAI-Llama-ChatBot-main,它可能提供了额外的模块和功能,助力你在Llama 2的基础上创建更加丰富的交互体验。 参考资源链接:[Llama 2开源模型AI聊天机器人:Organic LlamaBot](https://wenku.csdn.net/doc/uqdvgdm6hx)
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云矩阵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值