Skip to content

Commit dfdeb7c

Browse files
bplunkertBen Plunkertmxyng
authored
Add URL path to client URL in in Client._parse_host() (#170)
* 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]>
1 parent 8b694bb commit dfdeb7c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

ollama/_client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,14 @@ def _parse_host(host: Optional[str]) -> str:
987987
'http://example.com:11434'
988988
>>> _parse_host('example.com:56789/')
989989
'http://example.com:56789'
990+
>>> _parse_host('example.com/path')
991+
'http://example.com:11434/path'
992+
>>> _parse_host('example.com:56789/path')
993+
'http://example.com:56789/path'
994+
>>> _parse_host('https://example.com:56789/path')
995+
'https://example.com:56789/path'
996+
>>> _parse_host('example.com:56789/path/')
997+
'http://example.com:56789/path'
990998
"""
991999

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

1013+
if path := split.path.strip('/'):
1014+
return f'{scheme}://{host}:{port}/{path}'
1015+
10051016
return f'{scheme}://{host}:{port}'

0 commit comments

Comments
 (0)