Skip to content

Conversation

@matdev83
Copy link
Owner

@matdev83 matdev83 commented Nov 7, 2025

Summary

  • extend the chat domain model and translation pipeline to carry repetition_penalty and min_p
  • allow OpenRouter to forward the new sampling parameters and warn on unsupported backends
  • update parameter resolution plus connector tests to cover the additional knobs and warning paths

Testing

  • python -m pytest tests/unit/connectors/test_precision_payload_mapping.py tests/unit/core/services/test_parameter_resolution_service.py

Codex Task

Summary by CodeRabbit

  • New Features

    • Added two new generation parameters (repetition_penalty and min_p) to fine-tune response generation across supported LLM backends.
    • Integrated warning notifications when unsupported parameters are specified, improving configuration transparency.
  • Chores

    • Enhanced internal parameter resolution infrastructure to track new generation parameters.
    • Expanded test coverage for parameter handling across backends.

@coderabbitai
Copy link

coderabbitai bot commented Nov 7, 2025

Walkthrough

Adds two new generation parameters (repetition_penalty and min_p) to the domain model, parameter resolution service, and multiple AI connectors. Most connectors emit warnings when these unsupported parameters are present; OpenRouter explicitly supports them. Substantially rewrites the Gemini backend with lazy initialization, streaming support, and robust payload transformation.

Changes

Cohort / File(s) Summary
Domain models
src/core/domain/chat.py, src/core/domain/gemini_translation.py
Added repetition_penalty and min_p optional fields to ChatRequest; updated Gemini translation to extract and forward these fields from Gemini payloads.
Parameter resolution
src/core/services/parameter_resolution_service.py
Extended ResolvedParameters and ParameterResolutionService to recognize and resolve repetition_penalty and min_p through standard precedence pipeline; updated to_dict and get_debug_info.
Anthropic connector
src/connectors/anthropic.py
Added warnings in _prepare_anthropic_payload when repetition_penalty or min_p are present (unsupported).
Gemini backend
src/connectors/gemini.py
Comprehensive rewrite: introduced GeminiBackend class with lazy model loading, initialization flow, async/sync model accessors, content transformation for chat parts, streaming support with cancellation, payload construction with generationConfig merging, OpenRouter header context builder, robust error handling, and backend registry registration.
Gemini Cloud Project connector
src/connectors/gemini_cloud_project.py
Added warnings in _build_generation_config when repetition_penalty or min_p are present (unsupported).
Gemini OAuth base connector
src/connectors/gemini_oauth_base.py
Added warnings in _build_generation_config when repetition_penalty or min_p are present (unsupported).
OpenAI connector
src/connectors/openai.py
Major rewrite: full-featured implementation with health checks, header handling, robust JSON decoding, message payload normalization, model loading, streaming support with cancellation, error handling, filtering of unsupported parameters (repetition_penalty, min_p), and SUPPORTED_CUSTOM_PARAMETERS attribute.
OpenRouter backend
src/connectors/openrouter.py
Added SUPPORTED_CUSTOM_PARAMETERS class attribute with frozenset({"repetition_penalty", "min_p"}).
Test suite
tests/unit/connectors/test_precision_payload_mapping.py, tests/unit/core/services/test_parameter_resolution_service.py
Added test assertions for parameter warnings, payload omissions for unsupported backends, and extended coverage of new parameters in resolved parameters, to_dict, and get_debug_info.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ParameterResolutionService
    participant Connector
    participant Backend API

    Client->>ParameterResolutionService: resolve_parameters (with repetition_penalty, min_p)
    ParameterResolutionService->>ParameterResolutionService: Apply precedence pipeline
    ParameterResolutionService-->>Client: ResolvedParameters (includes new fields)
    
    Client->>Connector: chat_completions (ChatRequest)
    Connector->>Connector: Check parameter support
    
    alt Parameter Supported (e.g., OpenRouter, Gemini)
        Connector->>Connector: Include in payload
        Connector->>Backend API: POST with repetition_penalty, min_p
    else Parameter Unsupported
        Connector->>Connector: Log warning, omit from payload
        Connector->>Backend API: POST without parameter
    end
    
    Backend API-->>Connector: Response
    Connector-->>Client: ResponseEnvelope
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • src/connectors/gemini.py: Substantial rewrite with 15+ new methods, lazy initialization, streaming/non-streaming dual paths, and sophisticated payload transformation requiring careful logic verification.
  • src/connectors/openai.py: Full-featured rewrite with health checks, JSON decoding guards, message normalization, streaming support, and parameter filtering—complex error paths and state management.
  • src/core/services/parameter_resolution_service.py: Extension of parameter precedence pipeline with new fields; verify precedence handling and debug output consistency.
  • Heterogeneous changes: Mix of trivial parameter additions (domain models, most connectors), complex rewrites (gemini.py, openai.py), and test assertions—each requires distinct reasoning.
  • Integration points: Parameter flow from domain → resolution service → connectors; verify consistent handling across supported/unsupported backends and proper warning emission.

