如何本地部署 deepseek 请参考(windows 部署安装 大模型 DeepSeek-R1)
那么实际使用中需要开启API模式,这样可以无拘无束地通过API集成的方式,集成到各种第三方系统和应用当中。
上遍文章是基于Ollama框架运行了deepSeek R1模型,ollama相当于一个代理,我们直接调用ollama的API即可实现大模型接口的调用。
OpenAI的接口调用
from openai import OpenAI
client = OpenAI(
base_url='http://localhost:11434/v1/',
api_key='ollama',
)
chat_completion = client.chat.completions.create(
messages=[
{
'role': 'user',
'content': '土拨鼠原产地',
}
],
model='deepseek-r1:1.5b',
# stream=True,
temperature=0.0,
)
print(chat_completion)
输出:
使用ollama简易API调用
from ollama import chat
from ollama import ChatResponse
response: ChatResponse = chat(model='deepseek-r1:1.5b', messages=[
{
'role': 'user',
'content': '土拨鼠原产地',
},
])
print(response['message']['content'])
# or access fields directly from the response object
print(response.message.content)
输出: