reply func(http.ResponseWriter, ModelFakeCall)
}
-// Call returns call number n.
-func (f *ModelFake) Call(n int) ModelFakeCall {
- f.mutex.Lock()
- defer f.mutex.Unlock()
+func newModelFake(t *testing.T) *ModelFake {
+ t.Helper()
- return f.calls[n]
-}
+ f := &ModelFake{
+ reply: func(w http.ResponseWriter, _ ModelFakeCall) {
+ modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("a line")}, 100, 0, 5))
+ },
+ }
-// Calls returns the number of calls.
-func (f *ModelFake) Calls() int {
- f.mutex.Lock()
- defer f.mutex.Unlock()
+ f.Server = httptest.NewServer(http.HandlerFunc(f.serve))
+ t.Cleanup(f.Close)
- return len(f.calls)
+ return f
}
func (f *ModelFake) serve(w http.ResponseWriter, r *http.Request) {
reply(w, call)
}
-func newModelFake(t *testing.T) *ModelFake {
- t.Helper()
-
- f := &ModelFake{
- reply: func(w http.ResponseWriter, _ ModelFakeCall) {
- modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("a line")}, 100, 0, 5))
- },
- }
-
- f.Server = httptest.NewServer(http.HandlerFunc(f.serve))
- t.Cleanup(f.Close)
+// Call returns call number n.
+func (f *ModelFake) Call(n int) ModelFakeCall {
+ f.mutex.Lock()
+ defer f.mutex.Unlock()
- return f
+ return f.calls[n]
}
-func modelTestRequest() ModelRequest {
- return ModelRequest{
- Model: "gpt-test",
- Effort: "low",
- Input: []any{modelUserMessage("hello")},
- }
+// Calls returns the number of calls.
+func (f *ModelFake) Calls() int {
+ f.mutex.Lock()
+ defer f.mutex.Unlock()
+
+ return len(f.calls)
}
// modelWriteEvents writes events as a server-sent event stream.
}
}
-func modelMessageItem(text string) map[string]any {
- return map[string]any{
- "type": "message",
- "role": "assistant",
- "content": []any{
- map[string]any{"type": "output_text", "text": text},
- },
- }
-}
-
func modelCompletedEvent(output []any, input, cached, out int) map[string]any {
if output == nil {
output = []any{}
}
}
+func modelMessageItem(text string) map[string]any {
+ return map[string]any{
+ "type": "message",
+ "role": "assistant",
+ "content": []any{
+ map[string]any{"type": "output_text", "text": text},
+ },
+ }
+}
+
+func modelTestRequest() ModelRequest {
+ return ModelRequest{
+ Model: "gpt-test",
+ Effort: "low",
+ Input: []any{modelUserMessage("hello")},
+ }
+}
+
func modelReadUsage(t *testing.T, path string) []ModelUsageRecord {
t.Helper()