解决问题HTTPConnectionPool(host=‘127.0.0.1‘, port=11434): Max retries exceeded with url: /api/

解决Dfiy配置时出现 An error occurred during credentials validation: HTTPConnectionPool(host='127.0.0.1', port=11434): Max retries exceeded with url: /api/generate (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f851f9bcda0>: Failed to establish a new connection: [Errno 111] Connection refused'))问题.

主要原因:http://127.0.0.1:11434地址为该DOCker自身的回环地址,相当于DOCker自身的IP。

http://host.docker.internal:11434 地址为从DOCker内访问宿主机服务,Dify随通过浏览器,但是Dify在DOCker内部运行,但是OLLAMA没有在DOCker内部,OLLAMA在宿主机,添加OLLAMA相当于DOCker访宿主机程序,即DOCker访问宿主机上的模型服务OLLAMA,因此需要用http://host.docker.internal:11434或者http://自身电脑ip:11434.

当Dfiy配置添加Ollama时,基础URL填写http://127.0.0.1:11434

此时保存出现问题右侧问题:

An error occurred during credentials validation: HTTPConnectionPool(host='127.0.0.1', port=11434): Max retries exceeded with url: /api/chat (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f851f9bd220>: Failed to establish a new connection: [Errno 111] Connection refused'))

http://127.0.0.1:11434 修改为 http://host.docker.internal:11434 即可。

主要原因:http://127.0.0.1:11434地址为该DOCker自身的回环地址,相当于DOCker自身的IP。

http://host.docker.internal:11434 地址为从DOCker内访问宿主机服务,Dify随通过浏览器,但是Dify在DOCker内部运行,但是OLLAMA没有在DOCker内部,OLLAMA在宿主机,添加OLLAMA相当于DOCker访宿主机程序,即DOCker访问宿主机上的模型服务OLLAMA,因此需要用http://host.docker.internal:11434或者http://自身电脑ip:11434.