Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ Requirement: `pip install tqdm`

- [pull.py](pull.py)

### Ollama Create - Create a model from a Modelfile
### Ollama Create - Create a model from a base model or a GGUF file

- [create.py](create.py)
- [create-gguf.py](create-gguf.py)

### Ollama Embed - Generate embeddings with a model

Expand Down
23 changes: 23 additions & 0 deletions examples/create-gguf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Import a local GGUF file as a model.
#
# Modelfile equivalent:
# FROM ./model.gguf
#
# The API takes blob digests rather than file paths, so each file is uploaded
# first with Client.create_blob(), which streams the file to the server and
# returns its 'sha256:...' digest. The same pattern works for adapters=.

from ollama import Client

client = Client()

path = 'path/to/model.gguf' # replace with a real GGUF file on disk

response = client.create(
model='my-gguf-model',
files={'model.gguf': client.create_blob(path)},
# quantize='q4_K_M', # optional: quantize the weights during import
system='You are a helpful assistant.',
stream=False,
)
print(response.status)
17 changes: 16 additions & 1 deletion examples/create.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
from ollama import Client

client = Client()

# Each keyword argument maps to a Modelfile directive; together they are the
# Modelfile, expressed in Python:
# from_ -> FROM template -> TEMPLATE messages -> MESSAGE
# system -> SYSTEM parameters -> PARAMETER license -> LICENSE
response = client.create(
model='my-assistant',
from_='gemma3',
system='You are mario from Super Mario Bros.',
system='You are Mario from Super Mario Bros.',
template='{{ .System }} {{ .Prompt }}',
parameters={'temperature': 0.6, 'num_ctx': 4096, 'stop': ['<end_of_turn>']},
messages=[
{'role': 'user', 'content': 'Who are you?'},
{'role': 'assistant', 'content': "It's-a me, Mario!"},
],
license='MIT',
stream=False,
)
print(response.status)

# To import model weights from a local GGUF file instead of deriving from an
# existing model, see create-gguf.py.