Mac 安装Ollama和llama3,本地部署LobeChat和刘皇叔聊三国

Ollama安装

下载Ollama

网址:https://ollama.com/
支持macOS、Linux和Windows多个平台

Ollama常用指令和链接

1. 常用指令

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
  cp          Copy a model
  rm          Remove a model
  help        Help about any command

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

2. 链接
Blog:https://ollama.com/blog
Docs:https://github.com/ollama/ollama/tree/main/docs
GitHub:https://github.com/ollama/ollama
模型仓库https://ollama.com/library

运行Ollama

以Llama 3为例

ollama run llama3

自动安装latest的版本是8B 4-bit模型,信息如下:

如果是70B模型,可以参考
仓库中Llama 3的介绍:https://ollama.com/library/llama3

运行之后,项目默认监听 11434 端口,终端查看

curl localhost:11434

输出:

Ollama is running

运行成功,可以在终端聊天了.

API 交互Ollama

按下 Ctrl + D 可以退出终端交互,但此时模型并不会退出,仍旧可以正常通过 Api 接口交互。
具体可以参考官网api文档:https://github.com/ollama/ollama/blob/main/docs/api.md

简单api交互例子,新打开一个终端,输入

curl http://localhost:11434/api/generate -d '{
    
    
  "model": "llama3",
  "prompt": "Why is the sky blue?",
  "stream": false
}'

退出可以从电脑右上角退出

基于Llama 3角色扮演

在任意目录下建一个modelfile文件。具体信息查看官网modelfile文档:
https://github.com/ollama/ollama/blob/main/docs/modelfile.md

modelfile文件:

FROM llama3

# set the temperature to 1 [higher is more creative, lower is more coherent]
PARAMETER temperature 1

# set the system message
SYSTEM """
You are Liu Bei from the Three Kingdoms period in China. Answer as Liu Bei, the assistant, only used Simplified Chinese.
"""

创建刘备的个人聊天助手,新的模型我命名为Czi

ollama create Czi -f ./Modelfile

查看模型:

ollama ls

运行Czi模型

ollama run Czi

这样就可以啦!
接下里是本地部署LobeChat,实现网页的交互

LobeChat安装

首先安装docker

这里跳过了。。。

安装LobeChat的docker 镜像和运行

LobeChat的帮助文档与 Ollama 集成

一行代码:

docker run -d -p 3210:3210 -e OLLAMA_PROXY_URL=http://host.docker.internal:11434/v1 lobehub/lobe-chat

可以看到LobeChat运行在本地3210端口,浏览器打开http://localhost:3210

这样就可以交互了!

默认的LobeChat没有Czi模型,我们需要添加一下~

LobeChat的帮助文档在 LobeChat 中使用 Ollama

在 设置 -> 语言模型 中找到 Ollama 的配置选项

配置好了,可以跟刘皇叔在LobeChat中聊天啦!

猜你喜欢

转载自blog.csdn.net/weixin_46460463/article/details/138006321