feat(generation): score articles with selected relevance model (#48)

This commit is contained in:
2026-11-25 18:09:36 +01:00
parent c5b8d0d4da
commit 90dd2a65d2
53 changed files with 1639 additions and 105 deletions

View File

@ -0,0 +1,21 @@
package ai
import "encoding/json"
// Native schema generation and local validation are complementary: count and
// index uniqueness are always checked locally, even after constrained decoding.
func titleScoreSchema(count int) json.RawMessage {
index := map[string]any{"type": "integer", "minimum": 0, "maximum": count - 1}
row := func(withScore bool) map[string]any {
properties := map[string]any{"index": index}
required := []string{"index"}
if withScore {
properties["score"] = map[string]any{"type": "number", "minimum": 0, "maximum": 100}
required = append(required, "score")
}
return map[string]any{"type": "object", "properties": properties, "required": required, "additionalProperties": false}
}
schema := map[string]any{"type": "object", "properties": map[string]any{"scores": map[string]any{"type": "array", "minItems": count, "maxItems": count, "items": map[string]any{"anyOf": []any{row(false), row(true)}}}}, "required": []string{"scores"}, "additionalProperties": false}
raw, _ := json.Marshal(schema)
return raw
}