This commit is contained in:
Michael Yang 2023-12-21 14:21:02 -08:00
parent 9d93f70806
commit 47c934c74b
5 changed files with 576 additions and 392 deletions

View File

@ -3,9 +3,9 @@ from ollama import generate
prefix = '''def remove_non_ascii(s: str) -> str:
""" '''
suffix = '''
suffix = """
return result
'''
"""
response = generate(

View File

@ -9,6 +9,7 @@ from base64 import b64encode
from typing import Any, AnyStr, Union, Optional, List, Mapping
import sys
if sys.version_info < (3, 9):
from typing import Iterator, AsyncIterator
else:
@ -18,13 +19,11 @@ from ollama._types import Message, Options
class BaseClient:
def __init__(self, client, base_url='http://127.0.0.1:11434') -> None:
self._client = client(base_url=base_url, follow_redirects=True, timeout=None)
class Client(BaseClient):
def __init__(self, base='http://localhost:11434') -> None:
super().__init__(httpx.Client, base)
@ -61,7 +60,10 @@ class Client(BaseClient):
raise Exception('must provide a model')
fn = self._stream if stream else self._request_json
return fn('POST', '/api/generate', json={
return fn(
'POST',
'/api/generate',
json={
'model': model,
'prompt': prompt,
'system': system,
@ -72,7 +74,8 @@ class Client(BaseClient):
'images': [_encode_image(image) for image in images or []],
'format': format,
'options': options or {},
})
},
)
def chat(
self,
@ -96,13 +99,17 @@ class Client(BaseClient):
message['images'] = [_encode_image(image) for image in images]
fn = self._stream if stream else self._request_json
return fn('POST', '/api/chat', json={
return fn(
'POST',
'/api/chat',
json={
'model': model,
'messages': messages,
'stream': stream,
'format': format,
'options': options or {},
})
},
)
def pull(
self,
@ -111,11 +118,15 @@ class Client(BaseClient):
stream: bool = False,
) -> Union[Mapping[str, Any], Iterator[Mapping[str, Any]]]:
fn = self._stream if stream else self._request_json
return fn('POST', '/api/pull', json={
return fn(
'POST',
'/api/pull',
json={
'model': model,
'insecure': insecure,
'stream': stream,
})
},
)
def push(
self,
@ -124,11 +135,15 @@ class Client(BaseClient):
stream: bool = False,
) -> Union[Mapping[str, Any], Iterator[Mapping[str, Any]]]:
fn = self._stream if stream else self._request_json
return fn('POST', '/api/push', json={
return fn(
'POST',
'/api/push',
json={
'model': model,
'insecure': insecure,
'stream': stream,
})
},
)
def create(
self,
@ -145,11 +160,15 @@ class Client(BaseClient):
raise Exception('must provide either path or modelfile')
fn = self._stream if stream else self._request_json
return fn('POST', '/api/create', json={
return fn(
'POST',
'/api/create',
json={
'model': model,
'modelfile': modelfile,
'stream': stream,
})
},
)
def _parse_modelfile(self, modelfile: str, base: Optional[Path] = None) -> str:
base = Path.cwd() if base is None else base
@ -170,7 +189,7 @@ class Client(BaseClient):
sha256sum = sha256()
with open(path, 'rb') as r:
while True:
chunk = r.read(32*1024)
chunk = r.read(32 * 1024)
if not chunk:
break
sha256sum.update(chunk)
@ -204,7 +223,6 @@ class Client(BaseClient):
class AsyncClient(BaseClient):
def __init__(self, base='http://localhost:11434') -> None:
super().__init__(httpx.AsyncClient, base)
@ -225,6 +243,7 @@ class AsyncClient(BaseClient):
if e := part.get('error'):
raise Exception(e)
yield part
return inner()
async def generate(
@ -244,7 +263,10 @@ class AsyncClient(BaseClient):
raise Exception('must provide a model')
fn = self._stream if stream else self._request_json
return await fn('POST', '/api/generate', json={
return await fn(
'POST',
'/api/generate',
json={
'model': model,
'prompt': prompt,
'system': system,
@ -255,7 +277,8 @@ class AsyncClient(BaseClient):
'images': [_encode_image(image) for image in images or []],
'format': format,
'options': options or {},
})
},
)
async def chat(
self,
@ -279,13 +302,17 @@ class AsyncClient(BaseClient):
message['images'] = [_encode_image(image) for image in images]
fn = self._stream if stream else self._request_json
return await fn('POST', '/api/chat', json={
return await fn(
'POST',
'/api/chat',
json={
'model': model,
'messages': messages,
'stream': stream,
'format': format,
'options': options or {},
})
},
)
async def pull(
self,
@ -294,11 +321,15 @@ class AsyncClient(BaseClient):
stream: bool = False,
) -> Union[Mapping[str, Any], AsyncIterator[Mapping[str, Any]]]:
fn = self._stream if stream else self._request_json
return await fn('POST', '/api/pull', json={
return await fn(
'POST',
'/api/pull',
json={
'model': model,
'insecure': insecure,
'stream': stream,
})
},
)
async def push(
self,
@ -307,11 +338,15 @@ class AsyncClient(BaseClient):
stream: bool = False,
) -> Union[Mapping[str, Any], AsyncIterator[Mapping[str, Any]]]:
fn = self._stream if stream else self._request_json
return await fn('POST', '/api/push', json={
return await fn(
'POST',
'/api/push',
json={
'model': model,
'insecure': insecure,
'stream': stream,
})
},
)
async def create(
self,
@ -328,11 +363,15 @@ class AsyncClient(BaseClient):
raise Exception('must provide either path or modelfile')
fn = self._stream if stream else self._request_json
return await fn('POST', '/api/create', json={
return await fn(
'POST',
'/api/create',
json={
'model': model,
'modelfile': modelfile,
'stream': stream,
})
},
)
async def _parse_modelfile(self, modelfile: str, base: Optional[Path] = None) -> str:
base = Path.cwd() if base is None else base
@ -353,7 +392,7 @@ class AsyncClient(BaseClient):
sha256sum = sha256()
with open(path, 'rb') as r:
while True:
chunk = r.read(32*1024)
chunk = r.read(32 * 1024)
if not chunk:
break
sha256sum.update(chunk)
@ -369,7 +408,7 @@ class AsyncClient(BaseClient):
async def upload_bytes():
with open(path, 'rb') as r:
while True:
chunk = r.read(32*1024)
chunk = r.read(32 * 1024)
if not chunk:
break
yield chunk

View File

@ -1,6 +1,7 @@
from typing import Any, TypedDict, List
import sys
if sys.version_info < (3, 11):
from typing_extensions import NotRequired
else:

View File

@ -25,6 +25,7 @@ requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.ruff]
line-length = 999
indent-width = 2
[tool.ruff.format]

View File

@ -21,19 +21,25 @@ class PrefixPattern(URIPattern):
def test_client_chat(httpserver: HTTPServer):
httpserver.expect_ordered_request('/api/chat', method='POST', json={
httpserver.expect_ordered_request(
'/api/chat',
method='POST',
json={
'model': 'dummy',
'messages': [{'role': 'user', 'content': 'Why is the sky blue?'}],
'stream': False,
'format': '',
'options': {},
}).respond_with_json({
},
).respond_with_json(
{
'model': 'dummy',
'message': {
'role': 'assistant',
'content': "I don't know.",
},
})
}
)
client = Client(httpserver.url_for('/'))
response = client.chat('dummy', messages=[{'role': 'user', 'content': 'Why is the sky blue?'}])
@ -46,22 +52,32 @@ def test_client_chat_stream(httpserver: HTTPServer):
def stream_handler(_: Request):
def generate():
for message in ['I ', "don't ", 'know.']:
yield json.dumps({
yield (
json.dumps(
{
'model': 'dummy',
'message': {
'role': 'assistant',
'content': message,
},
}) + '\n'
}
)
+ '\n'
)
return Response(generate())
httpserver.expect_ordered_request('/api/chat', method='POST', json={
httpserver.expect_ordered_request(
'/api/chat',
method='POST',
json={
'model': 'dummy',
'messages': [{'role': 'user', 'content': 'Why is the sky blue?'}],
'stream': True,
'format': '',
'options': {},
}).respond_with_handler(stream_handler)
},
).respond_with_handler(stream_handler)
client = Client(httpserver.url_for('/'))
response = client.chat('dummy', messages=[{'role': 'user', 'content': 'Why is the sky blue?'}], stream=True)
@ -71,7 +87,10 @@ def test_client_chat_stream(httpserver: HTTPServer):
def test_client_chat_images(httpserver: HTTPServer):
httpserver.expect_ordered_request('/api/chat', method='POST', json={
httpserver.expect_ordered_request(
'/api/chat',
method='POST',
json={
'model': 'dummy',
'messages': [
{
@ -83,13 +102,16 @@ def test_client_chat_images(httpserver: HTTPServer):
'stream': False,
'format': '',
'options': {},
}).respond_with_json({
},
).respond_with_json(
{
'model': 'dummy',
'message': {
'role': 'assistant',
'content': "I don't know.",
},
})
}
)
client = Client(httpserver.url_for('/'))
@ -102,7 +124,10 @@ def test_client_chat_images(httpserver: HTTPServer):
def test_client_generate(httpserver: HTTPServer):
httpserver.expect_ordered_request('/api/generate', method='POST', json={
httpserver.expect_ordered_request(
'/api/generate',
method='POST',
json={
'model': 'dummy',
'prompt': 'Why is the sky blue?',
'system': '',
@ -113,10 +138,13 @@ def test_client_generate(httpserver: HTTPServer):
'images': [],
'format': '',
'options': {},
}).respond_with_json({
},
).respond_with_json(
{
'model': 'dummy',
'response': 'Because it is.',
})
}
)
client = Client(httpserver.url_for('/'))
response = client.generate('dummy', 'Why is the sky blue?')
@ -128,13 +156,22 @@ def test_client_generate_stream(httpserver: HTTPServer):
def stream_handler(_: Request):
def generate():
for message in ['Because ', 'it ', 'is.']:
yield json.dumps({
yield (
json.dumps(
{
'model': 'dummy',
'response': message,
}) + '\n'
}
)
+ '\n'
)
return Response(generate())
httpserver.expect_ordered_request('/api/generate', method='POST', json={
httpserver.expect_ordered_request(
'/api/generate',
method='POST',
json={
'model': 'dummy',
'prompt': 'Why is the sky blue?',
'system': '',
@ -145,7 +182,8 @@ def test_client_generate_stream(httpserver: HTTPServer):
'images': [],
'format': '',
'options': {},
}).respond_with_handler(stream_handler)
},
).respond_with_handler(stream_handler)
client = Client(httpserver.url_for('/'))
response = client.generate('dummy', 'Why is the sky blue?', stream=True)
@ -155,7 +193,10 @@ def test_client_generate_stream(httpserver: HTTPServer):
def test_client_generate_images(httpserver: HTTPServer):
httpserver.expect_ordered_request('/api/generate', method='POST', json={
httpserver.expect_ordered_request(
'/api/generate',
method='POST',
json={
'model': 'dummy',
'prompt': 'Why is the sky blue?',
'system': '',
@ -166,10 +207,13 @@ def test_client_generate_images(httpserver: HTTPServer):
'images': ['iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGNgYGAAAAAEAAH2FzhVAAAAAElFTkSuQmCC'],
'format': '',
'options': {},
}).respond_with_json({
},
).respond_with_json(
{
'model': 'dummy',
'response': 'Because it is.',
})
}
)
client = Client(httpserver.url_for('/'))
@ -181,13 +225,19 @@ def test_client_generate_images(httpserver: HTTPServer):
def test_client_pull(httpserver: HTTPServer):
httpserver.expect_ordered_request('/api/pull', method='POST', json={
httpserver.expect_ordered_request(
'/api/pull',
method='POST',
json={
'model': 'dummy',
'insecure': False,
'stream': False,
}).respond_with_json({
},
).respond_with_json(
{
'status': 'success',
})
}
)
client = Client(httpserver.url_for('/'))
response = client.pull('dummy')
@ -202,13 +252,18 @@ def test_client_pull_stream(httpserver: HTTPServer):
yield json.dumps({'status': 'writing manifest'}) + '\n'
yield json.dumps({'status': 'removing any unused layers'}) + '\n'
yield json.dumps({'status': 'success'}) + '\n'
return Response(generate())
httpserver.expect_ordered_request('/api/pull', method='POST', json={
httpserver.expect_ordered_request(
'/api/pull',
method='POST',
json={
'model': 'dummy',
'insecure': False,
'stream': True,
}).respond_with_json({})
},
).respond_with_json({})
client = Client(httpserver.url_for('/'))
response = client.pull('dummy', stream=True)
@ -216,11 +271,15 @@ def test_client_pull_stream(httpserver: HTTPServer):
def test_client_push(httpserver: HTTPServer):
httpserver.expect_ordered_request('/api/push', method='POST', json={
httpserver.expect_ordered_request(
'/api/push',
method='POST',
json={
'model': 'dummy',
'insecure': False,
'stream': False,
}).respond_with_json({})
},
).respond_with_json({})
client = Client(httpserver.url_for('/'))
response = client.push('dummy')
@ -228,11 +287,15 @@ def test_client_push(httpserver: HTTPServer):
def test_client_push_stream(httpserver: HTTPServer):
httpserver.expect_ordered_request('/api/push', method='POST', json={
httpserver.expect_ordered_request(
'/api/push',
method='POST',
json={
'model': 'dummy',
'insecure': False,
'stream': True,
}).respond_with_json({})
},
).respond_with_json({})
client = Client(httpserver.url_for('/'))
response = client.push('dummy', stream=True)
@ -241,11 +304,15 @@ def test_client_push_stream(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('/api/create', method='POST', json={
httpserver.expect_ordered_request(
'/api/create',
method='POST',
json={
'model': 'dummy',
'modelfile': 'FROM @sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n',
'stream': False,
}).respond_with_json({})
},
).respond_with_json({})
client = Client(httpserver.url_for('/'))
@ -260,11 +327,15 @@ def test_client_create_path(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('/api/create', method='POST', json={
httpserver.expect_ordered_request(
'/api/create',
method='POST',
json={
'model': 'dummy',
'modelfile': 'FROM @sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n',
'stream': False,
}).respond_with_json({})
},
).respond_with_json({})
client = Client(httpserver.url_for('/'))
@ -288,11 +359,15 @@ def 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('/api/create', method='POST', json={
httpserver.expect_ordered_request(
'/api/create',
method='POST',
json={
'model': 'dummy',
'modelfile': 'FROM @sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n',
'stream': False,
}).respond_with_json({})
},
).respond_with_json({})
client = Client(httpserver.url_for('/'))
@ -307,11 +382,15 @@ def test_client_create_path_user_home(httpserver: HTTPServer, userhomedir):
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('/api/create', method='POST', json={
httpserver.expect_ordered_request(
'/api/create',
method='POST',
json={
'model': 'dummy',
'modelfile': 'FROM @sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n',
'stream': False,
}).respond_with_json({})
},
).respond_with_json({})
client = Client(httpserver.url_for('/'))
@ -321,11 +400,15 @@ def test_client_create_modelfile(httpserver: HTTPServer):
def test_client_create_from_library(httpserver: HTTPServer):
httpserver.expect_ordered_request('/api/create', method='POST', json={
httpserver.expect_ordered_request(
'/api/create',
method='POST',
json={
'model': 'dummy',
'modelfile': 'FROM llama2\n',
'stream': False,
}).respond_with_json({})
},
).respond_with_json({})
client = Client(httpserver.url_for('/'))
@ -356,13 +439,17 @@ def test_client_create_blob_exists(httpserver: HTTPServer):
@pytest.mark.asyncio
async def test_async_client_chat(httpserver: HTTPServer):
httpserver.expect_ordered_request('/api/chat', method='POST', json={
httpserver.expect_ordered_request(
'/api/chat',
method='POST',
json={
'model': 'dummy',
'messages': [{'role': 'user', 'content': 'Why is the sky blue?'}],
'stream': False,
'format': '',
'options': {},
}).respond_with_json({})
},
).respond_with_json({})
client = AsyncClient(httpserver.url_for('/'))
response = await client.chat('dummy', messages=[{'role': 'user', 'content': 'Why is the sky blue?'}])
@ -371,13 +458,17 @@ async def test_async_client_chat(httpserver: HTTPServer):
@pytest.mark.asyncio
async def test_async_client_chat_stream(httpserver: HTTPServer):
httpserver.expect_ordered_request('/api/chat', method='POST', json={
httpserver.expect_ordered_request(
'/api/chat',
method='POST',
json={
'model': 'dummy',
'messages': [{'role': 'user', 'content': 'Why is the sky blue?'}],
'stream': True,
'format': '',
'options': {},
}).respond_with_json({})
},
).respond_with_json({})
client = AsyncClient(httpserver.url_for('/'))
response = await client.chat('dummy', messages=[{'role': 'user', 'content': 'Why is the sky blue?'}], stream=True)
@ -386,7 +477,10 @@ async def test_async_client_chat_stream(httpserver: HTTPServer):
@pytest.mark.asyncio
async def test_async_client_chat_images(httpserver: HTTPServer):
httpserver.expect_ordered_request('/api/chat', method='POST', json={
httpserver.expect_ordered_request(
'/api/chat',
method='POST',
json={
'model': 'dummy',
'messages': [
{
@ -398,7 +492,8 @@ async def test_async_client_chat_images(httpserver: HTTPServer):
'stream': False,
'format': '',
'options': {},
}).respond_with_json({})
},
).respond_with_json({})
client = AsyncClient(httpserver.url_for('/'))
@ -410,7 +505,10 @@ async def test_async_client_chat_images(httpserver: HTTPServer):
@pytest.mark.asyncio
async def test_async_client_generate(httpserver: HTTPServer):
httpserver.expect_ordered_request('/api/generate', method='POST', json={
httpserver.expect_ordered_request(
'/api/generate',
method='POST',
json={
'model': 'dummy',
'prompt': 'Why is the sky blue?',
'system': '',
@ -421,7 +519,8 @@ async def test_async_client_generate(httpserver: HTTPServer):
'images': [],
'format': '',
'options': {},
}).respond_with_json({})
},
).respond_with_json({})
client = AsyncClient(httpserver.url_for('/'))
response = await client.generate('dummy', 'Why is the sky blue?')
@ -430,7 +529,10 @@ async def test_async_client_generate(httpserver: HTTPServer):
@pytest.mark.asyncio
async def test_async_client_generate_stream(httpserver: HTTPServer):
httpserver.expect_ordered_request('/api/generate', method='POST', json={
httpserver.expect_ordered_request(
'/api/generate',
method='POST',
json={
'model': 'dummy',
'prompt': 'Why is the sky blue?',
'system': '',
@ -441,7 +543,8 @@ async def test_async_client_generate_stream(httpserver: HTTPServer):
'images': [],
'format': '',
'options': {},
}).respond_with_json({})
},
).respond_with_json({})
client = AsyncClient(httpserver.url_for('/'))
response = await client.generate('dummy', 'Why is the sky blue?', stream=True)
@ -450,7 +553,10 @@ async def test_async_client_generate_stream(httpserver: HTTPServer):
@pytest.mark.asyncio
async def test_async_client_generate_images(httpserver: HTTPServer):
httpserver.expect_ordered_request('/api/generate', method='POST', json={
httpserver.expect_ordered_request(
'/api/generate',
method='POST',
json={
'model': 'dummy',
'prompt': 'Why is the sky blue?',
'system': '',
@ -461,7 +567,8 @@ async def test_async_client_generate_images(httpserver: HTTPServer):
'images': ['iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGNgYGAAAAAEAAH2FzhVAAAAAElFTkSuQmCC'],
'format': '',
'options': {},
}).respond_with_json({})
},
).respond_with_json({})
client = AsyncClient(httpserver.url_for('/'))
@ -473,11 +580,15 @@ async def test_async_client_generate_images(httpserver: HTTPServer):
@pytest.mark.asyncio
async def test_async_client_pull(httpserver: HTTPServer):
httpserver.expect_ordered_request('/api/pull', method='POST', json={
httpserver.expect_ordered_request(
'/api/pull',
method='POST',
json={
'model': 'dummy',
'insecure': False,
'stream': False,
}).respond_with_json({})
},
).respond_with_json({})
client = AsyncClient(httpserver.url_for('/'))
response = await client.pull('dummy')
@ -486,11 +597,15 @@ async def test_async_client_pull(httpserver: HTTPServer):
@pytest.mark.asyncio
async def test_async_client_pull_stream(httpserver: HTTPServer):
httpserver.expect_ordered_request('/api/pull', method='POST', json={
httpserver.expect_ordered_request(
'/api/pull',
method='POST',
json={
'model': 'dummy',
'insecure': False,
'stream': True,
}).respond_with_json({})
},
).respond_with_json({})
client = AsyncClient(httpserver.url_for('/'))
response = await client.pull('dummy', stream=True)
@ -499,11 +614,15 @@ async def test_async_client_pull_stream(httpserver: HTTPServer):
@pytest.mark.asyncio
async def test_async_client_push(httpserver: HTTPServer):
httpserver.expect_ordered_request('/api/push', method='POST', json={
httpserver.expect_ordered_request(
'/api/push',
method='POST',
json={
'model': 'dummy',
'insecure': False,
'stream': False,
}).respond_with_json({})
},
).respond_with_json({})
client = AsyncClient(httpserver.url_for('/'))
response = await client.push('dummy')
@ -512,11 +631,15 @@ async def test_async_client_push(httpserver: HTTPServer):
@pytest.mark.asyncio
async def test_async_client_push_stream(httpserver: HTTPServer):
httpserver.expect_ordered_request('/api/push', method='POST', json={
httpserver.expect_ordered_request(
'/api/push',
method='POST',
json={
'model': 'dummy',
'insecure': False,
'stream': True,
}).respond_with_json({})
},
).respond_with_json({})
client = AsyncClient(httpserver.url_for('/'))
response = await client.push('dummy', stream=True)
@ -526,11 +649,15 @@ async def test_async_client_push_stream(httpserver: HTTPServer):
@pytest.mark.asyncio
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('/api/create', method='POST', json={
httpserver.expect_ordered_request(
'/api/create',
method='POST',
json={
'model': 'dummy',
'modelfile': 'FROM @sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n',
'stream': False,
}).respond_with_json({})
},
).respond_with_json({})
client = AsyncClient(httpserver.url_for('/'))
@ -546,11 +673,15 @@ async def test_async_client_create_path(httpserver: HTTPServer):
@pytest.mark.asyncio
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('/api/create', method='POST', json={
httpserver.expect_ordered_request(
'/api/create',
method='POST',
json={
'model': 'dummy',
'modelfile': 'FROM @sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n',
'stream': False,
}).respond_with_json({})
},
).respond_with_json({})
client = AsyncClient(httpserver.url_for('/'))
@ -566,11 +697,15 @@ async def test_async_client_create_path_relative(httpserver: HTTPServer):
@pytest.mark.asyncio
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('/api/create', method='POST', json={
httpserver.expect_ordered_request(
'/api/create',
method='POST',
json={
'model': 'dummy',
'modelfile': 'FROM @sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n',
'stream': False,
}).respond_with_json({})
},
).respond_with_json({})
client = AsyncClient(httpserver.url_for('/'))
@ -586,11 +721,15 @@ async def test_async_client_create_path_user_home(httpserver: HTTPServer, userho
@pytest.mark.asyncio
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('/api/create', method='POST', json={
httpserver.expect_ordered_request(
'/api/create',
method='POST',
json={
'model': 'dummy',
'modelfile': 'FROM @sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n',
'stream': False,
}).respond_with_json({})
},
).respond_with_json({})
client = AsyncClient(httpserver.url_for('/'))
@ -601,11 +740,15 @@ async def test_async_client_create_modelfile(httpserver: HTTPServer):
@pytest.mark.asyncio
async def test_async_client_create_from_library(httpserver: HTTPServer):
httpserver.expect_ordered_request('/api/create', method='POST', json={
httpserver.expect_ordered_request(
'/api/create',
method='POST',
json={
'model': 'dummy',
'modelfile': 'FROM llama2\n',
'stream': False,
}).respond_with_json({})
},
).respond_with_json({})
client = AsyncClient(httpserver.url_for('/'))