mirror of
https://github.com/linux-do/new-api.git
synced 2025-11-09 07:33:41 +08:00
feat: 支持vertex ai渠道多个部署地区
This commit is contained in:
@@ -62,6 +62,7 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
|
||||
if err := json.Unmarshal([]byte(info.ApiKey), adc); err != nil {
|
||||
return "", fmt.Errorf("failed to decode credentials file: %w", err)
|
||||
}
|
||||
region := GetModelRegion(info.ApiVersion, info.OriginModelName)
|
||||
a.AccountCredentials = *adc
|
||||
suffix := ""
|
||||
if a.RequestMode == RequestModeGemini {
|
||||
@@ -72,9 +73,9 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
|
||||
}
|
||||
return fmt.Sprintf(
|
||||
"https://%s-aiplatform.googleapis.com/v1/projects/%s/locations/%s/publishers/google/models/%s:%s",
|
||||
info.ApiVersion,
|
||||
region,
|
||||
adc.ProjectID,
|
||||
info.ApiVersion,
|
||||
region,
|
||||
info.UpstreamModelName,
|
||||
suffix,
|
||||
), nil
|
||||
@@ -89,18 +90,18 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
|
||||
}
|
||||
return fmt.Sprintf(
|
||||
"https://%s-aiplatform.googleapis.com/v1/projects/%s/locations/%s/publishers/anthropic/models/%s:%s",
|
||||
info.ApiVersion,
|
||||
region,
|
||||
adc.ProjectID,
|
||||
info.ApiVersion,
|
||||
region,
|
||||
info.UpstreamModelName,
|
||||
suffix,
|
||||
), nil
|
||||
} else if a.RequestMode == RequestModeLlama {
|
||||
return fmt.Sprintf(
|
||||
"https://%s-aiplatform.googleapis.com/v1beta1/projects/%s/locations/%s/endpoints/openapi/chat/completions",
|
||||
info.ApiVersion,
|
||||
region,
|
||||
adc.ProjectID,
|
||||
info.ApiVersion,
|
||||
region,
|
||||
), nil
|
||||
}
|
||||
return "", errors.New("unsupported request mode")
|
||||
|
||||
16
relay/channel/vertex/relay-vertex.go
Normal file
16
relay/channel/vertex/relay-vertex.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package vertex
|
||||
|
||||
import "one-api/common"
|
||||
|
||||
func GetModelRegion(other string, localModelName string) string {
|
||||
// if other is json string
|
||||
if common.IsJsonStr(other) {
|
||||
m := common.StrToMap(other)
|
||||
if m[localModelName] != nil {
|
||||
return m[localModelName].(string)
|
||||
} else {
|
||||
return m["default"].(string)
|
||||
}
|
||||
}
|
||||
return other
|
||||
}
|
||||
@@ -83,7 +83,7 @@ func createSignedJWT(email, privateKeyPEM string) (string, error) {
|
||||
"iss": email,
|
||||
"scope": "https://www.googleapis.com/auth/cloud-platform",
|
||||
"aud": "https://www.googleapis.com/oauth2/v4/token",
|
||||
"exp": now.Add(time.Minute * 30).Unix(),
|
||||
"exp": now.Add(time.Minute * 35).Unix(),
|
||||
"iat": now.Unix(),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user