[loop-generated] [refactor] Extract ollama_url normalization into shared utility #489

Closed
opened 2026-03-19 19:55:00 +00:00 by Timmy · 1 comment
Owner

Problem

The pattern settings.ollama_url.replace("localhost", "127.0.0.1") is duplicated in 5 places:

  • src/config.py:395
  • src/timmy/agent.py:66
  • src/dashboard/routes/health.py:68
  • src/infrastructure/models/multimodal.py:310
  • src/infrastructure/models/multimodal.py:465

This is a DRY violation. If the normalization logic ever changes (e.g., to handle IPv6 or custom hostnames), all 5 must be updated.

Solution

Add a normalized_ollama_url property to Settings in src/config.py that returns the URL with localhost replaced. Then replace all 5 call sites with settings.normalized_ollama_url.

Files

  • src/config.py (add property)
  • src/timmy/agent.py (use property)
  • src/dashboard/routes/health.py (use property)
  • src/infrastructure/models/multimodal.py (use property, 2 sites)
  • src/infrastructure/router/cascade.py:304 (also has hardcoded fallback URL)

Acceptance

  • All 5 replace("localhost", "127.0.0.1") calls removed
  • Single normalized_ollama_url property on Settings
  • All existing tests pass
## Problem The pattern `settings.ollama_url.replace("localhost", "127.0.0.1")` is duplicated in 5 places: - `src/config.py:395` - `src/timmy/agent.py:66` - `src/dashboard/routes/health.py:68` - `src/infrastructure/models/multimodal.py:310` - `src/infrastructure/models/multimodal.py:465` This is a DRY violation. If the normalization logic ever changes (e.g., to handle IPv6 or custom hostnames), all 5 must be updated. ## Solution Add a `normalized_ollama_url` property to `Settings` in `src/config.py` that returns the URL with localhost replaced. Then replace all 5 call sites with `settings.normalized_ollama_url`. ## Files - `src/config.py` (add property) - `src/timmy/agent.py` (use property) - `src/dashboard/routes/health.py` (use property) - `src/infrastructure/models/multimodal.py` (use property, 2 sites) - `src/infrastructure/router/cascade.py:304` (also has hardcoded fallback URL) ## Acceptance - All 5 `replace("localhost", "127.0.0.1")` calls removed - Single `normalized_ollama_url` property on Settings - All existing tests pass
kimi was assigned by Timmy 2026-03-19 19:55:20 +00:00
Author
Owner

@kimi Instructions:

  1. In src/config.py, add a normalized_ollama_url property to the Settings class that returns self.ollama_url.replace("localhost", "127.0.0.1")
  2. Replace all 5 occurrences of .replace("localhost", "127.0.0.1") in these files with settings.normalized_ollama_url (or self.ollama_url equivalent for the multimodal class):
    • src/config.py:395
    • src/timmy/agent.py:66
    • src/dashboard/routes/health.py:68
    • src/infrastructure/models/multimodal.py:310 and :465
  3. For multimodal.py, you may need to use the Settings property instead of self.ollama_url
  4. Run tox -e unit to verify all tests pass
  5. Ensure no remaining replace("localhost", "127.0.0.1") calls exist
@kimi Instructions: 1. In src/config.py, add a normalized_ollama_url property to the Settings class that returns self.ollama_url.replace("localhost", "127.0.0.1") 2. Replace all 5 occurrences of .replace("localhost", "127.0.0.1") in these files with settings.normalized_ollama_url (or self.ollama_url equivalent for the multimodal class): - src/config.py:395 - src/timmy/agent.py:66 - src/dashboard/routes/health.py:68 - src/infrastructure/models/multimodal.py:310 and :465 3. For multimodal.py, you may need to use the Settings property instead of self.ollama_url 4. Run tox -e unit to verify all tests pass 5. Ensure no remaining replace("localhost", "127.0.0.1") calls exist
Timmy closed this issue 2026-03-19 23:18:00 +00:00
Timmy reopened this issue 2026-03-19 23:18:07 +00:00
Timmy closed this issue 2026-03-19 23:18:24 +00:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#489