Skip to content

Add openrouter sub-provider (endpoint tag) selection for CompanyBot, … - #20

Merged
kiranharidas187 merged 3 commits into
ELEVATE-Project:release-1.3.0from
darshilbabel:drop_10_work
Aug 13, 2026
Merged

Add openrouter sub-provider (endpoint tag) selection for CompanyBot, …#20
kiranharidas187 merged 3 commits into
ELEVATE-Project:release-1.3.0from
darshilbabel:drop_10_work

Conversation

@KUNALTEMPEST

@KUNALTEMPEST KUNALTEMPEST commented Aug 11, 2026

Copy link
Copy Markdown

…wired into gateway routing via provider_options

Summary by CodeRabbit

  • New Features

    • Added gateway provider, model, and optional sub-provider configuration for company bots.
    • Admin forms now dynamically load available providers, models, and OpenRouter endpoints.
    • Saved gateway selections remain available even when temporarily unavailable remotely.
  • Bug Fixes

    • Chat responses and title generation now consistently use the configured effective gateway provider and model.
    • Dependent model and sub-provider selections are cleared when their related settings change.

…wired into gateway routing via provider_options
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bb510c50-d8ef-4574-82ed-db8f5ce29ca5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR adds gateway provider, model, and sub-provider fields. Admin forms load gateway choices dynamically. Gateway requests and title generation use centralized effective provider and model resolution.

Changes

Gateway configuration

Layer / File(s) Summary
Gateway configuration storage
chatbot/models/company_models.py, chatbot/migrations/0090_add_companybot_gateway_provider_model.py
Adds nullable gateway provider, model, and sub-provider fields to CompanyBot and HistoricalCompanyBot. Clears dependent selections when provider or model values change.
Gateway lookup and effective resolution
chatbot/llm_models/llm_gateway.py
Adds effective provider/model resolution and gateway API lookups for providers, models, and OpenRouter endpoints. Builds OpenRouter provider restrictions from the selected sub-provider.
Gateway admin form behavior
chatbot/admin/company_admin.py
Hides legacy fields, loads gateway choices, populates dependent model and endpoint selections, and preserves saved values that are unavailable remotely.
Gateway request integrations
chatbot/services/response_handlers/base_response_handler.py, chatbot/celery_tasks/title_tasks.py
Uses centralized gateway provider/model resolution for streaming, non-streaming, and title-generation requests. Removes the handler-specific model resolution helper.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant BaseResponseHandler
  participant get_effective_provider_model
  participant call_llm_gateway
  BaseResponseHandler->>get_effective_provider_model: Resolve provider and model
  get_effective_provider_model-->>BaseResponseHandler: Return effective values
  BaseResponseHandler->>call_llm_gateway: Submit gateway request
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding OpenRouter sub-provider endpoint tag selection for CompanyBot.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@KUNALTEMPEST

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
chatbot/celery_tasks/title_tasks.py (1)

79-79: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use the Ruff-recommended message unpacking.

Ruff RUF005 flags list concatenation here. Replace it with unpacking while preserving message order.

Proposed fix
-        messages=[system_msg] + list(messages),
+        messages=[system_msg, *list(messages)],
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@chatbot/celery_tasks/title_tasks.py` at line 79, Update the messages
construction in the task containing the messages argument to use
Ruff-recommended iterable unpacking instead of list concatenation, while
preserving system_msg as the first message and retaining all existing messages
in order.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@chatbot/llm_models/llm_gateway.py`:
- Around line 47-56: Update get_effective_provider_model to fall back to
company_bot.provider and company_bot.llm_model when gateway_provider or
gateway_model is not configured, while preserving other_params.custom_model as
the model override. Alternatively, add a migration that backfills
gateway_provider and gateway_model for every existing bot before this function
is used; ensure both interactive and title-generation calls receive routable
provider/model values.

In `@chatbot/models/company_models.py`:
- Around line 196-204: Update CompanyBot.save so any fields cleared when
gateway_provider or gateway_model changes are added to kwargs["update_fields"]
before calling super().save; preserve all other requested fields and handle
update_fields only when it is provided.

In `@chatbot/services/response_handlers/base_response_handler.py`:
- Around line 574-576: Ensure gateway_provider and gateway_model are populated
from legacy provider and llm_model values, or reject incomplete configurations
before routing. Apply the fix to all affected calls: base_response_handler.py
lines 574-576 and 684-686, and title_tasks.py lines 76-80; update the shared
get_effective_provider_model path or each caller so non-streaming, streaming,
and title requests never pass null routing values.

---

Nitpick comments:
In `@chatbot/celery_tasks/title_tasks.py`:
- Line 79: Update the messages construction in the task containing the messages
argument to use Ruff-recommended iterable unpacking instead of list
concatenation, while preserving system_msg as the first message and retaining
all existing messages in order.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6df37b4d-10eb-4855-8b6e-d7fa035f07d5

📥 Commits

Reviewing files that changed from the base of the PR and between ce09a36 and bc670d0.

📒 Files selected for processing (6)
  • chatbot/admin/company_admin.py
  • chatbot/celery_tasks/title_tasks.py
  • chatbot/llm_models/llm_gateway.py
  • chatbot/migrations/0090_add_companybot_gateway_provider_model.py
  • chatbot/models/company_models.py
  • chatbot/services/response_handlers/base_response_handler.py

Comment thread chatbot/llm_models/llm_gateway.py
Comment thread chatbot/models/company_models.py
Comment thread chatbot/services/response_handlers/base_response_handler.py
@kiranharidas187
kiranharidas187 merged commit 0a03725 into ELEVATE-Project:release-1.3.0 Aug 13, 2026
1 check passed
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