https://ollama.com/ 下载安装 可以安装各种大模型 安装 ollama run deepseek-r1:7b 提问 1+2+3 一直加到50等于多少 python 调用当前大模型 安装 langchain-ollama uv add langchain-ollama from langchain_core.prompts import C…

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


安装
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="")