Skip to content

Commit aab82f2

Browse files
authored
Merge pull request #1817 from wzxjohn/hotfix/relay_vertex_claude
fix(relay): wrong URL for claude model in GCP Vertex AI
2 parents 933ab43 + 8d92ce3 commit aab82f2

File tree

1 file changed

+48
-21
lines changed

1 file changed

+48
-21
lines changed

relay/channel/vertex/adaptor.go

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -91,50 +91,77 @@ func (a *Adaptor) getRequestUrl(info *relaycommon.RelayInfo, modelName, suffix s
9191
}
9292
a.AccountCredentials = *adc
9393

94-
if a.RequestMode == RequestModeLlama {
94+
if a.RequestMode == RequestModeGemini {
95+
if region == "global" {
96+
return fmt.Sprintf(
97+
"https://aiplatform.googleapis.com/v1/projects/%s/locations/global/publishers/google/models/%s:%s",
98+
adc.ProjectID,
99+
modelName,
100+
suffix,
101+
), nil
102+
} else {
103+
return fmt.Sprintf(
104+
"https://%s-aiplatform.googleapis.com/v1/projects/%s/locations/%s/publishers/google/models/%s:%s",
105+
region,
106+
adc.ProjectID,
107+
region,
108+
modelName,
109+
suffix,
110+
), nil
111+
}
112+
} else if a.RequestMode == RequestModeClaude {
113+
if region == "global" {
114+
return fmt.Sprintf(
115+
"https://aiplatform.googleapis.com/v1/projects/%s/locations/global/publishers/anthropic/models/%s:%s",
116+
adc.ProjectID,
117+
modelName,
118+
suffix,
119+
), nil
120+
} else {
121+
return fmt.Sprintf(
122+
"https://%s-aiplatform.googleapis.com/v1/projects/%s/locations/%s/publishers/anthropic/models/%s:%s",
123+
region,
124+
adc.ProjectID,
125+
region,
126+
modelName,
127+
suffix,
128+
), nil
129+
}
130+
} else if a.RequestMode == RequestModeLlama {
95131
return fmt.Sprintf(
96132
"https://%s-aiplatform.googleapis.com/v1beta1/projects/%s/locations/%s/endpoints/openapi/chat/completions",
97133
region,
98134
adc.ProjectID,
99135
region,
100136
), nil
101137
}
102-
103-
if region == "global" {
104-
return fmt.Sprintf(
105-
"https://aiplatform.googleapis.com/v1/projects/%s/locations/global/publishers/google/models/%s:%s",
106-
adc.ProjectID,
107-
modelName,
108-
suffix,
109-
), nil
138+
} else {
139+
var keyPrefix string
140+
if strings.HasSuffix(suffix, "?alt=sse") {
141+
keyPrefix = "&"
110142
} else {
111-
return fmt.Sprintf(
112-
"https://%s-aiplatform.googleapis.com/v1/projects/%s/locations/%s/publishers/google/models/%s:%s",
113-
region,
114-
adc.ProjectID,
115-
region,
116-
modelName,
117-
suffix,
118-
), nil
143+
keyPrefix = "?"
119144
}
120-
} else {
121145
if region == "global" {
122146
return fmt.Sprintf(
123-
"https://aiplatform.googleapis.com/v1/publishers/google/models/%s:%s?key=%s",
147+
"https://aiplatform.googleapis.com/v1/publishers/google/models/%s:%s%skey=%s",
124148
modelName,
125149
suffix,
150+
keyPrefix,
126151
info.ApiKey,
127152
), nil
128153
} else {
129154
return fmt.Sprintf(
130-
"https://%s-aiplatform.googleapis.com/v1/publishers/google/models/%s:%s?key=%s",
155+
"https://%s-aiplatform.googleapis.com/v1/publishers/google/models/%s:%s%skey=%s",
131156
region,
132157
modelName,
133158
suffix,
159+
keyPrefix,
134160
info.ApiKey,
135161
), nil
136162
}
137163
}
164+
return "", errors.New("unsupported request mode")
138165
}
139166

140167
func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
@@ -188,7 +215,7 @@ func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Header, info *rel
188215
}
189216
req.Set("Authorization", "Bearer "+accessToken)
190217
}
191-
if a.AccountCredentials.ProjectID != "" {
218+
if a.AccountCredentials.ProjectID != "" {
192219
req.Set("x-goog-user-project", a.AccountCredentials.ProjectID)
193220
}
194221
return nil

0 commit comments

Comments
 (0)