Skip to content

Commit 7b1c366

Browse files
committed
fix(vertex): error when an unknown path is requested
1 parent 23829a6 commit 7b1c366

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

vertex/vertex.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ func vertexMiddleware(region, projectID string) sdkoption.Middleware {
9191
body, _ = sjson.SetBytes(body, "anthropic_version", DefaultVersion)
9292
}
9393

94-
if r.URL.Path == "/v1/messages" && r.Method == http.MethodPost {
94+
switch {
95+
case r.URL.Path == "/v1/messages" && r.Method == http.MethodPost:
9596
if projectID == "" {
9697
return nil, fmt.Errorf("no projectId was given and it could not be resolved from credentials")
9798
}
@@ -107,14 +108,16 @@ func vertexMiddleware(region, projectID string) sdkoption.Middleware {
107108
}
108109

109110
r.URL.Path = fmt.Sprintf("/v1/projects/%s/locations/%s/publishers/anthropic/models/%s:%s", projectID, region, model, specifier)
110-
}
111111

112-
if r.URL.Path == "/v1/messages/count_tokens" && r.Method == http.MethodPost {
112+
case r.URL.Path == "/v1/messages/count_tokens" && r.Method == http.MethodPost:
113113
if projectID == "" {
114114
return nil, fmt.Errorf("no projectId was given and it could not be resolved from credentials")
115115
}
116116

117117
r.URL.Path = fmt.Sprintf("/v1/projects/%s/locations/%s/publishers/anthropic/models/count-tokens:rawPredict", projectID, region)
118+
119+
default:
120+
return nil, fmt.Errorf("vertex middleware does not support %s %s", r.Method, r.URL.Path)
118121
}
119122

120123
reader := bytes.NewReader(body)

0 commit comments

Comments
 (0)