(二)langchain 调用本地seepseek大模型

直接上 代码

python 复制代码
# 01-hello-ollama.py
from langchain.chat_models import init_chat_model
model=init_chat_model(
    model="ollama:deepseek-r1:1.5b",
    base_url="http://localhost:11434",
    temperature=0.1,
    timeout=30,
    max_tokens=2000
)

for chunk in model.stream("你好你谁"):
    print(chunk.content,end='',flush=True)

(langchain1.0) D:\IDO\mylangchain1.0>python 01-hello-ollama.py

遇到问题:

"C:\Users\Administrator\.conda\envs\langchain1.0\Lib\site-packages\ollama\_client.py", line 179, in inner raise ResponseError(e.response.text, e.response.status_code) from None ollama._types.ResponseError: (status code: 502) (langchain1.0) D:\IDO\mylangchain1.0>

报错502给我苦恼的要死,各种改ollama段端口。

解决问题思路。

1.确定ollama run deepseek-r1:1.5b 能跑起来。如果跑不起来是不是模型没有下载

2.ollama serve 重启ollama serve看到这个界面就代码ollama 服务器启动成功

3.然后重新开启一个prompt窗口 进入工程目录 激活运行环境 运行python 01-hello-ollama.py

(我的还是报502)

我又是改端口,又是改防火墙,最后发现是vpn的事情。我把vpn关了,重启服务就好了,要命了啊!!!!

相关推荐
扯蛋4382 小时前
1.x 时代的记忆系统 (一)
langchain·llm·aigc
梦想三三5 小时前
LangChain RAG PDF 智能问答实战:用 Streamlit 构建本地知识库(完整代码)
人工智能·python·langchain·大模型·rag
ganjiee00077 小时前
langchain.messages引用报错
langchain
大模型真好玩9 小时前
LangChain DeepAgents 速通指南(十二)——一文详解生产级智能体的命令体系和工程设计
人工智能·langchain·agent
用户3126874877209 小时前
AI Agent 开发实战(十):Agent 设计模式(ReAct / Plan-Execute / Reflection)
langchain
鱼饼Y9 小时前
AI时代,使用大模型学习LangChain (4)——LangGraph
typescript·langchain
吃饱了得干活9 小时前
Agent 记忆系统:从短期记忆到长期记忆
python·langchain·agent
知行合一。。。11 小时前
LangChain--11--Milvus
langchain·milvus
流浪00112 小时前
LLM 大模型三种主流接入方式详解(API / 本地部署 / SDK)
langchain·llm
二进制_博客1 天前
LangSmith 调试
langchain·langsmith