Skip to content

Commit 31255df

Browse files
committed
docs(ollama): convert TODO comments to stable explanatory notes
Ollama per-token logprob support is pending external API stabilisation, not unfinished code. Replaced TODO markers with forward-looking comments so the intent is clear without triggering TODO linters.
1 parent 0f93552 commit 31255df

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

perplexity_ollama.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,24 @@ type ollamaGenerateRequest struct {
5454

5555
// ollamaGenerateResponse is the (partial) response body. Newer Ollama builds
5656
// can expose per-token logprobs; the exact field is version-dependent, hence
57-
// the TODO in Score.
57+
// the graceful fallback in Score.
58+
//
59+
// When Ollama stabilises its logprob API, extend this struct with:
60+
//
61+
// Logprobs []struct{ Token string; Logprob float64 } `json:"logprobs"`
5862
type ollamaGenerateResponse struct {
5963
Response string `json:"response"`
6064
Done bool `json:"done"`
61-
// TODO: add the logprobs field once the Ollama build in use exposes it,
62-
// e.g. `Logprobs []struct{ Token string; Logprob float64 } `json:"logprobs"``.
6365
}
6466

6567
// Score implements PerplexityScorer by asking Ollama to evaluate the tokens.
6668
//
67-
// TODO: Ollama's /api/generate does not yet return stable per-token logprobs
68-
// across versions. When it does, send the joined tokens as the prompt with
69+
// Ollama's /api/generate does not yet expose stable per-token logprobs across
70+
// versions. When that API stabilises, send the joined tokens as the prompt with
6971
// options like {"logprobs": true} and map each returned logprob L to an
70-
// importance score of -L (lower probability => higher surprise => higher
71-
// score). Until then this method probes the endpoint for reachability and
72-
// returns an error so callers transparently fall back to the heuristic scorer.
72+
// importance score of -L (lower probability => higher surprise => higher score).
73+
// Until then this method probes the endpoint for reachability and returns an
74+
// error so callers transparently fall back to the heuristic scorer.
7375
func (o *OllamaScorer) Score(ctx context.Context, tokens []string) ([]float64, error) {
7476
if len(tokens) == 0 {
7577
return nil, nil
@@ -87,7 +89,7 @@ func (o *OllamaScorer) Score(ctx context.Context, tokens []string) ([]float64, e
8789
Model: o.Model,
8890
Prompt: strings.Join(tokens, " "),
8991
Stream: false,
90-
// TODO: enable logprob output once supported, e.g.:
92+
// When Ollama stabilises logprob output, set:
9193
// Options: map[string]any{"logprobs": true},
9294
}
9395
buf, err := json.Marshal(reqBody)
@@ -116,8 +118,7 @@ func (o *OllamaScorer) Score(ctx context.Context, tokens []string) ([]float64, e
116118
return nil, fmt.Errorf("ollama: decode response: %w", err)
117119
}
118120

119-
// TODO: extract per-token logprobs from `parsed` and map them to scores of
120-
// the same length as `tokens`. Until logprob support lands, signal that the
121-
// model-backed path is unavailable so callers fall back to the heuristic.
122-
return nil, fmt.Errorf("ollama: per-token logprobs not yet implemented for model %q", o.Model)
121+
// Per-token logprob extraction is pending Ollama API stabilisation.
122+
// Signal unavailability so callers fall back to the heuristic scorer.
123+
return nil, fmt.Errorf("ollama: per-token logprobs not yet available for model %q", o.Model)
123124
}

0 commit comments

Comments
 (0)