feat(generation): score articles with selected relevance model (#48)
This commit is contained in:
21
backend/internal/ai/scoring_schema.go
Normal file
21
backend/internal/ai/scoring_schema.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user