Ollama入门(windows版本)

一、简介

通过简单的安装指令,可以让用户执行一条命令就在本地运行开源大型语言模型,如gemma。

二、安装方式

1、访问官网,点击【Download】进行下载https://ollama.com/

2、目前支持Linux、Mac和windows

3、github链接:https://github.com/ollama/ollama

三、下载并运行模型(命令行方式)

1、点击【View logs】进入ollama目录

2、运行gemma:2b模型(如未下载,会自动下载)

3、提问

bash 复制代码
ollama run gemma:2b



四、webapi方式运行

1、webapi方式运行

bash 复制代码
./ollama serve

2、如需指定端口,可在环境变量中进行配置

3、安装openai工具包

bash 复制代码
pip install openai

4、openai格式调用ollama部署的接口

python 复制代码
import openai
# 设置api_base
openai.api_key = "111" #不可为空,为空会报错
openai.api_base = "http://127.0.0.1:8000/v1"
# 2. 设置提示词
prompt = """
你是谁?

"""

# 3.调用(可切换模型)
# resp = openai.ChatCompletion.create(model="llama2", messages=[{"role": "user", "content": prompt}], stream = False)
resp = openai.ChatCompletion.create(model="llama2-chinese", messages=[{"role": "user", "content": prompt}], stream = False)
# resp = openai.ChatCompletion.create(model="gemma:7b", messages=[{"role": "user", "content": prompt}], stream = False)

# 4.输出
print(resp.choices[0].message.content)
相关推荐
万年咸鱼7 小时前
Qt Windows 使用管理员权限运行 Cmd
windows
2601_9623649711 小时前
从录入到解锁,完整梳理 Windows Hello 识别链路
windows·安全·电脑
hacker_LeeFei12 小时前
Windows 下配置 Redis 8.10.2 开机自启:一次踩坑全记录
数据库·windows·redis
赵文宇(温玉)13 小时前
怎么下载 Windows 的 ISO 系统镜像
windows
2601_9621773015 小时前
Windows 安装 Codex CLI 入门级教程
人工智能·windows·node.js·ai编程
shada18 小时前
CMake指定 MSVC 工具集与 Windows SDK
c++·windows
the3clipse18 小时前
Windows 10 与 Windows 11 视频编解码区别:AV1、HEVC、HDR 与 D3D12 编码支持对比
windows·h.265·hevc·hdr·av1·视频解码·d3d12
郭庆汝18 小时前
(三)MCP+A2A 从0到1构建类Manus多Agent全栈应用
windows
the3clipse18 小时前
MacOS、Linux 与 Windows 视频编解码对比:AV1、HEVC、ProRes 与硬件加速优劣势
linux·windows·macos·hevc·av1·视频解码·硬件解码
明王明王19 小时前
PVE 上用 SPICE:统一连接 Debian、Arch 和 Windows 11 桌面
运维·windows·debian