feat(generation): score articles with selected relevance model (#48)
This commit is contained in:
@ -12,6 +12,15 @@ import (
|
||||
)
|
||||
|
||||
func preferencesError(c *gin.Context, err error) {
|
||||
if errors.Is(err, models.ErrRankingModelIncompatible) {
|
||||
c.JSON(400, gin.H{"error": "ranking_model_incompatible", "reason": "ranking_structured_output_unsupported", "message": "Ce modèle reste disponible pour la synthèse mais sa sortie JSON structurée n’est pas prise en charge pour le classement."})
|
||||
return
|
||||
}
|
||||
|
||||
if errors.Is(err, models.ErrRankingModelUnavailable) {
|
||||
c.JSON(400, gin.H{"error": "ranking_model_unavailable"})
|
||||
return
|
||||
}
|
||||
if errors.Is(err, models.ErrInvalidPromptBudget) {
|
||||
c.JSON(400, gin.H{"error": "invalid_prompt_budget"})
|
||||
return
|
||||
@ -42,6 +51,7 @@ func (h *Handler) GetMyPreferences(c *gin.Context) {
|
||||
|
||||
func (h *Handler) UpdateMyPreferences(c *gin.Context) {
|
||||
var body struct {
|
||||
RankingModelID *string `json:"ranking_model_id" binding:"omitempty,uuid"`
|
||||
Language string `json:"language" binding:"required,oneof=fr en"`
|
||||
RankingMode string `json:"ranking_mode" binding:"required,oneof=title title_content"`
|
||||
SummaryModelID *string `json:"summary_model_id" binding:"omitempty,uuid"`
|
||||
@ -51,7 +61,7 @@ func (h *Handler) UpdateMyPreferences(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid preferences"})
|
||||
return
|
||||
}
|
||||
req := models.UserPreferences{Language: body.Language, RankingMode: body.RankingMode, SummaryModelID: body.SummaryModelID, SummaryPromptTokenBudget: models.DefaultSummaryPromptTokenBudget}
|
||||
req := models.UserPreferences{RankingModelID: body.RankingModelID, Language: body.Language, RankingMode: body.RankingMode, SummaryModelID: body.SummaryModelID, SummaryPromptTokenBudget: models.DefaultSummaryPromptTokenBudget}
|
||||
if len(body.Budget) > 0 && (string(body.Budget) == "null" || json.Unmarshal(body.Budget, &req.SummaryPromptTokenBudget) != nil || req.SummaryPromptTokenBudget < 1 || req.SummaryPromptTokenBudget > models.MaxSummaryPromptTokenBudget) {
|
||||
c.JSON(400, gin.H{"error": "invalid_prompt_budget"})
|
||||
return
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/tradarr/backend/internal/httputil"
|
||||
"github.com/tradarr/backend/internal/models"
|
||||
"github.com/tradarr/backend/internal/rankingcapability"
|
||||
"github.com/tradarr/backend/internal/summarybudget"
|
||||
)
|
||||
|
||||
@ -23,21 +24,31 @@ func catalogHTTPError(c *gin.Context, err error) {
|
||||
}
|
||||
}
|
||||
func (h *Handler) ListMySummaryModels(c *gin.Context) {
|
||||
role := c.Query("role")
|
||||
if role != "" && role != "summary" && role != "ranking" {
|
||||
c.JSON(400, gin.H{"error": "invalid model role"})
|
||||
return
|
||||
}
|
||||
|
||||
rows, err := h.repo.ListSummaryModels(true)
|
||||
if err != nil {
|
||||
catalogHTTPError(c, err)
|
||||
return
|
||||
}
|
||||
type option struct {
|
||||
PromptCapacity *summarybudget.Profile `json:"prompt_capacity"`
|
||||
ID string `json:"id"`
|
||||
Provider string `json:"provider"`
|
||||
Model string `json:"model"`
|
||||
Label string `json:"label"`
|
||||
RankingCapability rankingcapability.Capability `json:"ranking_capability"`
|
||||
PromptCapacity *summarybudget.Profile `json:"prompt_capacity"`
|
||||
ID string `json:"id"`
|
||||
Provider string `json:"provider"`
|
||||
Model string `json:"model"`
|
||||
Label string `json:"label"`
|
||||
}
|
||||
result := []option{}
|
||||
for _, row := range rows {
|
||||
result = append(result, option{row.PromptCapacity, row.ID, row.Provider, row.Model, row.Label})
|
||||
if role == "ranking" && !row.RankingCapability.Selectable {
|
||||
continue
|
||||
}
|
||||
result = append(result, option{RankingCapability: row.RankingCapability, PromptCapacity: row.PromptCapacity, ID: row.ID, Provider: row.Provider, Model: row.Model, Label: row.Label})
|
||||
}
|
||||
httputil.OK(c, result)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user