Skip to content

Commit

Permalink
Merge pull request #8 from jmorganca/brucemacd/remote-create
Browse files Browse the repository at this point in the history
fix: remote create new file
  • Loading branch information
mxyng authored Jan 12, 2024
2 parents e0ee198 + e3733a2 commit fc60bd7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions ollama/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}'
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('/'))

Expand Down Expand Up @@ -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('/'))

Expand Down

0 comments on commit fc60bd7

Please sign in to comment.