X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/80e348724041a694002fc38f57e8868b9b9a2be9..0979625154094df73577d6e2be2d0e9a0a87306c:/model_fake_helper_test.go diff --git a/model_fake_helper_test.go b/model_fake_helper_test.go index f9d1451..af94776 100644 --- a/model_fake_helper_test.go +++ b/model_fake_helper_test.go @@ -49,22 +49,6 @@ func newModelFake(t *testing.T) *ModelFake { return f } -// Call returns call number n. -func (f *ModelFake) Call(n int) ModelFakeCall { - f.mutex.Lock() - defer f.mutex.Unlock() - - return f.calls[n] -} - -// Calls returns the number of calls. -func (f *ModelFake) Calls() int { - f.mutex.Lock() - defer f.mutex.Unlock() - - return len(f.calls) -} - func (f *ModelFake) serve(w http.ResponseWriter, r *http.Request) { raw, err := io.ReadAll(r.Body) if err != nil { @@ -95,12 +79,20 @@ func (f *ModelFake) serve(w http.ResponseWriter, r *http.Request) { reply(w, call) } -func modelTestRequest() ModelRequest { - return ModelRequest{ - Model: "gpt-test", - Effort: "low", - Input: []any{modelUserMessage("hello")}, - } +// Call returns call number n. +func (f *ModelFake) Call(n int) ModelFakeCall { + f.mutex.Lock() + defer f.mutex.Unlock() + + return f.calls[n] +} + +// 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. @@ -120,16 +112,6 @@ func modelWriteEvents(w http.ResponseWriter, events ...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 modelCompletedEvent(output []any, input, cached, out int) map[string]any { if output == nil { output = []any{} @@ -148,6 +130,24 @@ func modelCompletedEvent(output []any, input, cached, out int) map[string]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()