Skip to content

Commit c3661e8

Browse files
authored
Merge pull request #37 from liu-cong/body
Update targetModel in request body
2 parents 9270ff6 + 53396a9 commit c3661e8

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

pkg/ext-proc/handlers/request.go

+16-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package handlers
33
import (
44
"encoding/json"
55
"fmt"
6+
"strconv"
67

78
configPb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
89
extProcPb "github.com/envoyproxy/go-control-plane/envoy/service/ext_proc/v3"
@@ -41,6 +42,7 @@ func (s *Server) HandleRequestBody(reqCtx *RequestContext, req *extProcPb.Proces
4142
// TODO: Read from LLMService CRD.
4243
Critical: true,
4344
}
45+
klog.V(3).Infof("LLM Request: %+v", llmReq)
4446

4547
// Update target models in the body.
4648
rb["model"] = llmReq.ResolvedTargetModel
@@ -49,7 +51,7 @@ func (s *Server) HandleRequestBody(reqCtx *RequestContext, req *extProcPb.Proces
4951
klog.Errorf("Error marshaling request body: %v", err)
5052
return nil, fmt.Errorf("error marshaling request body: %v", err)
5153
}
52-
klog.V(3).Infof("Updated body: %v", updatedBody)
54+
klog.V(3).Infof("Updated body: %v", string(updatedBody))
5355

5456
targetPod, err := s.scheduler.Schedule(llmReq)
5557
if err != nil {
@@ -68,6 +70,14 @@ func (s *Server) HandleRequestBody(reqCtx *RequestContext, req *extProcPb.Proces
6870
RawValue: []byte(targetPod.Address),
6971
},
7072
},
73+
// We need to update the content length header if the body is mutated, see Envoy doc:
74+
// https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/filters/http/ext_proc/v3/processing_mode.proto#enum-extensions-filters-http-ext-proc-v3-processingmode-bodysendmode
75+
{
76+
Header: &configPb.HeaderValue{
77+
Key: "Content-Length",
78+
RawValue: []byte(strconv.Itoa(len(updatedBody))),
79+
},
80+
},
7181
}
7282
// Print headers for debugging
7383
for _, header := range headers {
@@ -81,12 +91,11 @@ func (s *Server) HandleRequestBody(reqCtx *RequestContext, req *extProcPb.Proces
8191
HeaderMutation: &extProcPb.HeaderMutation{
8292
SetHeaders: headers,
8393
},
84-
// TODO: Enable body mutation
85-
// BodyMutation: &extProcPb.BodyMutation{
86-
// Mutation: &extProcPb.BodyMutation_Body{
87-
// Body: updatedBody,
88-
// },
89-
// },
94+
BodyMutation: &extProcPb.BodyMutation{
95+
Mutation: &extProcPb.BodyMutation_Body{
96+
Body: updatedBody,
97+
},
98+
},
9099
},
91100
},
92101
},

0 commit comments

Comments
 (0)