mirror of
https://github.com/ollama/ollama-python.git
synced 2026-01-13 21:57:16 +08:00
Merge pull request #277 from ollama/mxyng/no-head
no head request for create blob
This commit is contained in:
commit
dc38fe4675
@ -528,14 +528,8 @@ class Client(BaseClient):
|
|||||||
|
|
||||||
digest = f'sha256:{sha256sum.hexdigest()}'
|
digest = f'sha256:{sha256sum.hexdigest()}'
|
||||||
|
|
||||||
try:
|
with open(path, 'rb') as r:
|
||||||
self._request_raw('HEAD', f'/api/blobs/{digest}')
|
self._request_raw('POST', f'/api/blobs/sha256:{digest}', content=r)
|
||||||
except ResponseError as e:
|
|
||||||
if e.status_code != 404:
|
|
||||||
raise
|
|
||||||
|
|
||||||
with open(path, 'rb') as r:
|
|
||||||
self._request_raw('POST', f'/api/blobs/{digest}', content=r)
|
|
||||||
|
|
||||||
return digest
|
return digest
|
||||||
|
|
||||||
@ -1012,21 +1006,15 @@ class AsyncClient(BaseClient):
|
|||||||
|
|
||||||
digest = f'sha256:{sha256sum.hexdigest()}'
|
digest = f'sha256:{sha256sum.hexdigest()}'
|
||||||
|
|
||||||
try:
|
async def upload_bytes():
|
||||||
await self._request_raw('HEAD', f'/api/blobs/{digest}')
|
with open(path, 'rb') as r:
|
||||||
except ResponseError as e:
|
while True:
|
||||||
if e.status_code != 404:
|
chunk = r.read(32 * 1024)
|
||||||
raise
|
if not chunk:
|
||||||
|
break
|
||||||
|
yield chunk
|
||||||
|
|
||||||
async def upload_bytes():
|
await self._request_raw('POST', f'/api/blobs/{digest}', content=upload_bytes())
|
||||||
with open(path, 'rb') as r:
|
|
||||||
while True:
|
|
||||||
chunk = r.read(32 * 1024)
|
|
||||||
if not chunk:
|
|
||||||
break
|
|
||||||
yield chunk
|
|
||||||
|
|
||||||
await self._request_raw('POST', f'/api/blobs/{digest}', content=upload_bytes())
|
|
||||||
|
|
||||||
return digest
|
return digest
|
||||||
|
|
||||||
|
|||||||
@ -293,7 +293,7 @@ def test_client_push_stream(httpserver: HTTPServer):
|
|||||||
|
|
||||||
|
|
||||||
def test_client_create_path(httpserver: HTTPServer):
|
def test_client_create_path(httpserver: HTTPServer):
|
||||||
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='HEAD').respond_with_response(Response(status=200))
|
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='POST').respond_with_response(Response(status=200))
|
||||||
httpserver.expect_ordered_request(
|
httpserver.expect_ordered_request(
|
||||||
'/api/create',
|
'/api/create',
|
||||||
method='POST',
|
method='POST',
|
||||||
@ -316,7 +316,7 @@ def test_client_create_path(httpserver: HTTPServer):
|
|||||||
|
|
||||||
|
|
||||||
def test_client_create_path_relative(httpserver: HTTPServer):
|
def test_client_create_path_relative(httpserver: HTTPServer):
|
||||||
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='HEAD').respond_with_response(Response(status=200))
|
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='POST').respond_with_response(Response(status=200))
|
||||||
httpserver.expect_ordered_request(
|
httpserver.expect_ordered_request(
|
||||||
'/api/create',
|
'/api/create',
|
||||||
method='POST',
|
method='POST',
|
||||||
@ -348,7 +348,7 @@ def userhomedir():
|
|||||||
|
|
||||||
|
|
||||||
def test_client_create_path_user_home(httpserver: HTTPServer, userhomedir):
|
def test_client_create_path_user_home(httpserver: HTTPServer, userhomedir):
|
||||||
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='HEAD').respond_with_response(Response(status=200))
|
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='POST').respond_with_response(Response(status=200))
|
||||||
httpserver.expect_ordered_request(
|
httpserver.expect_ordered_request(
|
||||||
'/api/create',
|
'/api/create',
|
||||||
method='POST',
|
method='POST',
|
||||||
@ -371,7 +371,7 @@ def test_client_create_path_user_home(httpserver: HTTPServer, userhomedir):
|
|||||||
|
|
||||||
|
|
||||||
def test_client_create_modelfile(httpserver: HTTPServer):
|
def test_client_create_modelfile(httpserver: HTTPServer):
|
||||||
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='HEAD').respond_with_response(Response(status=200))
|
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='POST').respond_with_response(Response(status=200))
|
||||||
httpserver.expect_ordered_request(
|
httpserver.expect_ordered_request(
|
||||||
'/api/create',
|
'/api/create',
|
||||||
method='POST',
|
method='POST',
|
||||||
@ -390,7 +390,7 @@ def test_client_create_modelfile(httpserver: HTTPServer):
|
|||||||
|
|
||||||
|
|
||||||
def test_client_create_modelfile_roundtrip(httpserver: HTTPServer):
|
def test_client_create_modelfile_roundtrip(httpserver: HTTPServer):
|
||||||
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='HEAD').respond_with_response(Response(status=200))
|
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='POST').respond_with_response(Response(status=200))
|
||||||
httpserver.expect_ordered_request(
|
httpserver.expect_ordered_request(
|
||||||
'/api/create',
|
'/api/create',
|
||||||
method='POST',
|
method='POST',
|
||||||
@ -455,7 +455,6 @@ def test_client_create_from_library(httpserver: HTTPServer):
|
|||||||
|
|
||||||
|
|
||||||
def test_client_create_blob(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='POST').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('/'))
|
client = Client(httpserver.url_for('/'))
|
||||||
@ -466,7 +465,7 @@ def test_client_create_blob(httpserver: HTTPServer):
|
|||||||
|
|
||||||
|
|
||||||
def test_client_create_blob_exists(httpserver: HTTPServer):
|
def test_client_create_blob_exists(httpserver: HTTPServer):
|
||||||
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='HEAD').respond_with_response(Response(status=200))
|
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='POST').respond_with_response(Response(status=200))
|
||||||
|
|
||||||
client = Client(httpserver.url_for('/'))
|
client = Client(httpserver.url_for('/'))
|
||||||
|
|
||||||
@ -774,7 +773,7 @@ async def test_async_client_push_stream(httpserver: HTTPServer):
|
|||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_async_client_create_path(httpserver: HTTPServer):
|
async def test_async_client_create_path(httpserver: HTTPServer):
|
||||||
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='HEAD').respond_with_response(Response(status=200))
|
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='POST').respond_with_response(Response(status=200))
|
||||||
httpserver.expect_ordered_request(
|
httpserver.expect_ordered_request(
|
||||||
'/api/create',
|
'/api/create',
|
||||||
method='POST',
|
method='POST',
|
||||||
@ -798,7 +797,7 @@ async def test_async_client_create_path(httpserver: HTTPServer):
|
|||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_async_client_create_path_relative(httpserver: HTTPServer):
|
async def test_async_client_create_path_relative(httpserver: HTTPServer):
|
||||||
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='HEAD').respond_with_response(Response(status=200))
|
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='POST').respond_with_response(Response(status=200))
|
||||||
httpserver.expect_ordered_request(
|
httpserver.expect_ordered_request(
|
||||||
'/api/create',
|
'/api/create',
|
||||||
method='POST',
|
method='POST',
|
||||||
@ -822,7 +821,7 @@ async def test_async_client_create_path_relative(httpserver: HTTPServer):
|
|||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_async_client_create_path_user_home(httpserver: HTTPServer, userhomedir):
|
async def test_async_client_create_path_user_home(httpserver: HTTPServer, userhomedir):
|
||||||
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='HEAD').respond_with_response(Response(status=200))
|
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='POST').respond_with_response(Response(status=200))
|
||||||
httpserver.expect_ordered_request(
|
httpserver.expect_ordered_request(
|
||||||
'/api/create',
|
'/api/create',
|
||||||
method='POST',
|
method='POST',
|
||||||
@ -846,7 +845,7 @@ async def test_async_client_create_path_user_home(httpserver: HTTPServer, userho
|
|||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_async_client_create_modelfile(httpserver: HTTPServer):
|
async def test_async_client_create_modelfile(httpserver: HTTPServer):
|
||||||
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='HEAD').respond_with_response(Response(status=200))
|
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='POST').respond_with_response(Response(status=200))
|
||||||
httpserver.expect_ordered_request(
|
httpserver.expect_ordered_request(
|
||||||
'/api/create',
|
'/api/create',
|
||||||
method='POST',
|
method='POST',
|
||||||
@ -866,7 +865,7 @@ async def test_async_client_create_modelfile(httpserver: HTTPServer):
|
|||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_async_client_create_modelfile_roundtrip(httpserver: HTTPServer):
|
async def test_async_client_create_modelfile_roundtrip(httpserver: HTTPServer):
|
||||||
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='HEAD').respond_with_response(Response(status=200))
|
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='POST').respond_with_response(Response(status=200))
|
||||||
httpserver.expect_ordered_request(
|
httpserver.expect_ordered_request(
|
||||||
'/api/create',
|
'/api/create',
|
||||||
method='POST',
|
method='POST',
|
||||||
@ -933,7 +932,6 @@ async def test_async_client_create_from_library(httpserver: HTTPServer):
|
|||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_async_client_create_blob(httpserver: HTTPServer):
|
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='POST').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('/'))
|
client = AsyncClient(httpserver.url_for('/'))
|
||||||
@ -945,7 +943,7 @@ async def test_async_client_create_blob(httpserver: HTTPServer):
|
|||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_async_client_create_blob_exists(httpserver: HTTPServer):
|
async def test_async_client_create_blob_exists(httpserver: HTTPServer):
|
||||||
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='HEAD').respond_with_response(Response(status=200))
|
httpserver.expect_ordered_request(PrefixPattern('/api/blobs/'), method='POST').respond_with_response(Response(status=200))
|
||||||
|
|
||||||
client = AsyncClient(httpserver.url_for('/'))
|
client = AsyncClient(httpserver.url_for('/'))
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user