ollama qwen2 运行&openai 兼容api 测试

qwen2 模型已经发布了,各种新闻都说很不错,所以通过ollama 测试下

安装ollama

  • cli
curl -fsSL https://ollama.com/install.sh | sh
  • 启动服务
ollama serve

拉取qwen2:1.5b 模型

使用了api 模式

  • cli
curl -X POST http://localhost:11434/api/pull -d '{"model":"qwen2:1.5b"}'

openai api 访问

  • 使用了python sdk
from openai import OpenAI
 
client = OpenAI(
    base_url = 'http://localhost:11434/v1/',
    api_key='ollama', # required, but unused
)
 
response = client.chat.completions.create(
  model="qwen2:1.5b",
  messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "你是谁"},
    {"role": "user", "content": "今天是星期几?"}
  ]
)
print(response.choices[0].message.content)
  • 效果

说明

目前ollama 似乎对于模型加载有点问题,在测试llama3 的时候有问题,github 上也有类似的issue,所以对于qwen2的我也使用了api 模式拉取,目前qwen2 模型的能力以及速度目前看着还真不错,值得学习下

参考资料

https://ollama.com/library/qwen2:1.5b
https://github.com/ollama/ollama/releases/tag/v0.1.42
https://github.com/ollama/ollama/blob/main/README.md#quickstart

posted on   荣锋亮  阅读(2876)  评论(5编辑  收藏  举报

相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· spring官宣接入deepseek,真的太香了~
历史上的今天:
2023-06-10 nginx-clojure-0.6.0 集成nginx 1.25.0 构建的解决方法
2023-06-10 nginx-clojure 源码构建一些问题
2023-06-10 nginx-clojure 0.6.0 的一些新特性
2020-06-10 使用openresty+empty_gif 进行请求数据分析
2020-06-10 使用lua-resty-repl 调试openresty
2020-06-10 supervisord golang 实现试用
2020-06-10 Prisma 2.0 ga

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示