一、拉取并运行模型

ollama run llama3.1

二、查看目前ollama已下载的模型

ollama list

三、展示模型信息

ollama show qwen2:0.5b

四、删除模型

ollama rm qwen2:0.5b

五、服务启动

# 服务启动
ollama serve
# 如果如果有异常,说端口冲突,(1)杀掉11434端口的进程。(2)修改ollama的服务监听端口。
set OLLAMA_HOST=127.0.0.1:11436  # 修改服务监听端口

六、服务使用

# curl使用
curl http://localhost:11434/api/generate -d "{ \"model\": \"qwen2:0.5b\", \"prompt\": \"Why is the sky blue?\" }"
# OpenAi使用
from openai import OpenAI

client = OpenAI(
    base_url = 'http://127.0.0.1:11436/v1',
    api_key='ollama', # required, but unused
)

response = client.chat.completions.create(
  model="llama3.1",
  messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Who won the world series in 2020?"},
    {"role": "assistant", "content": "The LA Dodgers won in 2020."},
    {"role": "user", "content": "Where was it played?"}
  ]
)
print(response.choices[0].message.content)
# ollama使用
import ollama
response = ollama.chat(model='llama3.1', messages=[
  {
    'role': 'user',
    'content': 'Why is the sky blue?',
  },
])
print(response['message']['content'])
Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