You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用LangChain调用Ollama的Llama3时出现404错误求助

LangChain调用Ollama Llama3出现404错误

错误信息

langchain_community.llms.ollama.OllamaEndpointNotFoundError: Ollama call failed with status code 404. Maybe your model is not found and you should pull the model with `ollama pull llama3`.

环境与背景

  • 运行系统:MacOS
  • 调用代码:
from langchain_community.llms import Ollama

llm = Ollama(model="llama3", base_url="http://localhost:11434/")
llm.invoke("Why is the sky blue?")
  • 已尝试ollama serve启动服务,无效
  • 确认Ollama服务在localhost:11434正常运行
  • 访问localhost:11434/llama3返回404
  • ollama list显示Llama3已安装

解决方案

1. 核对模型完整名称

运行ollama list查看已安装模型的完整标识,比如实际可能是llama3:8b或llama3:70b,而非单纯的llama3。修改代码中的model参数为完整名称:

llm = Ollama(model="llama3:8b", base_url="http://localhost:11434")

2. 修正base_url格式

移除base_url末尾的斜杠,Ollama API路径不需要该后缀:

llm = Ollama(model="llama3", base_url="http://localhost:11434")

3. 直接验证Ollama API可用性

用curl测试模型是否能正常响应,替换为你的完整模型名:

curl http://localhost:11434/api/generate -d '{
  "model": "llama3:8b",
  "prompt": "Why is the sky blue?",
  "stream": false
}'

如果返回正常结果,说明模型本身无问题,问题出在LangChain的配置。

4. 重启Ollama服务

停止当前服务后重新启动:

pkill ollama
ollama serve

5. 更新依赖版本

确保LangChain相关包和Ollama模型为最新版:

pip install --upgrade langchain langchain-community
ollama pull llama3

内容的提问来源于stack exchange,提问作者Parvez Shah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 17:52:05