From b79cb55a75ba949a5b525ccaaaf3452b92fc6c4b Mon Sep 17 00:00:00 2001 From: cubatic45 Date: Wed, 6 Mar 2024 15:49:12 +0800 Subject: [PATCH] add get models --- go.mod | 2 +- main.go | 6 ++++-- model.go | 7 +++++++ 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 model.go diff --git a/go.mod b/go.mod index 31fdf43..05ca703 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/cubatic45/copi -go 1.21.6 +go 1.22.0 require ( github.com/mitchellh/go-homedir v1.1.0 diff --git a/main.go b/main.go index 252ea2c..f2a1cf1 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,8 @@ func main() { fmt.Printf("copilotToken: %s\n", copilotToken) fmt.Printf("copilotTokenURL: %s\n", copilotTokenURL) Init() - http.HandleFunc("/", handleProxy) - http.ListenAndServe(":8081", nil) + mux := http.NewServeMux() + mux.HandleFunc("GET /v1/models", handleModel) + mux.HandleFunc("POST /v1/chat/completions", handleProxy) + http.ListenAndServe(":8081", mux) } diff --git a/model.go b/model.go new file mode 100644 index 0000000..47f1807 --- /dev/null +++ b/model.go @@ -0,0 +1,7 @@ +package main + +import "net/http" + +func handleModel(w http.ResponseWriter, r *http.Request) { + w.Write([]byte(`{"object":"list","data":[{"id":"gpt-3.5-turbo","object":"model","created":1677610602,"owned_by":"openai"},{"id":"gpt-4","object":"model","created":1677610602,"owned_by":"openai"}]}`)) +}