From c451b1749bf304ff57dd629fb3fd92efb41e4d40 Mon Sep 17 00:00:00 2001 From: jhaveri-bhavya Date: Sun, 6 Sep 2026 11:14:49 +0200 Subject: [PATCH] examples: show full Modelfile surface in create.py, add create-gguf.py create.py only set from_ and system, which makes it look like create() can't express a full Modelfile. Expand it to cover template, parameters, messages and license too, with a comment mapping each kwarg to its Modelfile directive. Add create-gguf.py for the weights-import path: upload the file with create_blob() and pass the returned digest through files=. Refs #664, #431 --- examples/README.md | 3 ++- examples/create-gguf.py | 23 +++++++++++++++++++++++ examples/create.py | 17 ++++++++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 examples/create-gguf.py diff --git a/examples/README.md b/examples/README.md index 1df713ea..57ae1fe2 100644 --- a/examples/README.md +++ b/examples/README.md @@ -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 diff --git a/examples/create-gguf.py b/examples/create-gguf.py new file mode 100644 index 00000000..807c6cf6 --- /dev/null +++ b/examples/create-gguf.py @@ -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) diff --git a/examples/create.py b/examples/create.py index 4ed8376f..d4c0e7b0 100755 --- a/examples/create.py +++ b/examples/create.py @@ -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': ['']}, + 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.