ItemFromRequestRow builds an eval Item from a ledger row (requires ai_request_json). If the row has selected_backend (successful completion), it is copied to expected_backend for routing regression.
(row requests.RequestRow)
| 11 | // ItemFromRequestRow builds an eval Item from a ledger row (requires ai_request_json). |
| 12 | // If the row has selected_backend (successful completion), it is copied to expected_backend for routing regression. |
| 13 | func ItemFromRequestRow(row requests.RequestRow) (Item, error) { |
| 14 | if len(row.AIRequestJSON) == 0 { |
| 15 | return Item{}, fmt.Errorf("request %s: missing ai_request_json", row.RequestID) |
| 16 | } |
| 17 | var req types.AIRequest |
| 18 | if err := json.Unmarshal(row.AIRequestJSON, &req); err != nil { |
| 19 | return Item{}, fmt.Errorf("request %s: %w", row.RequestID, err) |
| 20 | } |
| 21 | it := Item{ |
| 22 | TenantID: req.TenantID, |
| 23 | TaskType: req.TaskType, |
| 24 | Priority: req.Priority, |
| 25 | RequestType: req.RequestType, |
| 26 | PipelineRef: req.PipelineRef, |
| 27 | Context: req.Context, |
| 28 | Input: req.Input, |
| 29 | Options: map[string]any{ |
| 30 | "stream": req.Options.Stream, |
| 31 | "max_tokens": req.Options.MaxTokens, |
| 32 | }, |
| 33 | } |
| 34 | if row.SelectedBackend != "" { |
| 35 | it.ExpectedBackend = row.SelectedBackend |
| 36 | } |
| 37 | return it, nil |
| 38 | } |
| 39 | |
| 40 | // ItemsFromRequestRows converts ledger rows to eval items, skipping rows that fail conversion. |
| 41 | func ItemsFromRequestRows(rows []requests.RequestRow) ([]Item, []error) { |
no outgoing calls
no test coverage detected