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 2024-06-10 08:24  荣锋亮  阅读(868)  评论(0编辑  收藏  举报

导航