(t *testing.T)
| 102 | } |
| 103 | |
| 104 | func 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 | |
| 147 | func TestToolResultSize(t *testing.T) { |
| 148 | t.Parallel() |
nothing calls this directly
no test coverage detected