Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

davidxia
Copy link
Contributor

No description provided.

Signed-off-by: David Xia <david@davidxia.com>
},
}

if err := stream.Send(resp); err != nil {
Copy link
Contributor Author

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

Copy link
Contributor

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" {
Copy link
Contributor

@nacx nacx Feb 21, 2025

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")
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

@davidxia davidxia left a 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.

@davidxia davidxia closed this Feb 21, 2025
@davidxia davidxia deleted the test1 branch February 21, 2025 12:20
@davidxia
Copy link
Contributor Author

new one #399

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants