From b232a6c04d1eef82a86af70ed98c02e90e9c7a8c Mon Sep 17 00:00:00 2001 From: Bruce MacDonald Date: Fri, 12 Jan 2024 10:48:59 -0500 Subject: [PATCH 1/2] fix: remote create new file --- ollama/_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ollama/_client.py b/ollama/_client.py index 14608ba..91dcbf7 100644 --- a/ollama/_client.py +++ b/ollama/_client.py @@ -262,7 +262,7 @@ def _parse_modelfile(self, modelfile: str, base: Optional[Path] = None) -> str: for line in io.StringIO(modelfile): command, _, args = line.partition(' ') if command.upper() in ['FROM', 'ADAPTER']: - path = Path(args).expanduser() + path = Path(args.strip()).expanduser() path = path if path.is_absolute() else base / path if path.exists(): args = f'@{self._create_blob(path)}' @@ -288,7 +288,7 @@ def _create_blob(self, path: Union[str, Path]) -> str: raise with open(path, 'rb') as r: - self._request('PUT', f'/api/blobs/{digest}', content=r) + self._request('POST', f'/api/blobs/{digest}', content=r) return digest From e3733a235db9181d35c2c4be1a13f641d57a3cf9 Mon Sep 17 00:00:00 2001 From: Bruce MacDonald Date: Fri, 12 Jan 2024 11:03:40 -0500 Subject: [PATCH 2/2] fix tests --- ollama/_client.py | 2 +- tests/test_client.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ollama/_client.py b/ollama/_client.py index 91dcbf7..5b8b703 100644 --- a/ollama/_client.py +++ b/ollama/_client.py @@ -563,7 +563,7 @@ async def upload_bytes(): break yield chunk - await self._request('PUT', f'/api/blobs/{digest}', content=upload_bytes()) + await self._request('POST', f'/api/blobs/{digest}', content=upload_bytes()) return digest diff --git a/tests/test_client.py b/tests/test_client.py index 3b8ce8b..2f6c8c1 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -418,7 +418,7 @@ def test_client_create_from_library(httpserver: HTTPServer): def test_client_create_blob(httpserver: HTTPServer): httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='HEAD').respond_with_response(Response(status=404)) - httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='PUT').respond_with_response(Response(status=201)) + httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='POST').respond_with_response(Response(status=201)) client = Client(httpserver.url_for('/')) @@ -759,7 +759,7 @@ async def test_async_client_create_from_library(httpserver: HTTPServer): @pytest.mark.asyncio async def test_async_client_create_blob(httpserver: HTTPServer): httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='HEAD').respond_with_response(Response(status=404)) - httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='PUT').respond_with_response(Response(status=201)) + httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='POST').respond_with_response(Response(status=201)) client = AsyncClient(httpserver.url_for('/'))