Skip to content

Create a model using Modelfile #664

Open

Description

@qomhmd

Similar to #430, it seems the Client().create() method does not accept some modelfile argument for model creation. The example code provided in examples' readme does not actually use a Modelfil.

Activity

  1. jhaveri-bhavya commented on Sep 6, 2026

    @jhaveri-bhavya

    Posting this here for reference, since a few issues (#430, #431, this one) circle back to the same confusion and the examples/create.py in the repo only shows a tiny slice of it. I ran into the same thing. The short version: modelfile= was removed in #430 (instead create() now takes the Modelfile apart into separate arguments, one per directive) The example in examples/create.py is pretty minimal (just from_ + system).

    The mapping is basically:

    • FROM → from_
    • SYSTEM → system
    • TEMPLATE → template
    • PARAMETER → parameters (as a dict)
    • LICENSE → license
    • MESSAGE → messages

    So instead of writing a Modelfile like this:

    FROM gemma3
    SYSTEM You are Mario from Super Mario Bros.
    TEMPLATE "{{ .System }} {{ .Prompt }}"
    PARAMETER temperature 0.6
    PARAMETER stop <end_of_turn>
    MESSAGE user Who are you?
    MESSAGE assistant It's-a me, Mario!
    LICENSE MIT
    

    one can write:

    from ollama import Client
    
    client = Client()
    response = client.create(
        model='my-assistant',
        from_='gemma3',
        system='You are Mario from Super Mario Bros.',
        template='{{ .System }} {{ .Prompt }}',
        parameters={'temperature': 0.6, '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)  # 'success'

    Running ollama show my-assistant --modelfile afterwards shows every directive applied.
    And for the GGUF-import case (more relevant to #431): create() takes blob digests rather than file paths, so upload the file first with create_blob() and pass the digest through files=:

    client.create(
        model='my-gguf-model',
        files={'model.gguf': client.create_blob('path/to/model.gguf')},
        stream=False,
    )

    Might be worth expanding examples/create.py to cover more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions