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.