dm-ollamalib
Python package: helper functions to parse Ollama options from a string. Also show available options.
Nothing stellar, but these functionalities are somehow missing from the Ollama Python package.
Installation
If you haven't done so already, please install uv as this Python package and project manager basically makes all headaches of Python package management go away in an instant.
Simply do uv add dm-ollamalib and you are good to go.
In case you want to work with the GitHub repository (e.g., because testing out a branch or similar), do
uv add git+https://github.com/DrMicrobit/dm-ollamalib.
Usage
Three function are provided:
- two helper functions that return as string a list of Ollama options, their type, and if available a short description
- a parsing function that parses a string and returns a dictionary compatible for use with Ollama
Functions to describe Ollama options
Both functions return a string.
- help_overview(): returns a string showing name and type of supported Ollama options. String will look like this:
numa : bool
num_ctx : int
num_batch : int
...
- help_long:(): returns a string showing name, type and description of supported Ollama options. The string will look like this:
numa : bool
This parameter seems to be new, or not described in docs as of January 2025.
dm_ollamalib does not know it, sorry.
num_ctx : int
Sets the size of the context window used to generate the next token.
(Default: 2048)
...
Function to parse strings representing Ollama options
to_ollama_options() transforms a string with semicolon separated Ollama options to into an
Ollama options object. It has a more rigorous type checking than Ollama, e.g., if one passes
a float for a parameter expecting an int, this will be caught.
Arguments:
- params : str
A string representing options for Ollama, separated by semicolon. E.g. "num_ctx=8092;temperature=0.8" - oopt: ollama.Options | None An optional Ollama option object into which the new options from "params" would be parsed into.
Exceptions raised:
- ValueError for
- unrecognised Ollama options
- conversion errors of a string to required type (int, float, bool), e.g. "num_ctx=NotAnInt"
- incomplete options (e.g. "num_ctx=" or "=8092")
- unknown Ollama options
- RuntimeError
- if Ollama Python library has unexpected parameter types not handled by this function (should not happen, except if Ollama devs implemented something new)
Usage examples
from dm_ollamalib.parse_options import help_long, help_overview, to_ollama_options
print(help_overview())
print(help_long())
print(to_ollama_options("top_p=0.9;temperature=0.8"))
The first two lines will print the generated help texts for the options present in the Ollama Python package. The two subsequent lines show how to parse options from one or several strings coming from, e.g. command line.
The dictionary returned by to_ollama_options() can be used directly in calls to Ollama. E.g.
import ollama
from dm_ollamalib.optionhelper import to_ollama_options
op = to_ollama_options("top_p=0.9;temperature=0.8")
ostream = ollama.chat(
model="llama3.1",
options=op, # the options parsed from string
...
)
Alternatively, the following is also a valid use case
import ollama
from dm_ollamalib.optionhelper import to_ollama_options
op: ollama.Options = ollama.Options()
for s in ["top_p=0.9", "temperature=0.8"]
op = to_ollama_options(s, op)
ostream = ollama.chat(
model="llama3.1",
options=op, # the options parsed from all strings
...
)
Notes
The GitHub repository comes with all files I currently use for Python development across multiple platforms. Notably:
- configuration of the Python environment via
uv: pyproject.toml and uv.lock - configuration for linter and code formatter
ruff: ruff.toml - configuration for
pylint: .pylintrc - git ignore files: .gitignore
- configuration for
pre-commit: .pre-commit-config.yaml. The script used to checkgit commitsummary message is in devsupport/check_commitsummary.py - configuration for VSCode editor: .vscode directory
Metadata
Release files for dm-ollamalib 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dm_ollamalib-0.2.0.tar.gz | 29.0 kB | Without provenance | Details for dm_ollamalib-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dm_ollamalib-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for dm_ollamalib-0.2.0-py3-none-any.whl |
Total release size: 39.1 kB
Release files / dm_ollamalib-0.2.0.tar.gz
| Download URL | dm_ollamalib-0.2.0.tar.gz |
|---|---|
| Size | 29.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b5bcbd5d3a757c938cc4e7879b05781afc713ee9b3d02c8698a383b45640c823
|
|
BLAKE2b-256 checksum How to use checksums |
972ac3487bdf3710118255fc9372533654d4a8b436d8b9169a1dc14033ec3961
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.3
|
Release files / dm_ollamalib-0.2.0-py3-none-any.whl
| Download URL | dm_ollamalib-0.2.0-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
460025300f4a9598671f957da22850175c56292bd213bd95b6cf6493641b541a
|
|
BLAKE2b-256 checksum How to use checksums |
6649bdc25864af12873f15b5ecfcd19949ee4db7227e6c69ef7899188ebcf3b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.3
|
Security for dm-ollamalib 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.