f235b8ce90
- Move cmd/agentu/main.go → main.go (project root) - Move internal/llm/ → pkg/llm/ (leaf package, no internal deps) - Move internal/config/ → pkg/config/ (leaf package, no internal deps) - Update all import paths: agentu/internal/llm → agentu/pkg/llm (14 files) - Update all import paths: agentu/internal/config → agentu/pkg/config (3 files) - Update README: build/run commands, CLI flags section - agent/session/tools/tui stay in internal/ (app-specific business logic) Build: go build . | Test: go test ./... | Vet: go vet ./...
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package llm
|
|
|
|
import "testing"
|
|
|
|
func TestEstimateTokensEmpty(t *testing.T) {
|
|
if got := EstimateTokens(nil, nil); got != 0 {
|
|
t.Fatalf("EstimateTokens(nil, nil) = %d, want 0", got)
|
|
}
|
|
}
|
|
|
|
func TestEstimateTokens(t *testing.T) {
|
|
shortMessages := []Message{{Role: RoleUser, Content: "hello"}}
|
|
short := EstimateTokens(shortMessages, nil)
|
|
if short <= 4 {
|
|
t.Fatalf("short estimate = %d, want message framing plus content", short)
|
|
}
|
|
if short > 50 {
|
|
t.Fatalf("short estimate = %d, looks too high for one short message", short)
|
|
}
|
|
|
|
longMessages := []Message{
|
|
{Role: RoleUser, Content: "hello"},
|
|
{Role: RoleAssistant, Content: "This is a longer response with enough content to exceed the short estimate."},
|
|
}
|
|
long := EstimateTokens(longMessages, nil)
|
|
if long <= short {
|
|
t.Fatalf("long estimate = %d, want > short estimate %d", long, short)
|
|
}
|
|
|
|
withTools := EstimateTokens(shortMessages, []Tool{{
|
|
Type: "function",
|
|
Function: ToolFunction{
|
|
Name: "file_read",
|
|
Description: "Read a file",
|
|
Parameters: []byte(`{"type":"object"}`),
|
|
},
|
|
}})
|
|
if withTools <= short {
|
|
t.Fatalf("withTools estimate = %d, want > short estimate %d", withTools, short)
|
|
}
|
|
|
|
if msgTokens := estimateMessageTokens(shortMessages[0]); msgTokens <= 4 {
|
|
t.Fatalf("estimateMessageTokens = %d, want message framing plus content", msgTokens)
|
|
}
|
|
}
|