ollama.create not working properly #183

Closed
opened 2026-02-15 16:28:32 -05:00 by yindo · 10 comments
Owner

Originally created by @erlebach on GitHub (Dec 10, 2024).

Could somebody please provide a working python example using ollama.create ? so far I have been unsuccessful. I also noticed that there are no examples of this type in the examples/ folder. Thanks.

Originally created by @erlebach on GitHub (Dec 10, 2024). Could somebody please provide a working python example using `ollama.create` ? so far I have been unsuccessful. I also noticed that there are no examples of this type in the examples/ folder. Thanks.
yindo closed this issue 2026-02-15 16:28:32 -05:00
Author
Owner

@mustangs0786 commented on GitHub (Jan 9, 2025):

same i also facing issue here...

@mustangs0786 commented on GitHub (Jan 9, 2025): same i also facing issue here...
Author
Owner

@iNLyze commented on GitHub (Jan 17, 2025):

Up until version 0.4.5 I wrapped it like so:

class Model():
    def __init__(
            self,
            name: str,
            model: str,
            system: str,
            options: Dict = None,
    ):
        rm_str = ['\\n', '\t'] # Remove problematic string formatting
        self.name = self._clean(str(name), rm_str, len(rm_str)*[' '])
        self.model = self._clean(str(model), rm_str, len(rm_str)*[' ']) # e.g. 'llama3.1:latest'
        self.system = f"""{self._clean(str(system), rm_str, len(rm_str)*[' '])}""" # e.g. 'You are a helpful assistant.'
        self.options = options
        self.modelfile = f"""FROM {model}\nSYSTEM {system}\n{self._options_to_modelfile(options)}"""
        self.modelfile = self._clean(self.modelfile, rm_str, len(rm_str)*[' '])
        print(self.modelfile)
        self._create()

    def _clean(self, s: str, old: str|List[str]='\\n', new:str|List[str]=' ') -> str:
        out = s
        if not isinstance(old, List):
            old = [old]
        if not isinstance(new, List):
            new = [new]
        assert len(old)==len(new)
        for o, n in zip(old, new):
            out = out.replace(o, n)
        return out
    
    def _create(self):
        self.create_status = ollama.create(model=self.name, modelfile=self.modelfile)

    def _options_to_modelfile(self, options: Dict = None):
        if options is None:
            res = ''
        else:
            res = 'PARAMETER '+ 'PARAMETER '.join([' '.join((k,str(v), '\n')) for k,v in options.items()])
        return res
    
    def _format_to_modelfile(self, format: BaseModel = None):
        if format is None:
            res = None
        else:
            res = format.model_json_schema()
        return res

However, with the next version the API was completely changed. Can I ask, btw, why this was done (e.g. @pdevine )? Now you have to pass all parameters separately, see changes.
I have not found documentation on this yet, @erlebach.

