MCPcopy Index your code
hub / github.com/coder/coder / EstimatePromptSize

Function EstimatePromptSize

coderd/x/chatd/chatloop/metrics.go:180–188  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

178// fantasy prompt by summing the text content lengths of all
179// message parts. This avoids JSON marshaling overhead.
180func 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.

Callers 2

TestEstimatePromptSizeFunction · 0.92
RunFunction · 0.85

Calls 1

ContentPartSizeFunction · 0.85

Tested by 1

TestEstimatePromptSizeFunction · 0.74