AI agent 大模型实战之 本地部署及调用大模型ollama
AI

下载安装
可以安装各种大模型


安装
ollama run deepseek-r1:7b提问 1+2+3 一直加到50等于多少

python 调用当前大模型
安装 langchain-ollama
uv add langchain-ollama
from langchain_core.prompts import ChatPromptTemplate
from langchain_ollama.llms import OllamaLLM
template = """Question: {question}
Answer: Let's think step by step."""
prompt = ChatPromptTemplate.from_template(template)
model = OllamaLLM(model="deepseek-r1:7b")
chain = prompt | model
resp = chain.invoke({"question": "你是谁?"})
print(resp)
# 流式打印
resp = chain.stream({"question": "你是谁?"})
for chunk in resp:
print(chunk,end="")
![[衡天云]爆款云服务器 低至12元/月](/hty.png)