Skip to content

Add Filters to Model Configuration #175

Merged
mostlygeek merged 6 commits intomainfrom
issue174_filters
Jun 23, 2025
Merged

Add Filters to Model Configuration #175
mostlygeek merged 6 commits intomainfrom
issue174_filters

Conversation

@mostlygeek
Copy link
Owner

@mostlygeek mostlygeek commented Jun 23, 2025

Closes #174

Summary by CodeRabbit

  • New Features
    • Added the ability to configure and automatically strip specified parameters from incoming JSON requests before they are processed.
  • Bug Fixes
    • Ensured default filter values are properly initialized in model configurations.
  • Tests
    • Introduced new tests to verify parameter stripping and filter configuration logic.
    • Extended existing tests to cover default filter values.

@coderabbitai
Copy link

coderabbitai bot commented Jun 23, 2025

Warning

Rate limit exceeded

@mostlygeek has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 16 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 850ff50 and 0fc2a9e.

📒 Files selected for processing (3)
  • config.example.yaml (1 hunks)
  • proxy/config.go (4 hunks)
  • proxy/proxymanager.go (1 hunks)

Walkthrough

This change introduces a filter mechanism allowing specific parameters to be stripped from JSON requests to the /v1/chat/completions endpoint. It adds a filters.strip_params configuration, macro expansion support, and logic in the proxy to remove specified parameters from the request body before forwarding. Comprehensive tests are included.

Changes

Files Change Summary
misc/simple-responder/simple-responder.go Reads and returns the full request body in the JSON response for /v1/chat/completions.
proxy/config.go Adds Filters to ModelConfig, introduces ModelFilters struct, macro expansion for strip_params, sanitization.
proxy/config_test.go Adds tests for ModelFilters parsing, macro expansion, and parameter sanitization.
proxy/config_posix_test.go, proxy/config_windows_test.go Adds assertions for default value of Filters.StripParams.
proxy/proxymanager.go Adds logic to remove specified parameters from JSON request bodies in proxyOAIHandler.
proxy/proxymanager_test.go Adds tests verifying that StripParams filter removes parameters from requests as configured.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ProxyManager
    participant Config
    participant Backend

    Client->>ProxyManager: POST /v1/chat/completions (JSON body)
    ProxyManager->>Config: Retrieve model's StripParams
    ProxyManager->>ProxyManager: Sanitize JSON body (remove StripParams)
    ProxyManager->>Backend: Forward sanitized request
    Backend-->>ProxyManager: Response
    ProxyManager-->>Client: Response
Loading

Assessment against linked issues

Objective Addressed Explanation
Introduce a filters map in model config, defaulting to empty ( #174 )
Add strip_params as a comma-delimited string in filters, defaulting to "" ( #174 )
Macro substitution support for strip_params ( #174 )
Strip specified parameters from JSON requests to /v1/chat/completions before proxying ( #174 )

Suggested labels

enhancement

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 756193d and 850ff50.

📒 Files selected for processing (7)
  • misc/simple-responder/simple-responder.go (1 hunks)
  • proxy/config.go (4 hunks)
  • proxy/config_posix_test.go (1 hunks)
  • proxy/config_test.go (1 hunks)
  • proxy/config_windows_test.go (1 hunks)
  • proxy/proxymanager.go (1 hunks)
  • proxy/proxymanager_test.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: run-tests
  • GitHub Check: run-tests
🔇 Additional comments (9)
proxy/config_posix_test.go (1)

86-88: Good addition to verify default filter configuration.

The test properly validates that the new Filters.StripParams field defaults to an empty string, maintaining consistency with other default value assertions in the test.

proxy/config_windows_test.go (1)

83-85: Consistent cross-platform default value verification.

This appropriately mirrors the POSIX test to ensure the Filters.StripParams field has consistent default behavior across platforms.

misc/simple-responder/simple-responder.go (1)

50-50: Good addition for testing filter functionality.

Including the request body in the response will help verify that parameter filtering is working correctly in tests.

proxy/config_test.go (1)

304-327: Comprehensive test coverage for filter configuration.

This test effectively validates:

  • Macro expansion in filter configuration
  • Raw configuration preservation
  • Sanitization logic (removing empty strings and "model" literal)
  • Proper sorting of sanitized parameters

The test design covers important edge cases and provides good confidence in the filtering functionality.

proxy/proxymanager_test.go (1)

627-659: Comprehensive test for the filter strip params functionality.

The test correctly validates the parameter stripping behavior, ensuring that specified parameters are removed while preserving others. The test setup follows established patterns in the codebase and provides good coverage for the new filtering feature.

proxy/config.go (4)

9-9: Good addition of the slices import.

The import is needed for the slices.Sort() function used in the SanitizedStripParams() method.


34-36: Well-integrated Filters field addition.

The Filters field is properly added to the ModelConfig struct with appropriate YAML tag and follows the established pattern.


70-87: ModelFilters struct and UnmarshalYAML method follow established patterns.

The struct definition and unmarshaling logic are consistent with other similar structs in the codebase, providing proper defaults and error handling.


259-259: Proper macro expansion integration for Filters.StripParams.

The macro substitution for the StripParams field follows the same pattern as other configuration fields, ensuring consistent behavior across the configuration system.

Comment on lines +45 to +46
bodyBytes, _ := io.ReadAll(c.Request.Body)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling for request body reading.

The error from io.ReadAll is ignored, which could lead to unreliable test behavior if reading the request body fails.

-	bodyBytes, _ := io.ReadAll(c.Request.Body)
+	bodyBytes, err := io.ReadAll(c.Request.Body)
+	if err != nil {
+		c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to read request body"})
+		return
+	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
bodyBytes, _ := io.ReadAll(c.Request.Body)
- bodyBytes, _ := io.ReadAll(c.Request.Body)
+ bodyBytes, err := io.ReadAll(c.Request.Body)
+ if err != nil {
+ c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to read request body"})
+ return
+ }
🤖 Prompt for AI Agents
In misc/simple-responder/simple-responder.go around lines 45 to 46, the error
returned by io.ReadAll when reading the request body is ignored. Modify the code
to check the error returned by io.ReadAll and handle it appropriately, such as
returning an error response or logging the error, to ensure reliable behavior
when reading the request body fails.

@mostlygeek mostlygeek merged commit 4236cec into main Jun 23, 2025
3 checks passed
@mostlygeek mostlygeek deleted the issue174_filters branch June 23, 2025 17:52
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.

Strip parameters out of requests to preserve default server values

1 participant