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

Function TestEstimatePromptSize

coderd/x/chatd/chatloop/metrics_test.go:104–145  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

102}
103
104func TestEstimatePromptSize(t *testing.T) {
105 t.Parallel()
106
107 messages := []fantasy.Message{
108 {
109 Role: fantasy.MessageRoleSystem,
110 Content: []fantasy.MessagePart{
111 fantasy.TextPart{Text: "You are a helpful assistant."},
112 },
113 },
114 {
115 Role: fantasy.MessageRoleUser,
116 Content: []fantasy.MessagePart{
117 fantasy.TextPart{Text: "Hello world"},
118 fantasy.ReasoningPart{Text: "thinking..."},
119 fantasy.FilePart{Data: []byte("filedata")},
120 },
121 },
122 {
123 Role: fantasy.MessageRoleAssistant,
124 Content: []fantasy.MessagePart{
125 fantasy.TextPart{Text: "Hi there!"},
126 fantasy.ToolCallPart{Input: `{"file":"main.go"}`},
127 },
128 },
129 {
130 Role: fantasy.MessageRoleTool,
131 Content: []fantasy.MessagePart{
132 fantasy.ToolResultPart{
133 Output: fantasy.ToolResultOutputContentText{Text: "result"},
134 },
135 },
136 },
137 }
138
139 size := chatloop.EstimatePromptSize(messages)
140 // "You are a helpful assistant." (28) + "Hello world" (11) +
141 // "thinking..." (11) + "filedata" (8) +
142 // "Hi there!" (9) + `{"file":"main.go"}` (18) +
143 // "result" (6) = 91
144 assert.Equal(t, 91, size)
145}
146
147func TestToolResultSize(t *testing.T) {
148 t.Parallel()

Callers

nothing calls this directly

Calls 2

EstimatePromptSizeFunction · 0.92
EqualMethod · 0.45

Tested by

no test coverage detected