messageJSONByteCount approximates the message's contribution to the advisor prompt using the length of its JSON serialization. The JSON wrapping ({"role":"...","content":[{"type":"text","text":"..."}]}) is counted alongside the user-visible text; the measurement is intended for budget accounting, no
(msg fantasy.Message)
| 192 | // counted alongside the user-visible text; the measurement is intended |
| 193 | // for budget accounting, not for reporting visible character counts. |
| 194 | func messageJSONByteCount(msg fantasy.Message) int { |
| 195 | data, err := json.Marshal(msg) |
| 196 | if err == nil { |
| 197 | return len(data) |
| 198 | } |
| 199 | |
| 200 | total := 0 |
| 201 | for _, part := range msg.Content { |
| 202 | partData, partErr := json.Marshal(part) |
| 203 | if partErr == nil { |
| 204 | total += len(partData) |
| 205 | } |
| 206 | } |
| 207 | return total |
| 208 | } |
no test coverage detected