ollama / ollama-python

Ollama Python library
https://ollama.com
MIT License
2.69k stars 221 forks source link

Client fails to query resources behind reverse proxy path #113

Open jpsullivan opened 2 months ago

jpsullivan commented 2 months ago

The _parse_host method seems to be stripping off the end of URLs that Ollama may be proxied behind. For example, if I have a rule setup in Caddy/Nginx ro forward Ollama to http://localhost:8080/ollama, the client returns "http://localhost:8080", which causes all API requests to fail as the URL is technically invalid.

DJ4ddi commented 2 months ago

Quick fix: Open _client.py and replace the last line with:


  path = split.path or ''

  return f'{scheme}://{host}:{port}{path}'
trollkarlen commented 1 month ago

Is there a fix for this in the pipe ?

Also headers for auth and more in a proxy framework would be nice to add.

bplunkert commented 1 month ago

@trollkarlen I've opened up #170 following the suggestion by @DJ4ddi. I've tested and can confirm this seems to resolve the issue for me.

You can test it out in requirements.txt:

ollama @ git+https://github.com/inferret/ollama-python.git@add_url_path
kttalley commented 22 hours ago

I believe I'm facing this same exact issue with my Windows 10 Apache server. It'd be great to get this fix for folks running multiple services from one server/domain, or for those wanting to isolate ollama to a specific sub-domain instead of dedicating the root.