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)
相关推荐
问简9 分钟前
Windows11自定义分区大小安装系统
windows
sukalot3 小时前
windows 驱动实例分析系列: HidHide驱动分析-HidHideClient 篇(中)
windows·驱动开发
我是Superman丶15 小时前
Arduino IDE 安装教程:Windows/macOS/Linux 开发环境搭建
ide·windows·macos
辻弋20115 小时前
自动检测硬件生成驱动清单、实时监控FPS、120秒性能记录——30+项优化模块化开关,所有改动可精确复原
服务器·windows·游戏引擎·电脑·开源软件
江湖人称菠萝包15 小时前
【Windows】《深入浅出Windows API程序设计:编程基础篇》笔记-Chapter8-子窗口控件
windows·笔记
其实防守也摸鱼17 小时前
OpenClaw Windows 踩坑实战指南
运维·服务器·数据库·windows·github·copilot
佳&弥1 天前
后渗透痕迹清理
服务器·windows·web安全·网络安全
MSTcheng.1 天前
【Linux学习】Linux学习第四弹——Linux基本指令3
linux·windows·学习·操作系统·指令
霸道流氓气质1 天前
MyBatis 与 SQL 层面关键技术详解
windows·sql·mybatis
一直走下去-明1 天前
在 Windows 上安装 uv
windows·uv