How to Troubleshoot Ollama Server Connection Issues in MoneyPrinterV2
Ensure Ollama is running with ollama serve, verify config.json contains the correct ollama_base_url (default http://127.0.0.1:11434), and confirm your target model is pulled using ollama list before starting MoneyPrinterV2.
MoneyPrinterV2 relies on the Ollama local LLM server to generate video content scripts. When the application cannot establish a connection to Ollama, content generation halts completely. This guide explains the connection architecture in FujiwaraChoki/MoneyPrinterV2 and provides systematic troubleshooting steps based on the source code implementation.
Understanding the Ollama Connection Architecture
Configuration Layer in config.py
The connection parameters originate in src/config.py. This module reads config.json and exposes two critical functions: get_ollama_base_url() and get_ollama_model(). By default, ollama_base_url resolves to http://127.0.0.1:11434【/src/config.py L72-L90】.
Client Initialization in llm_provider.py
The src/llm_provider.py file constructs the actual Ollama client instance. It imports the base URL via get_ollama_base_url() and instantiates ollama.Client with this endpoint【/src/llm_provider.py L1-L9】.
Model Validation in main.py
During application startup, src/main.py performs strict validation. It calls get_ollama_model() and checks server availability. If the Ollama server reports no available models, the application aborts immediately with an error message at lines 448-460【/src/main.py L448-L460】.
Pre-flight Checks in preflight_local.py
The scripts/preflight_local.py script provides proactive diagnostics. It performs a health check against the configured base URL and warns when the server reports no models, allowing you to fix issues before launching the main application【/scripts/preflight_local.py L67-L80】.
Common Connection Failure Points
When MoneyPrinterV2 fails to connect to Ollama, the issue typically falls into one of these categories:
- Server not running – The Ollama process is not active, causing immediate "connection refused" or timeout errors from the client.
- Incorrect base URL – The client points to the wrong host or port, commonly occurring in Docker environments where the container IP differs from localhost.
- Network restrictions – Firewalls or VPNs block port 11434, preventing the HTTP connection from establishing.
- Model not pulled – The application aborts with "No models found on Ollama" because the target model was never downloaded.
- Corrupt configuration –
config.jsoncontains malformed JSON or missing required keys, causing the configuration layer to fail.
Step-by-Step Troubleshooting Guide
Follow these steps in order to diagnose and resolve Ollama connection issues in MoneyPrinterV2:
-
Run the pre-flight script – Execute the diagnostic script to surface connectivity problems before the main application starts:
python3 scripts/preflight_local.py -
Confirm the server endpoint – Verify that Ollama is listening on the expected port. Use curl to test the tags endpoint:
curl http://127.0.0.1:11434/api/tagsA successful response returns JSON containing available models.
-
Check the model name – Ensure the model specified in
config.jsonmatches an entry in the Ollama server. List installed models:ollama listIf the model is missing, pull it:
ollama pull llama3.2:3b. -
Validate configuration – Verify that
config.jsoncontains valid JSON with both required keys:{ "ollama_base_url": "http://127.0.0.1:11434", "ollama_model": "llama3.2:3b" } -
Restart the application – After fixing any of the above issues, launch MoneyPrinterV2 again:
python3 src/main.py
Diagnostic Code Examples
Use these Python snippets to programmatically verify your Ollama setup within the MoneyPrinterV2 environment:
Programmatic health check:
import requests
from src.config import get_ollama_base_url
def ollama_health():
url = f"{get_ollama_base_url().rstrip('/')}/api/tags"
try:
resp = requests.get(url, timeout=5)
resp.raise_for_status()
print("Ollama reachable – models:", [m["name"] for m in resp.json()["models"]])
except Exception as e:
print("Failed to reach Ollama:", e)
ollama_health()
Inspecting the configured model:
from src.config import get_ollama_model
model = get_ollama_model()
if not model:
raise RuntimeError("Ollama model not set in config.json")
print("Configured Ollama model:", model)
Summary
- MoneyPrinterV2 connects to Ollama through
src/config.py, which readsollama_base_urlandollama_modelfromconfig.json. - Connection failures typically stem from the Ollama server not running, incorrect base URLs, network blocks on port 11434, or missing models.
- Use
scripts/preflight_local.pyto diagnose issues before launching the main application. - Verify connectivity using
curl http://127.0.0.1:11434/api/tagsand ensure the target model appears inollama list.
Frequently Asked Questions
Why does MoneyPrinterV2 fail immediately on startup with a connection error?
The application aborts during initialization in src/main.py lines 448-460 when it cannot validate the Ollama model. This occurs when the server is unreachable, the base URL is misconfigured, or the specified model has not been pulled to the local machine.
Can I use a remote Ollama server instead of localhost?
Yes. Modify the ollama_base_url value in config.json to point to your remote host, such as http://192.168.1.100:11434 or a Docker container IP. Ensure port 11434 is open on the remote host and any firewalls between the client and server allow the connection.
How do I verify which model MoneyPrinterV2 is trying to use?
Import get_ollama_model() from src/config.py and print its return value, or check the ollama_model key directly in your config.json file. The value must match an entry shown in the ollama list command output.
What does the preflight_local.py script check?
The script performs a health check against the Ollama server using the base URL configured in config.json. It verifies HTTP connectivity to the /api/tags endpoint and warns if the server reports no available models, allowing you to resolve issues before running src/main.py.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →