Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions internal/backendauth/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ func newGCPHandler(gcpAuth *filterapi.GCPAuth) (Handler, error) {
// The suffix is combined with the generated prefix to form the complete path for the GCP API call.
func (g *gcpHandler) Do(_ context.Context, requestHeaders map[string]string, _ []byte) ([]internalapi.Header, error) {
// Build the GCP URL prefix using the configured region and project name.
prefixPath := fmt.Sprintf("https://%s-aiplatform.googleapis.com/v1/projects/%s/locations/%s", g.region, g.projectName, g.region)

prefixPath := fmt.Sprintf("/v1/projects/%s/locations/%s", g.projectName, g.region)
// Find and update the ":path" header by prepending the prefix.
path := requestHeaders[":path"]
// Update the raw byte value if present.
Expand Down
2 changes: 1 addition & 1 deletion internal/backendauth/gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestGCPHandler_Do(t *testing.T) {
requestHeaders: map[string]string{
":path": "publishers/google/models/gemini-pro:generateContent",
},
wantPathValue: "https://us-central1-aiplatform.googleapis.com/v1/projects/test-project/locations/us-central1/publishers/google/models/gemini-pro:generateContent",
wantPathValue: "/v1/projects/test-project/locations/us-central1/publishers/google/models/gemini-pro:generateContent",
},
}

Expand Down
9 changes: 0 additions & 9 deletions tests/extproc/testupstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ func TestWithTestUpstream(t *testing.T) {
method: http.MethodPost,
requestBody: `{"model":"gemini-1.5-pro","messages":[{"role":"system","content":"You are a helpful assistant."}]}`,
expRequestBody: `{"contents":null,"tools":null,"generation_config":{},"system_instruction":{"parts":[{"text":"You are a helpful assistant."}]}}`,
expHost: "gcp-region-aiplatform.googleapis.com",
expPath: "/v1/projects/gcp-project-name/locations/gcp-region/publishers/google/models/gemini-1.5-pro:generateContent",
expRequestHeaders: map[string]string{"Authorization": "Bearer " + fakeGCPAuthToken},
responseStatus: strconv.Itoa(http.StatusOK),
Expand All @@ -276,7 +275,6 @@ func TestWithTestUpstream(t *testing.T) {
method: http.MethodPost,
requestBody: `{"model":"gemini-1.5-pro","messages":[{"role":"system","content":"You are a helpful assistant."}]}`,
expRequestBody: `{"contents":null,"tools":null,"generation_config":{},"system_instruction":{"parts":[{"text":"You are a helpful assistant."}]}}`,
expHost: "gcp-region-aiplatform.googleapis.com",
expPath: "/v1/projects/gcp-project-name/locations/gcp-region/publishers/google/models/gemini-1.5-pro:generateContent",
expRequestHeaders: map[string]string{"Authorization": "Bearer " + fakeGCPAuthToken},
responseStatus: strconv.Itoa(http.StatusOK),
Expand All @@ -291,7 +289,6 @@ func TestWithTestUpstream(t *testing.T) {
method: http.MethodPost,
requestBody: `{"model":"gemini-1.5-pro","messages":[{"role":"user","content":"tell me the delivery date for order 123"}],"tools":[{"type":"function","function":{"name":"get_delivery_date","description":"Get the delivery date for a customer's order. Call this whenever you need to know the delivery date, for example when a customer asks 'Where is my package'","parameters":{"type":"object","properties":{"order_id":{"type":"string","description":"The customer's order ID."}},"required":["order_id"]}}}]}`,
expRequestBody: `{"contents":[{"parts":[{"text":"tell me the delivery date for order 123"}],"role":"user"}],"tools":[{"functionDeclarations":[{"description":"Get the delivery date for a customer's order. Call this whenever you need to know the delivery date, for example when a customer asks 'Where is my package'","name":"get_delivery_date","parameters":{"properties":{"order_id":{"description":"The customer's order ID.","type":"string"}},"required":["order_id"],"type":"object"}}]}],"generation_config":{}}`,
expHost: "gcp-region-aiplatform.googleapis.com",
expPath: "/v1/projects/gcp-project-name/locations/gcp-region/publishers/google/models/gemini-1.5-pro:generateContent",
expRequestHeaders: map[string]string{"Authorization": "Bearer " + fakeGCPAuthToken},
responseStatus: strconv.Itoa(http.StatusOK),
Expand All @@ -306,7 +303,6 @@ func TestWithTestUpstream(t *testing.T) {
method: http.MethodPost,
requestBody: `{"model":"claude-3-sonnet","max_completion_tokens":1024, "messages":[{"role":"system","content":"You are an Anthropic assistant."},{"role":"user","content":"Hello!"}]}`,
expRequestBody: `{"max_tokens":1024,"messages":[{"content":[{"text":"Hello!","type":"text"}],"role":"user"}],"system":[{"text":"You are an Anthropic assistant.","type":"text"}],"anthropic_version":"vertex-2023-10-16"}`,
expHost: "gcp-region-aiplatform.googleapis.com",
expPath: "/v1/projects/gcp-project-name/locations/gcp-region/publishers/anthropic/models/claude-3-sonnet:rawPredict",
expRequestHeaders: map[string]string{"Authorization": "Bearer " + fakeGCPAuthToken},
responseStatus: strconv.Itoa(http.StatusOK),
Expand Down Expand Up @@ -538,7 +534,6 @@ data: [DONE]
method: http.MethodPost,
requestBody: `{"model":"gemini-1.5-pro","messages":[{"role":"system","content":"You are a helpful assistant."}], "stream": true}`,
expRequestBody: `{"contents":null,"tools":null,"generation_config":{},"system_instruction":{"parts":[{"text":"You are a helpful assistant."}]}}`,
expHost: "gcp-region-aiplatform.googleapis.com",
expPath: "/v1/projects/gcp-project-name/locations/gcp-region/publishers/google/models/gemini-1.5-pro:streamGenerateContent",
expRawQuery: "alt=sse",
expRequestHeaders: map[string]string{"Authorization": "Bearer " + fakeGCPAuthToken},
Expand Down Expand Up @@ -576,7 +571,6 @@ data: [DONE]
responseType: "sse",
requestBody: `{"model":"claude-3-sonnet","max_completion_tokens":1024, "messages":[{"role":"user","content":"Why is the sky blue?"}], "stream": true}`,
expRequestBody: `{"max_tokens":1024,"messages":[{"content":[{"text":"Why is the sky blue?","type":"text"}],"role":"user"}],"stream":true,"anthropic_version":"vertex-2023-10-16"}`,
expHost: "gcp-region-aiplatform.googleapis.com",
expPath: "/v1/projects/gcp-project-name/locations/gcp-region/publishers/anthropic/models/claude-3-sonnet:streamRawPredict",
expRequestHeaders: map[string]string{"Authorization": "Bearer " + fakeGCPAuthToken},
responseStatus: strconv.Itoa(http.StatusOK),
Expand Down Expand Up @@ -640,7 +634,6 @@ data: [DONE]
}
}]
}`,
expHost: "gcp-region-aiplatform.googleapis.com",
expPath: "/v1/projects/gcp-project-name/locations/gcp-region/publishers/anthropic/models/claude-3-sonnet:streamRawPredict",
expRequestHeaders: map[string]string{"Authorization": "Bearer " + fakeGCPAuthToken},
responseStatus: strconv.Itoa(http.StatusOK),
Expand Down Expand Up @@ -838,7 +831,6 @@ data: [DONE]
method: http.MethodPost,
requestBody: `{"model":"claude-3-sonnet","max_tokens":100,"messages":[{"role":"user","content":[{"type":"text","text":"Hello, just a simple test message."}]}],"stream":false}`,
expRequestBody: `{"anthropic_version":"vertex-2023-10-16","max_tokens":100,"messages":[{"content":[{"text":"Hello, just a simple test message.","type":"text"}],"role":"user"}],"stream":false}`,
expHost: "gcp-region-aiplatform.googleapis.com",
expPath: "/v1/projects/gcp-project-name/locations/gcp-region/publishers/anthropic/models/claude-3-sonnet:rawPredict",
expRequestHeaders: map[string]string{"Authorization": "Bearer " + fakeGCPAuthToken},
responseStatus: strconv.Itoa(http.StatusOK),
Expand All @@ -854,7 +846,6 @@ data: [DONE]
responseType: "sse",
requestBody: `{"model":"claude-3-sonnet","max_tokens":100,"messages":[{"role":"user","content":[{"type":"text","text":"Tell me a short joke"}]}],"stream":true}`,
expRequestBody: `{"anthropic_version":"vertex-2023-10-16","max_tokens":100,"messages":[{"content":[{"text":"Tell me a short joke","type":"text"}],"role":"user"}],"stream":true}`,
expHost: "gcp-region-aiplatform.googleapis.com",
expPath: "/v1/projects/gcp-project-name/locations/gcp-region/publishers/anthropic/models/claude-3-sonnet:streamRawPredict",
expRequestHeaders: map[string]string{"Authorization": "Bearer " + fakeGCPAuthToken},
responseStatus: strconv.Itoa(http.StatusOK),
Expand Down