[GH-ISSUE #10849] Refactor API client for modularity and improved separation of concerns #7123

Open
opened 2026-04-12 19:07:56 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @theotrosman on GitHub (May 24, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/10849

Monolithic Client implementation
The Client struct is handling:

Transport (HTTP)

Request construction

Response decoding

Endpoint-specific logic

Streaming logic (with scanner and custom buffer)
All within a single package, which makes it harder to test and evolve each layer independently.

Code duplication across streaming endpoints
Methods like Generate, Chat, Pull, Push, and Create all repeat the same pattern:

JSON marshaling

Setting headers

Decoding line-delimited JSON
This logic is repeated and could be abstracted.

Lack of interfaces for mocking/testing
The current implementation makes it difficult to mock the Client for unit testing, due to tight coupling and lack of interfaces for transport or API contracts.

No error wrapping for external context
Most json.Unmarshal and http.Do errors are returned raw, which can reduce traceability during debugging.

Responsibility overload in stream and do
These two functions are doing too much: managing encoding/decoding, context, header configuration, error parsing, and response control flow.

Originally created by @theotrosman on GitHub (May 24, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/10849 Monolithic Client implementation The Client struct is handling: Transport (HTTP) Request construction Response decoding Endpoint-specific logic Streaming logic (with scanner and custom buffer) All within a single package, which makes it harder to test and evolve each layer independently. Code duplication across streaming endpoints Methods like Generate, Chat, Pull, Push, and Create all repeat the same pattern: JSON marshaling Setting headers Decoding line-delimited JSON This logic is repeated and could be abstracted. Lack of interfaces for mocking/testing The current implementation makes it difficult to mock the Client for unit testing, due to tight coupling and lack of interfaces for transport or API contracts. No error wrapping for external context Most json.Unmarshal and http.Do errors are returned raw, which can reduce traceability during debugging. Responsibility overload in stream and do These two functions are doing too much: managing encoding/decoding, context, header configuration, error parsing, and response control flow.
GiteaMirror added the feature request label 2026-04-12 19:07:56 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#7123