Skip to main content

LLM plugin providing access to local Ollama models

Project description

llm-ollama

PyPI Changelog Tests License

LLM plugin providing access to models running on local Ollama server.

Installation

Install this plugin in the same environment as LLM.

llm install llm-ollama

Usage

First, ensure that your Ollama server is running and that you have pulled some models. You can use ollama list to check what is locally available.

The plugin will query the Ollama server for the list of models. You can use llm ollama list-models to see the list; it should be the same as output by ollama list. All these models will be automatically registered with LLM and made available for prompting, chatting, and embedding.

Assuming you have llama2:latest available, you can run a prompt using:

llm -m llama2:latest 'How much is 2+2?'

The plugin automatically creates a short alias for models that have :latest in the name, so the previous command is equivalent to running:

llm -m llama2 'How much is 2+2?'

To start an interactive chat session:

llm chat -m llama2
Chatting with llama2:latest
Type 'exit' or 'quit' to exit
Type '!multi' to enter multiple lines, then '!end' to finish
>

Image attachments

Multi-modal Ollama models can accept image attachments using the LLM attachments options:

llm -m llava "Describe this image" -a https://static.simonwillison.net/static/2024/pelicans.jpg

Embeddings

The plugin supports LLM embeddings. Both regular and specialized embedding models (such as mxbai-embed-large) can be used:

llm embed -m mxbai-embed-large -i README.md

By default, the input will be truncated from the end to fit within the context length. This behavior can be changed by setting OLLAMA_EMBED_TRUNCATE=no environment variable. In such case, embedding operation will fail if context length is exceeded.

Model aliases

The same Ollama model may be referred by several names with different tags. For example, in the following list, there is a single unique model with three different names:

ollama list
NAME                    ID              SIZE    MODIFIED
stable-code:3b          aa5ab8afb862    1.6 GB  9 hours ago
stable-code:code        aa5ab8afb862    1.6 GB  9 seconds ago
stable-code:latest      aa5ab8afb862    1.6 GB  14 seconds ago

In such cases, the plugin will register a single model and create additional aliases. Continuing the previous example, this is what LLM will have:

llm models
...

Ollama: stable-code:3b (aliases: stable-code:code, stable-code:latest, stable-code)

Model options

All models accept Ollama modelfile parameters as options. Use the -o name value syntax to specify them, for example:

  • -o temperature 0.8: set the temperature of the model
  • -o num_ctx 256000: set the size of the context window used to generate the next token

See the referenced page for the complete list with descriptions and default values.

Additionally, the -o json_object 1 option can be used to force the model to reply with a valid JSON object. Note that your prompt must mention JSON for this to work.

Ollama server address

If your Ollama server is not hosted at the default localhost:11434 address, you can use OLLAMA_HOST environment variable to point the plugin to it.

Development

To set up this plugin locally, first checkout the code. Then create a new virtual environment:

cd llm-ollama
python3 -m venv venv
source venv/bin/activate

Now install the dependencies and test dependencies:

pip install -e '.[test]'

To run the tests:

pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_ollama-0.7.0.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

llm_ollama-0.7.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file llm_ollama-0.7.0.tar.gz.

File metadata

  • Download URL: llm_ollama-0.7.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for llm_ollama-0.7.0.tar.gz
Algorithm Hash digest
SHA256 7e57706db3dd73245ec90d4859c82d3717ccae4962bb038ec27beb358a778bb0
MD5 df7250bfdb6a5ef22c4ed78ad5b9cf70
BLAKE2b-256 8aa68b91fd14cebbb1822fc37c3dcfb7441ce11f3b605c3de7ab20ef1747bb1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_ollama-0.7.0.tar.gz:

Publisher: publish.yml on taketwo/llm-ollama

Attestations:

File details

Details for the file llm_ollama-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: llm_ollama-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for llm_ollama-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dce37f6da1500692f0d4cd10598ca90e12e79f18f8ed6c044633f2f7371708bd
MD5 1dce6cf971f5e335a1a57272a8ea7842
BLAKE2b-256 c8dbcd580a65fc4113be6bca57b40136cb4014b6bbd9b665f4b8d928233b271f

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_ollama-0.7.0-py3-none-any.whl:

Publisher: publish.yml on taketwo/llm-ollama

Attestations:

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page