Skip to content

Commit

Permalink
[Add] 😅 API Path to fight HF block
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry-zklcdc committed Jan 14, 2024
1 parent c578652 commit 098e8ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/v1/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ var STOPFLAG = "stop"
func ChatHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
w.WriteHeader(http.StatusMethodNotAllowed)
w.Write([]byte("Method Not Allowed"))
return
}

if apikey != "" {
if r.Header.Get("Authorization") != "Bearer "+apikey {
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte("Unauthorized"))
return
}
}
Expand Down Expand Up @@ -65,6 +67,7 @@ func ChatHandler(w http.ResponseWriter, r *http.Request) {

if resq.Model != binglib.BALANCED && resq.Model != binglib.BALANCED_OFFLINE && resq.Model != binglib.CREATIVE && resq.Model != binglib.CREATIVE_OFFLINE && resq.Model != binglib.PRECISE && resq.Model != binglib.PRECISE_OFFLINE {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("Model Not Found"))
return
}

Expand Down Expand Up @@ -194,12 +197,14 @@ func ChatHandler(w http.ResponseWriter, r *http.Request) {
func ImageHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
w.WriteHeader(http.StatusMethodNotAllowed)
w.Write([]byte("Method Not Allowed"))
return
}

if apikey != "" {
if r.Header.Get("Authorization") != "Bearer "+apikey {
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte("Unauthorized"))
return
}
}
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
func main() {
http.HandleFunc("/v1/chat/completions", v1.ChatHandler)
http.HandleFunc("/v1/images/generations", v1.ImageHandler)
http.HandleFunc("/api/v1/chat/completions", v1.ChatHandler)
http.HandleFunc("/api/v1/images/generations", v1.ImageHandler)

http.HandleFunc("/sysconf", api.SysConf)

Expand Down

0 comments on commit 098e8ba

Please sign in to comment.