fix(tokens): count attached images in Estimate (~1500 tokens each)

This commit is contained in:
sausheong committed 2026-06-13 15:27:43 +08:00
1 parent 8c9bc2963d
commit 22f4329f44
2 files changed
+22

No files matched your search

+12
View File
@@ -4,6 +4,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/sausheong/harness/llm"
)
@@ -97,6 +98,17 @@ func TestContextWindowProxyProviderDetectedByModelFamily(t *testing.T) {
}
}
func TestEstimate_CountsImages(t *testing.T) {
textOnly := []llm.Message{{Role: "user", Content: "hello"}}
withImg := []llm.Message{{Role: "user", Content: "hello", Images: []llm.ImageContent{
{MimeType: "image/png", Data: []byte("x")},
{MimeType: "image/png", Data: []byte("y")},
}}}
base := Estimate(textOnly, "", nil)
withImages := Estimate(withImg, "", nil)
require.GreaterOrEqual(t, withImages-base, 2*perImageTokens)
}
func TestContextWindowOllamaDefault(t *testing.T) {
// Without RegisterOllamaContext call, ollama models fall back to a sane default
assert.Equal(t, 32000, ContextWindow("local/qwen2.5:3b-instruct"))