-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapabilities_test.go
More file actions
153 lines (143 loc) · 4.66 KB
/
Copy pathcapabilities_test.go
File metadata and controls
153 lines (143 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package llm
import (
"testing"
)
func TestParseOpenRouterModels(t *testing.T) {
body := []byte(`{
"data": [
{
"id": "anthropic/claude-sonnet-4.5",
"name": "Claude Sonnet 4.5",
"description": "A balanced frontier model for agentic coding and tool use.",
"context_length": 200000,
"architecture": {
"input_modalities": ["text", "image", "file"],
"output_modalities": ["text"]
},
"pricing": {
"prompt": "0.000003",
"completion": "0.000015"
},
"supported_parameters": ["tools", "tool_choice", "reasoning"]
},
{
"id": "google/gemini-2.0-flash-exp:free",
"context_length": 1048576,
"architecture": {
"input_modalities": ["text", "image"],
"output_modalities": ["text"]
},
"pricing": {
"prompt": "0",
"completion": "0"
},
"supported_parameters": ["tools"]
},
{
"id": "deepseek/deepseek-chat-v3.1",
"context_length": 65536,
"architecture": {
"input_modalities": ["text"],
"output_modalities": ["text"]
},
"pricing": {
"prompt": "0.00000027",
"completion": "0.0000011"
},
"supported_parameters": ["tools"]
}
]
}`)
caps, err := parseOpenRouterModels(body)
if err != nil {
t.Fatalf("parse: %v", err)
}
if len(caps) != 3 {
t.Fatalf("want 3 models, got %d", len(caps))
}
claude := caps["anthropic/claude-sonnet-4.5"]
if claude.Name != "Claude Sonnet 4.5" {
t.Errorf("claude name: want OpenRouter display name, got %q", claude.Name)
}
if claude.Description != "A balanced frontier model for agentic coding and tool use." {
t.Errorf("claude description not parsed: %q", claude.Description)
}
if !claude.Vision {
t.Error("claude should have vision")
}
if !claude.Tools {
t.Error("claude should support tools")
}
if !claude.Reasoning {
t.Error("claude should support reasoning")
}
if claude.PromptPrice != 3.0 {
t.Errorf("claude prompt price: want 3.0 (USD/M), got %v", claude.PromptPrice)
}
if claude.CompletionPrice != 15.0 {
t.Errorf("claude completion price: want 15.0, got %v", claude.CompletionPrice)
}
if claude.ContextLength != 200000 {
t.Errorf("claude context: want 200000, got %d", claude.ContextLength)
}
gemini := caps["google/gemini-2.0-flash-exp:free"]
if !gemini.Free() {
t.Error("gemini:free should be Free()")
}
if !gemini.Vision {
t.Error("gemini should have vision")
}
if gemini.Reasoning {
t.Error("gemini should not report reasoning (not in supported_parameters)")
}
deepseek := caps["deepseek/deepseek-chat-v3.1"]
if deepseek.Vision {
t.Error("deepseek chat should not have vision")
}
if !deepseek.Tools {
t.Error("deepseek should support tools")
}
// 0.00000027 * 1M = 0.27
if deepseek.PromptPrice < 0.269 || deepseek.PromptPrice > 0.271 {
t.Errorf("deepseek prompt price: want ~0.27, got %v", deepseek.PromptPrice)
}
}
func TestCapabilitiesFree(t *testing.T) {
tests := []struct {
name string
caps Capabilities
want bool
}{
{"explicit zero", Capabilities{}, true},
{"prompt only paid", Capabilities{PromptPrice: 1.0}, false},
{"completion only paid", Capabilities{CompletionPrice: 0.5}, false},
{"both paid", Capabilities{PromptPrice: 1, CompletionPrice: 1}, false},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if got := tc.caps.Free(); got != tc.want {
t.Errorf("Free() = %v, want %v", got, tc.want)
}
})
}
}
func TestExtractOpenRouterPageDescriptionUsesFullPayload(t *testing.T) {
current := "NVIDIA Nemotron 3 Nano Omni is a 30B-A3B open multimodal model designed to function as a perception and context sub-agent in enterprise agent systems. It accepts text, image, video, and..."
full := "NVIDIA Nemotron 3 Nano Omni is a 30B-A3B open multimodal model designed to function as a perception and context sub-agent in enterprise agent systems. It accepts text, image, video, and audio inputs and produces text output, enabling agents to perceive and reason across modalities in a single inference loop."
body := []byte(`prefix {\"description\":\"Short page meta.\"} middle {\"description\":\"` + full + `\"} suffix`)
got := extractOpenRouterPageDescription(body, current)
if got != full {
t.Fatalf("description mismatch:\nwant %q\ngot %q", full, got)
}
}
func TestOpenRouterDescriptionLooksTruncated(t *testing.T) {
if !OpenRouterDescriptionLooksTruncated("accepts text, image, video, and...") {
t.Fatal("ASCII ellipsis should be treated as truncated")
}
if !OpenRouterDescriptionLooksTruncated("accepts text, image, video, and…") {
t.Fatal("unicode ellipsis should be treated as truncated")
}
if OpenRouterDescriptionLooksTruncated("Full sentence.") {
t.Fatal("complete sentence should not be treated as truncated")
}
}