@iNLyze commented on GitHub (Jan 17, 2025): Up until version 0.4.5 I wrapped it like so: ```python class Model(): def __init__( self, name: str, model: str, system: str, options: Dict = None, ): rm_str = ['\\n', '\t'] # Remove problematic string formatting self.name = self._clean(str(name), rm_str, len(rm_str)*[' ']) self.model = self._clean(str(model), rm_str, len(rm_str)*[' ']) # e.g. 'llama3.1:latest' self.system = f"""{self._clean(str(system), rm_str, len(rm_str)*[' '])}""" # e.g. 'You are a helpful assistant.' self.options = options self.modelfile = f"""FROM {model}\nSYSTEM {system}\n{self._options_to_modelfile(options)}""" self.modelfile = self._clean(self.modelfile, rm_str, len(rm_str)*[' ']) print(self.modelfile) self._create() def _clean(self, s: str, old: str|List[str]='\\n', new:str|List[str]=' ') -> str: out = s if not isinstance(old, List): old = [old] if not isinstance(new, List): new = [new] assert len(old)==len(new) for o, n in zip(old, new): out = out.replace(o, n) return out def _create(self): self.create_status = ollama.create(model=self.name, modelfile=self.modelfile) def _options_to_modelfile(self, options: Dict = None): if options is None: res = '' else: res = 'PARAMETER '+ 'PARAMETER '.join([' '.join((k,str(v), '\n')) for k,v in options.items()]) return res def _format_to_modelfile(self, format: BaseModel = None): if format is None: res = None else: res = format.model_json_schema() return res ``` However, with the next version the API was completely changed. Can I ask, btw, why this was done (e.g. @pdevine )? Now you have to pass all parameters separately, see [changes](https://github.com/ollama/ollama-python/commit/427b0c629102f2880fa0c2cc410d7521ae7933af). I have not found documentation on this yet, @erlebach.
Author
Owner

@pdevine commented on GitHub (Jan 17, 2025):

Hey guys,

Sorry about the confusion here. We had a breaking change in the API for the create endpoint. This was because the Modelfile isn't a great way to serialize data and we wanted to simplify how it works and make it more RESTful. We should have bumped the version properly since it's a breaking change.

There is new documentation on how the format works in the main repo and the example in the ollama-python repo has been updated (admittedly this is still pretty sparse and could use more examples).

@iNLyze for your example you can just send each of the args in _create(), rename options to parameters and you shouldn't need self.modelfile anymore.

@pdevine commented on GitHub (Jan 17, 2025): Hey guys, Sorry about the confusion here. We had a breaking change in the API for the create endpoint. This was because the Modelfile isn't a great way to serialize data and we wanted to simplify how it works and make it more RESTful. We should have bumped the version properly since it's a breaking change. There is new documentation on how the format works in the main repo and the example in the `ollama-python` repo has been updated (admittedly this is still pretty sparse and could use more examples). @iNLyze for your example you can just send each of the args in `_create()`, rename `options` to `parameters` and you shouldn't need `self.modelfile` anymore.
Author
Owner

@mustangs0786 commented on GitHub (Jan 18, 2025):

HI @pdevine i tried latest way of creating model

ollama.create(model='example', from_='llama3.2', system="You are Mario from Super Mario Bros.")

still i am getting below error

ResponseError: path or Modelfile are required

can you please look into this

@mustangs0786 commented on GitHub (Jan 18, 2025): HI @pdevine i tried latest way of creating model `ollama.create(model='example', from_='llama3.2', system="You are Mario from Super Mario Bros.")` still i am getting below error ResponseError: path or Modelfile are required can you please look into this
Author
Owner

@nodeMevK commented on GitHub (Jan 18, 2025):

Yea i'm having the same issue as well

@nodeMevK commented on GitHub (Jan 18, 2025): Yea i'm having the same issue as well
Author
Owner

@ParthSareen commented on GitHub (Jan 21, 2025):

@mustangs0786 @nodeMevK could you please provide your Ollama versions as well? Should not be running into that anymore...

@ParthSareen commented on GitHub (Jan 21, 2025): @mustangs0786 @nodeMevK could you please provide your Ollama versions as well? Should not be running into that anymore...
Author
Owner

@nodeMevK commented on GitHub (Jan 21, 2025):

@ParthSareen i'm using Ollama 0.4.6

I get this error when running the example/create.py

Image

Image

and also get the same error when running the example from the readme

Image

Image

@nodeMevK commented on GitHub (Jan 21, 2025): @ParthSareen i'm using Ollama 0.4.6 I get this error when running the example/create.py ![Image](https://github.com/user-attachments/assets/5f1826e9-7865-403d-8740-03d67a423ea7) ![Image](https://github.com/user-attachments/assets/88eee34f-fe85-41e3-a2b7-2a2ea5d008f1) and also get the same error when running the example from the readme ![Image](https://github.com/user-attachments/assets/d375e7ef-f955-4e36-b5ef-1872543f5967) ![Image](https://github.com/user-attachments/assets/6a890b46-2a1a-4c65-b24a-d1912c045606)
Author
Owner

@ParthSareen commented on GitHub (Jan 22, 2025):

@nodeMevK
The API changed recently - can you make sure the ollama version you're running is v0.5.7 you can check with ollama -v

@ParthSareen commented on GitHub (Jan 22, 2025): @nodeMevK The API changed recently - can you make sure the ollama version you're running is `v0.5.7` you can check with `ollama -v`
Author
Owner

@nodeMevK commented on GitHub (Jan 22, 2025):

@ParthSareen ah thank you I updated ollama-python version but not the actual ollama. this fixed my issue

@nodeMevK commented on GitHub (Jan 22, 2025): @ParthSareen ah thank you I updated ollama-python version but not the actual ollama. this fixed my issue
Author
Owner

@ParthSareen commented on GitHub (Jan 22, 2025):

@nodeMevK Glad to hear that! Sorry about the change, should've bumped the major version to show breaking change.

@ParthSareen commented on GitHub (Jan 22, 2025): @nodeMevK Glad to hear that! Sorry about the change, should've bumped the major version to show breaking change.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ollama/ollama-python#183