Back to all reviewers

Loose API coupling

ollama/ollama
Based on 4 comments
Go

Maintain a clear separation between API definitions and their implementations by avoiding direct passing of API structures to implementation layers. Extract only the necessary values from API structures when passing data downstream.

API Go

Reviewer Prompt

Maintain a clear separation between API definitions and their implementations by avoiding direct passing of API structures to implementation layers. Extract only the necessary values from API structures when passing data downstream.

This approach has several benefits:

  • Improves maintainability as implementation details can evolve independently
  • Reduces tight coupling between API contracts and internal code
  • Makes testing easier by simplifying dependencies
  • Prevents implementation-specific requirements from leaking into the API design

Example of problematic coupling:

// Avoid: Passing entire API structure downstream
sampler := sample.NewSampler(req.Options, grammar)

Better approach:

// Better: Extract only needed values
sampler := sample.NewSampler(
    req.Options.Temperature,
    req.Options.TopK,
    req.Options.TopP,
    req.Options.MinP,
    req.Options.Seed,
    grammar,
)

Similarly, for transformation pipelines, prefer direct function calls with clear parameters over passing abstract data structures:

// Instead of: Using lists of transforms
transforms := []Transform{topK, topP, softmax}
Weighted(rng, transforms...)

// Better: Use specific function calls in a clear sequence
result := topK(topP(softmax(values)))

This principle extends to all layers of your API implementation - keep interfaces clean and pass only what’s needed.

4
Comments Analyzed
Go
Primary Language
API
Category

Source Discussions