Compare commits

...

8 Commits

Author SHA1 Message Date
Michael Yang c27eebc158 Merge pull request #41 from rachfop/patch-1
Update README.md
2024-01-30 14:31:17 -08:00
Patrick Rachford 46291d49a7 Update README.md
Fixes back ticks on code block.
2024-01-29 21:49:20 -08:00
Michael Yang cf3ab807c8 Merge pull request #40 from ollama/mxyng/fix-parse-modelfile
fix parse modelfile
2024-01-29 14:12:27 -08:00
Michael Yang 8e5d431d0d fix parse modelfile
- do not add newlines while parsing
- do not add leading whitespace
2024-01-29 13:42:34 -08:00
Michael Yang e201181d4c Merge pull request #34 from chenxizhang/patch-1
error handling code
2024-01-29 09:54:43 -08:00
chenxizhang c077b5d685 Update README.md
e.content should be e.error
2024-01-28 11:08:03 +08:00
Michael Yang f618a2f448 Merge pull request #32 from ollama/update-actions
update github actions
2024-01-26 11:32:40 -08:00
Michael Yang 354f012168 update github actions 2024-01-26 11:30:36 -08:00
4 changed files with 121 additions and 17 deletions
+2 -1
View File
@@ -17,7 +17,8 @@ jobs:
python-version: ${{ matrix.python-version }}
cache: poetry
- run: poetry install --with=dev
- run: poetry run ruff --output-format=github .
- run: poetry run ruff check --output-format=github .
- run: poetry run ruff format --check .
- run: poetry run pytest . --junitxml=junit/test-results-${{ matrix.python-version }}.xml --cov=ollama --cov-report=xml --cov-report=html
- name: check poetry.lock is up-to-date
run: poetry check --lock
+2 -2
View File
@@ -138,7 +138,7 @@ async def chat():
asyncio.run(chat())
```
Setting `stream=True`` modifies functions to return a Python asynchronous generator:
Setting `stream=True` modifies functions to return a Python asynchronous generator:
```python
import asyncio
@@ -162,7 +162,7 @@ model = 'does-not-yet-exist'
try:
ollama.chat(model)
except ollama.ResponseError as e:
print('Error:', e.content)
print('Error:', e.error)
if e.status_code == 404:
ollama.pull(model)
```
+18 -12
View File
@@ -259,13 +259,16 @@ class Client(BaseClient):
out = io.StringIO()
for line in io.StringIO(modelfile):
command, _, args = line.partition(' ')
if command.upper() in ['FROM', 'ADAPTER']:
path = Path(args.strip()).expanduser()
path = path if path.is_absolute() else base / path
if path.exists():
args = f'@{self._create_blob(path)}'
if command.upper() not in ['FROM', 'ADAPTER']:
print(line, end='', file=out)
continue
path = Path(args.strip()).expanduser()
path = path if path.is_absolute() else base / path
if path.exists():
args = f'@{self._create_blob(path)}\n'
print(command, args, end='', file=out)
print(command, args, file=out)
return out.getvalue()
def _create_blob(self, path: Union[str, Path]) -> str:
@@ -527,13 +530,16 @@ class AsyncClient(BaseClient):
out = io.StringIO()
for line in io.StringIO(modelfile):
command, _, args = line.partition(' ')
if command.upper() in ['FROM', 'ADAPTER']:
path = Path(args).expanduser()
path = path if path.is_absolute() else base / path
if path.exists():
args = f'@{await self._create_blob(path)}'
if command.upper() not in ['FROM', 'ADAPTER']:
print(line, end='', file=out)
continue
path = Path(args.strip()).expanduser()
path = path if path.is_absolute() else base / path
if path.exists():
args = f'@{await self._create_blob(path)}\n'
print(command, args, end='', file=out)
print(command, args, file=out)
return out.getvalue()
async def _create_blob(self, path: Union[str, Path]) -> str:
+99 -2
View File
@@ -416,13 +416,61 @@ def test_client_create_modelfile(httpserver: HTTPServer):
assert isinstance(response, dict)
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(
'/api/create',
method='POST',
json={
'name': 'dummy',
'modelfile': '''FROM @sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
TEMPLATE """[INST] <<SYS>>{{.System}}<</SYS>>
{{.Prompt}} [/INST]"""
SYSTEM """
Use
multiline
strings.
"""
PARAMETER stop [INST]
PARAMETER stop [/INST]
PARAMETER stop <<SYS>>
PARAMETER stop <</SYS>>''',
'stream': False,
},
).respond_with_json({})
client = Client(httpserver.url_for('/'))
with tempfile.NamedTemporaryFile() as blob:
response = client.create(
'dummy',
modelfile='\n'.join(
[
f'FROM {blob.name}',
'TEMPLATE """[INST] <<SYS>>{{.System}}<</SYS>>',
'{{.Prompt}} [/INST]"""',
'SYSTEM """',
'Use',
'multiline',
'strings.',
'"""',
'PARAMETER stop [INST]',
'PARAMETER stop [/INST]',
'PARAMETER stop <<SYS>>',
'PARAMETER stop <</SYS>>',
]
),
)
assert isinstance(response, dict)
def test_client_create_from_library(httpserver: HTTPServer):
httpserver.expect_ordered_request(
'/api/create',
method='POST',
json={
'name': 'dummy',
'modelfile': 'FROM llama2\n',
'modelfile': 'FROM llama2',
'stream': False,
},
).respond_with_json({})
@@ -820,6 +868,55 @@ async def test_async_client_create_modelfile(httpserver: HTTPServer):
assert isinstance(response, dict)
@pytest.mark.asyncio
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(
'/api/create',
method='POST',
json={
'name': 'dummy',
'modelfile': '''FROM @sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
TEMPLATE """[INST] <<SYS>>{{.System}}<</SYS>>
{{.Prompt}} [/INST]"""
SYSTEM """
Use
multiline
strings.
"""
PARAMETER stop [INST]
PARAMETER stop [/INST]
PARAMETER stop <<SYS>>
PARAMETER stop <</SYS>>''',
'stream': False,
},
).respond_with_json({})
client = AsyncClient(httpserver.url_for('/'))
with tempfile.NamedTemporaryFile() as blob:
response = await client.create(
'dummy',
modelfile='\n'.join(
[
f'FROM {blob.name}',
'TEMPLATE """[INST] <<SYS>>{{.System}}<</SYS>>',
'{{.Prompt}} [/INST]"""',
'SYSTEM """',
'Use',
'multiline',
'strings.',
'"""',
'PARAMETER stop [INST]',
'PARAMETER stop [/INST]',
'PARAMETER stop <<SYS>>',
'PARAMETER stop <</SYS>>',
]
),
)
assert isinstance(response, dict)
@pytest.mark.asyncio
async def test_async_client_create_from_library(httpserver: HTTPServer):
httpserver.expect_ordered_request(
@@ -827,7 +924,7 @@ async def test_async_client_create_from_library(httpserver: HTTPServer):
method='POST',
json={
'name': 'dummy',
'modelfile': 'FROM llama2\n',
'modelfile': 'FROM llama2',
'stream': False,
},
).respond_with_json({})