diff options
Diffstat (limited to 'cmd/mockupstream')
| -rw-r--r-- | cmd/mockupstream/main.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/cmd/mockupstream/main.go b/cmd/mockupstream/main.go index cf695bb..7dd5bbf 100644 --- a/cmd/mockupstream/main.go +++ b/cmd/mockupstream/main.go @@ -14,13 +14,44 @@ func main() { address := flag.String("address", "127.0.0.1:18080", "listen address") flag.Parse() mux := http.NewServeMux() + mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) }) + mux.HandleFunc("GET /v1/models", models) mux.HandleFunc("POST /v1/chat/completions", openAI) + mux.HandleFunc("POST /v1/embeddings", embeddings) mux.HandleFunc("POST /v1/messages", anthropic) server := &http.Server{Addr: *address, Handler: mux, ReadHeaderTimeout: 5 * time.Second} log.Printf("mock upstream listening on http://%s", *address) log.Fatal(server.ListenAndServe()) } +func models(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(map[string]any{ + "object": "list", + "data": []any{ + map[string]any{"id": "text-embedding-e2e", "object": "model"}, + map[string]any{"id": "chat-e2e", "object": "model"}, + }, + }) +} + +func embeddings(w http.ResponseWriter, r *http.Request) { + var request struct { + Model string `json:"model"` + Input json.RawMessage `json:"input"` + } + if json.NewDecoder(r.Body).Decode(&request) != nil || request.Model == "" || len(request.Input) == 0 { + http.Error(w, "invalid JSON", http.StatusBadRequest) + return + } + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(map[string]any{ + "object": "list", "model": request.Model, + "data": []any{map[string]any{"object": "embedding", "index": 0, "embedding": []float64{0.125, -0.25, 0.5, 0.75}}}, + "usage": map[string]int{"prompt_tokens": 6, "total_tokens": 6}, + }) +} + func openAI(w http.ResponseWriter, r *http.Request) { var request struct { Model string `json:"model"` |
