Skip to content

Commit

Permalink
Add URL path to client URL in in Client._parse_host() (#170)
Browse files Browse the repository at this point in the history
* Add URL path to client URL in in Client._parse_host()

* add tests for url path

* improve URL path handling

* restore trailing space

* remove extraneous path assignment

* Fix url path test

Co-authored-by: Michael Yang <[email protected]>

---------

Co-authored-by: Ben Plunkert <[email protected]>
Co-authored-by: Michael Yang <[email protected]>
  • Loading branch information
3 people authored Aug 23, 2024
1 parent 8b694bb commit dfdeb7c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ollama/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,14 @@ def _parse_host(host: Optional[str]) -> str:
'http://example.com:11434'
>>> _parse_host('example.com:56789/')
'http://example.com:56789'
>>> _parse_host('example.com/path')
'http://example.com:11434/path'
>>> _parse_host('example.com:56789/path')
'http://example.com:56789/path'
>>> _parse_host('https://example.com:56789/path')
'https://example.com:56789/path'
>>> _parse_host('example.com:56789/path/')
'http://example.com:56789/path'
"""

host, port = host or '', 11434
Expand All @@ -1002,4 +1010,7 @@ def _parse_host(host: Optional[str]) -> str:
host = split.hostname or '127.0.0.1'
port = split.port or port

if path := split.path.strip('/'):
return f'{scheme}://{host}:{port}/{path}'

return f'{scheme}://{host}:{port}'

0 comments on commit dfdeb7c

Please sign in to comment.