# ComfyUI Ollama Custom [ComfyUI](https://github.com/comfyanonymous/ComfyUI) Nodes for interacting with [Ollama](https://ollama.com/) using the [ollama python client](https://github.com/ollama/ollama-python). Integrate the power of LLMs into ComfyUI workflows easily or just experiment with LLM inference. To use this properly, you would need a running Ollama server reachable from the host that is running ComfyUI. Buy Me A Coffee ![pic](.meta/basic-example.jpg) ## Installation ### 1. Install ollama server on the desired host
Instructions Download for macOS Download for Windows Install on Linux ```shell curl -fsSL https://ollama.com/install.sh | sh ``` Docker Installation CPU only ```shell docker run -d -p 11434:11434 -v ollama:/root/.ollama --name ollama ollama/ollama ``` NVIDIA GPU ```shell docker run -d -p 11434:11434 --gpus=all -v ollama:/root/.ollama --name ollama ollama/ollama ```
### 2. Install the custom nodes Use ComfyUI's built-in extension manager to install the nodes. Search for `comfyui-ollama` by `Stav Sapir`. **Or** If you prefer [ComfyUI-Manager](https://github.com/ltdrdata/ComfyUI-Manager), search for `ollama` and select the one by `stavsap` ![pic](.meta/manager-install.png) **Or** 1. git clone into the `custom_nodes` folder inside your ComfyUI installation or download as zip and unzip the contents to `custom_nodes/compfyui-ollama`. 2. `pip install -r requirements.txt` 3. Start/restart ComfyUI ### Configuration (Ollama Key) If you are using **Ollama Cloud templates** that require authentication, you must provide your Ollama public key. You can do this automatically with the CLI: ```shell ollama signin ``` Or by manually adding your public key at [ollama.com/settings/key](https://ollama.com/settings/keys). Your public key is located at: | OS | Path to id_ed25519.pub | |----|-----------------------| | macOS | ~/.ollama/id_ed25519.pub | | Linux | /usr/share/ollama/.ollama/id_ed25519.pub | | Windows | C:\Users\\.ollama\id_ed25519.pub | See Ollama's [FAQ](https://docs.ollama.com/faq#where-can-i-find-my-ollama-public-key%3F) for more details. ## Nodes ### OllamaGenerate A node that provides ability to set the system prompt and the prompt. Ability to save context locally in the node `enable/disable` Inputs: - **OllamaConnectivity** (optional) - **OllamaOptions** (optional) - **images** (optional) - **context** (optional), a context from other OllamaConnectivity - **meta** (optional), passing metadata of the OllamaConnectivity and OllamaOptions from other OllamaGenerate node. **Notes:** - For this node to be operational, **OllamaConnectivity** or **meta** must be inputted!. - If **images** are inputted and a chain of **meta** usage is made, all the **images** need to be passed as well to the next **OllamaConnectivity** nodes. ## OllamaChat A node for **conversational interaction** using the dedicated Ollama chat endpoint (`ollama.chat`). It manages the full conversation history natively and allows for chained sequences of chat nodes. - **Functionality:** Unlike `OllamaGenerate`, this node is designed specifically for multi-turn conversations and cloud models with your Ollama public key (see the Configuration section). - **Key Features:** - Conversation history is handled natively within the node instance. - Dedicated history outputs for **chaining multiple chat nodes**. - Option to **reset** the current conversation history on demand. Inputs: - **OllamaConnectivity** (optional) - **OllamaOptions** (optional) - **images** (optional) - **meta** (optional), passing metadata of the OllamaConnectivity and OllamaOptions from other OllamaChat node. - **history** (optional), passing history ID from other OllamaChat node. Outputs: - **result**: The generated text - **thinking**: The thinking text - **meta**: The metadata to pass to the next OllamaChat node - **history**: The history ID to pass to the next OllamaChat node ### OllamaConnectivity A node responsible only fot the connectivity to the ollama server ### OllamaOptions A node for full control of the ollama api options. For an option to take effect, each option have also `enable/disable`, enabled options are passed to api call to ollama server. Ollama API options can be found in [this table](https://github.com/ollama/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values). **Note**: There is an additional option `debug` that enables debug print in the cli, its not part of ollama api. ### Deprecated nodes Old V1 nodes are still available, please replace them with the above ones. Here's the [documentation of V1](V1_nodes.md) nodes. ## Usage Example Please see the `example_workflows` folder or use ComfyUI's template browser. The custom Text Nodes in the examples can be found here: https://github.com/pythongosssss/ComfyUI-Custom-Scripts