fix: recognize '/v1' prefix
This commit is contained in:
@@ -91,7 +91,9 @@ func processRequest(c *gin.Context, upstream *OPENAI_UPSTREAM, record *Record, s
|
||||
out.Host = remote.Host
|
||||
out.URL.Scheme = remote.Scheme
|
||||
out.URL.Host = remote.Host
|
||||
out.URL.Path = in.URL.Path
|
||||
|
||||
out.URL.Path = upstream.URL.Path + strings.TrimPrefix(in.URL.Path, "/v1")
|
||||
|
||||
out.Header = http.Header{}
|
||||
out.Header.Set("Host", remote.Host)
|
||||
if upstream.SK == "asis" {
|
||||
|
||||
11
structure.go
11
structure.go
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
@@ -19,6 +20,7 @@ type OPENAI_UPSTREAM struct {
|
||||
SK string `yaml:"sk"`
|
||||
Endpoint string `yaml:"endpoint"`
|
||||
Timeout int64 `yaml:"timeout"`
|
||||
URL *url.URL
|
||||
}
|
||||
|
||||
func readConfig(filepath string) Config {
|
||||
@@ -50,5 +52,14 @@ func readConfig(filepath string) Config {
|
||||
config.DBAddr = "./db.sqlite"
|
||||
}
|
||||
|
||||
for i, upstream := range config.Upstreams {
|
||||
// parse upstream endpoint URL
|
||||
endpoint, err := url.Parse(upstream.Endpoint)
|
||||
if err != nil {
|
||||
log.Fatalf("Can't parse upstream endpoint URL '%s': %s", upstream.Endpoint, err)
|
||||
}
|
||||
config.Upstreams[i].URL = endpoint
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user