feat(generation): score articles with selected relevance model (#48)
This commit is contained in:
48
backend/internal/rankingcapability/capability.go
Normal file
48
backend/internal/rankingcapability/capability.go
Normal file
@ -0,0 +1,48 @@
|
||||
// Package rankingcapability describes the scoring role only. Unknown models
|
||||
// remain valid synthesis catalogue entries; discovery alone proves no capability.
|
||||
package rankingcapability
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Capability struct {
|
||||
Selectable bool `json:"selectable"`
|
||||
Mode string `json:"mode,omitempty"`
|
||||
Reason string `json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
// Deliberately exact model IDs: no guessed support for future/unknown names.
|
||||
// OpenAI: https://developers.openai.com/api/docs/guides/structured-outputs
|
||||
// Ollama local grammar: https://docs.ollama.com/capabilities/structured-outputs
|
||||
func Lookup(provider, model, endpoint string) Capability {
|
||||
supported := false
|
||||
switch provider {
|
||||
case "openai":
|
||||
switch model {
|
||||
case "gpt-4o-mini", "gpt-4o-mini-2024-07-18", "gpt-4o-2024-08-06", "gpt-4o-2024-11-20":
|
||||
supported = true
|
||||
}
|
||||
case "ollama":
|
||||
switch model {
|
||||
case "llama3", "llama3:8b", "llama3:70b", "qwen2.5:7b", "qwen3:8b":
|
||||
supported = true
|
||||
}
|
||||
if endpoint != "" {
|
||||
u, err := url.Parse(endpoint)
|
||||
if err != nil || u.Hostname() == "" || (u.Scheme != "http" && u.Scheme != "https") {
|
||||
supported = false
|
||||
} else {
|
||||
host := strings.ToLower(u.Hostname())
|
||||
if host == "ollama.com" || strings.HasSuffix(host, ".ollama.com") {
|
||||
supported = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if supported {
|
||||
return Capability{Selectable: true, Mode: "json_schema"}
|
||||
}
|
||||
return Capability{Reason: "ranking_structured_output_unsupported"}
|
||||
}
|
||||
15
backend/internal/rankingcapability/capability_test.go
Normal file
15
backend/internal/rankingcapability/capability_test.go
Normal file
@ -0,0 +1,15 @@
|
||||
package rankingcapability
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestScoringRequiresKnownStructuredModelAndAdapter(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
provider, model, endpoint string
|
||||
want bool
|
||||
}{{"openai", "gpt-4o-mini", "", true}, {"openai", "gpt-4o-mini-2024-07-18", "", true}, {"openai", "unknown-model", "", false}, {"ollama", "llama3", "http://ollama:11434", true}, {"ollama", "unknown-model", "http://ollama:11434", false}, {"ollama", "llama3", "https://ollama.com", false}, {"anthropic", "claude-sonnet-4-6", "", false}, {"gemini", "gemini-2.5-flash", "", false}, {"claudecode", "claude-sonnet-4-6", "", false}, {"other", "gpt-4o-mini", "", false}} {
|
||||
c := Lookup(tc.provider, tc.model, tc.endpoint)
|
||||
if c.Selectable != tc.want || (!tc.want && c.Reason == "") || (tc.want && c.Mode != "json_schema") {
|
||||
t.Fatalf("%+v => %+v", tc, c)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user