Ollama 本地部署大模型 | Windows本地部署 Llama3.1 大模型

Get up and running with large language models.
Run Llama 3.1, Phi 3, Mistral, Gemma 2, and other models. Customize and create your own.

Ollama是做什么的?

Ollama是一个开源的大型语言模型部署工具,它可以帮助用户快速在本地部署运行大模型。类似于Docker一样,仅仅用几行命令就可以运行一个大模型。

官方地址:Ollama

github:GitHub - ollama/ollama: Get up and running with Llama 3, Mistral, Gemma 2, and other large language

如何安装Ollama

官网直接下载安装:Download Ollama

在这里插入图片描述

配置Ollama模型文件地址

由于Ollama在下载模型时,会自动下载到C盘,因此需要设置下载目录。方法如下:

在环境变量中添加“OLLAMA_MODELS”,之后重启ollama,我把下载模型的目录设置在了"D:\ollama"目录下。

在这里插入图片描述

Ollama使用帮助

ollama -h 

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

在这里插入图片描述

需要重点注意的几个指令:

# 启动服务
ollama serve

# 拉模型
ollama pull llama3.1

# 部署模型
ollama run llama3.1

# 运行的模型列表
ollama list

# 模型删除
ollama rm llama3.1

Ollama部署大模型(llama3.1为例)

在安装模型之前需要到模型仓库中获取模型信息。

  • 模型仓库地址 library
    在这里插入图片描述

  • 选择需要的模型

在这里插入图片描述

  • 执行模型运行指令,如果本地没用模型镜像,ollama会先拉模型镜像,然后在进行启动运行。
    在这里插入图片描述
    在这里插入图片描述

使用API访问模型

Ollama有一套用于运行和管理模型的 REST API。

Generate a response

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

Chat with a model

curl http://localhost:11434/api/chat -d '{
  "model": "llama3.1",
  "messages": [
    { "role": "user", "content": "why is the sky blue?" }
  ]
}'

更多API可以参考:API documentation

curl http://localhost:11434/api/chat -d '{
  "model": "llama3.1",
  "messages": [
    { 
        "role": "user", 
        "content": "hello~" 
    }
  ]
}'

在这里插入图片描述

这样就基本完成了Ollama在本地部署大模型。

剩下的就是通过三方工具开发自己的大模型应用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

静愚 AGI

你的善意终将流回自己,加油!

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

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

打赏作者

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

抵扣说明:

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

余额充值