EstimatePromptSize returns a cheap byte-size estimate of a fantasy prompt by summing the text content lengths of all message parts. This avoids JSON marshaling overhead.
(messages []fantasy.Message)
| 178 | // fantasy prompt by summing the text content lengths of all |
| 179 | // message parts. This avoids JSON marshaling overhead. |
| 180 | func EstimatePromptSize(messages []fantasy.Message) int { |
| 181 | var size int |
| 182 | for _, msg := range messages { |
| 183 | for _, part := range msg.Content { |
| 184 | size += ContentPartSize(part) |
| 185 | } |
| 186 | } |
| 187 | return size |
| 188 | } |
| 189 | |
| 190 | // ContentPartSize returns the byte length of a MessagePart's |
| 191 | // primary text or data field. |