ollama-python-streaming

Streams responses from a local Ollama LLM in Python using LiteLLM with async support, retry logic, and adjustable thinking levels.

3|1|Updated Dec 23, 2025
One-click install
npx skills add https://github.com/marcus/marcus-skills --skill ollama-python-streaming
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ollama-python-streaming
Source: https://github.com/marcus/marcus-skills/tree/main/skills/ollama-python-streaming
Command: npx skills add https://github.com/marcus/marcus-skills --skill ollama-python-streaming

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Enables real-time streaming from a local Ollama LLM within Python applications using LiteLLM, facilitating interactive and responsive AI experiences.

Core Features & Use Cases

  • Async streaming with a robust client implementation
  • Retry logic with exponential backoff and error handling
  • Thinking model configuration for low/medium/high levels
  • Production-ready patterns for local Ollama integration

Quick Start

Install Ollama, start the server, install litellm, and run the minimal streaming example to observe live output.

Frequently Asked Questions about ollama-python-streaming

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I stream responses from a local Ollama LLM in Python?

To stream responses from a local Ollama LLM in Python, use LiteLLM with asyncio. This approach enables real-time output generation, allowing your application to display tokens as they arrive from the model rather than waiting for the full response.

What is the best way to handle errors and retries when streaming Ollama responses?

The best way to handle errors during Ollama streaming is implementing retry logic with exponential backoff. This pattern manages transient connection failures by progressively delaying repeated requests, ensuring robust async streaming without crashing your Python application.

Do I need LiteLLM to use thinking model configuration with Ollama?

Yes, you need LiteLLM to configure thinking model levels for Ollama. It acts as the client interface that passes the low, medium, or high thinking parameters to your local LLM, enabling you to adjust the model's reasoning depth.

Can I use asyncio for real-time LLM output in my Python application?

You can use asyncio to achieve real-time LLM output in Python. By leveraging asynchronous streaming via LiteLLM, your application remains responsive and handles other tasks concurrently while waiting for Ollama tokens to arrive.

What are the requirements for integrating local Ollama LLM streaming?

Requirements for integrating local Ollama streaming include a running Ollama server, the LiteLLM package, and a Python runtime with asyncio support. You must ensure network accessibility to the local server before initiating the async stream.