Extra attention needed:

  • Gemini backend streaming cancellation mechanism and error handling paths
  • OpenAI connector health check lifecycle and JSON decoding robustness
  • Parameter precedence logic in resolution service
  • Test coverage for both supported and unsupported parameter backends

Poem

A rabbit hops through configs new,
With repetition_penalty and min_p too!
🐰 Some backends cheer, some warn with care,
Gemini sparkles with streaming flair,
Parameters flow through service with grace,
—hopping swiftly through this codespace!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 68.38% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective of the changeset: adding support for two new parameters (repetition_penalty and min_p) across the connector system and domain model.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/enhance-backend-connectors-for-llm-parameters

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c03159e and b57ceeb.

📒 Files selected for processing (11)
  • src/connectors/anthropic.py (1 hunks)
  • src/connectors/gemini.py (1 hunks)
  • src/connectors/gemini_cloud_project.py (1 hunks)
  • src/connectors/gemini_oauth_base.py (1 hunks)
  • src/connectors/openai.py (1 hunks)
  • src/connectors/openrouter.py (1 hunks)
  • src/core/domain/chat.py (2 hunks)
  • src/core/domain/gemini_translation.py (2 hunks)
  • src/core/services/parameter_resolution_service.py (1 hunks)
  • tests/unit/connectors/test_precision_payload_mapping.py (7 hunks)
  • tests/unit/core/services/test_parameter_resolution_service.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Avoid using emojis in Python code comments or docstrings
Follow PEP 8 and use type hints for all functions
Import order must be: standard library, third-party, then local imports, separated by blank lines
Naming conventions: snake_case for variables and functions; PascalCase for classes
Error handling: use specific exceptions and include meaningful error messages
Prefer f-strings for string formatting

Files:

  • src/connectors/openrouter.py
  • src/connectors/anthropic.py
  • src/core/services/parameter_resolution_service.py
  • src/connectors/gemini_oauth_base.py
  • src/connectors/openai.py
  • src/core/domain/gemini_translation.py
  • src/connectors/gemini_cloud_project.py
  • tests/unit/connectors/test_precision_payload_mapping.py
  • src/core/domain/chat.py
  • tests/unit/core/services/test_parameter_resolution_service.py
  • src/connectors/gemini.py
src/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

src/**/*.py: Catch specific exceptions; avoid broad except Exception blocks
If a broad exception must be caught, log with exc_info=True and re-raise a specific custom exception
Use the most specific exception class from src.core.common.exceptions that accurately describes the error
Provide clear, helpful error messages and include relevant details in the details dictionary of custom exceptions

Files:

  • src/connectors/openrouter.py
  • src/connectors/anthropic.py
  • src/core/services/parameter_resolution_service.py
  • src/connectors/gemini_oauth_base.py
  • src/connectors/openai.py
  • src/core/domain/gemini_translation.py
  • src/connectors/gemini_cloud_project.py
  • src/core/domain/chat.py
  • src/connectors/gemini.py
🔇 Additional comments (6)
src/core/domain/chat.py (1)

153-169: Nice addition to the request schema.

Carrying repetition_penalty and min_p directly on ChatRequest keeps the domain model in sync with the new generation knobs and avoids ad‑hoc extras in extra_body. Looks good.

src/core/domain/gemini_translation.py (1)

221-305: Good pass‑through for Gemini config.

Capturing repetitionPenalty/minP from the incoming Gemini payload and threading them into CanonicalChatRequest keeps parity with the domain model and makes the values available to downstream connectors without touching unrelated config.

src/connectors/openrouter.py (1)

31-33: OpenRouter support list updated appropriately.

Declaring both knobs in SUPPORTED_CUSTOM_PARAMETERS lets the connector advertise first‑class support for these fields while other backends merely warn—nice alignment with the PR goals.

src/connectors/gemini_cloud_project.py (1)

1423-1434: Helpful warning path.

Logging when repetition_penalty or min_p show up makes it clearer to callers that Gemini still ignores them, which is a good safety net until the backend gains native support.

src/connectors/gemini_oauth_base.py (1)

2743-2753: Consistent warning behavior.

Mirroring the cloud-project warning logic here keeps the OAuth flow transparent about unsupported parameters without altering request bodies—thanks for keeping the connectors aligned.

tests/unit/core/services/test_parameter_resolution_service.py (1)

36-123: Test coverage looks thorough.

The new assertions over ResolvedParameters serialization and precedence for repetition_penalty/min_p ensure the resolution service stays honest as more knobs land. Nice job expanding the matrix.

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants