-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: return HTTP 404 when route not found #396
Conversation
Signed-off-by: David Xia <david@davidxia.com>
}, | ||
} | ||
|
||
if err := stream.Send(resp); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cannot use resp (variable of type *"github.com/envoyproxy/go-control-plane/envoy/service/ext_proc/v3".ImmediateResponse) as *"github.com/envoyproxy/go-control-plane/envoy/service/ext_proc/v3".ProcessingResponse value in argument to stream.Send
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the model_processor.go
you have an example of how to return an immediate response that you can use in the chat completion procesor.
@@ -84,6 +84,25 @@ func (c *chatCompletionProcessor) ProcessRequestBody(ctx context.Context, rawBod | |||
c.requestHeaders[c.config.modelNameHeaderKey] = model | |||
b, err := c.config.router.Calculate(c.requestHeaders) | |||
if err != nil { | |||
// if err.Error() == "no matching rule found" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of doing this and looking the error tree like you do, let's create a proper ErrRouteNotFound
in the filterapi/x
package. This way all implementations of Calculate can return that error consistently.
Then you can modify the default Calculate method to return that error, and here can cleanly just use errors.Is
and return the immediate response directly.
@@ -168,6 +170,25 @@ func (s *Server) Process(stream extprocv3.ExternalProcessor_ProcessServer) error | |||
|
|||
resp, err := s.processMsg(ctx, p, req) | |||
if err != nil { | |||
s.logger.Info("AAAAA") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fact that routes are calculated is an implementation detail of the chat completion processor, because it's based on the request body for requests to that endpoint. Therefore, I would not have this logic here as it couples the server
to semantics of a particular processor.
Let's keep this unchanged and just have the chat completion processor return the immediate response.
}, | ||
} | ||
|
||
if err := stream.Send(resp); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the model_processor.go
you have an example of how to return an immediate response that you can use in the chat completion procesor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nacx thanks for the very helpful guidance! Closing and will open another PR with your suggestions.
new one #399 |
No description provided.