自学内容网 自学内容网

利用 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.


原文地址:https://blog.csdn.net/qq_45392321/article/details/142891003

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!