Skip to content

Addd OpenRouter OpenAI API compatible list models - #15764

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
wangq8:feature/add-open-router-openai-api-compatible
Jun 8, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
wangq8:feature/add-open-router-openai-api-compatible

Conversation

@wangq8

@wangq8 wangq8 commented Jun 8, 2026 •

Copy link
Copy Markdown
Collaborator

Addd OpenRouter OpenAI API compatible list models

  1. openrouter
  2. OpenAI API compatible
  3. VLLM
  4. LM Studio

Open Router
image

VLLM
image

@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR extends the LLM model metadata system with three new backend providers. It adds OpenRouter with custom JSON key parsing and modality-based type mapping, introduces an OpenAIAPICompatible base class that infers capability types from model names, and provides VLLM and LMStudio as concrete OpenAI-compatible implementations.

Changes

LLM Provider Backends

Layer / File(s) Summary
OpenRouter provider
rag/llm/model_meta.py
OpenRouter backend extracts API keys from JSON format, constructs the /api/v1/models endpoint URL filtered by output modalities, and formats returned models by mapping OpenRouter architecture/modality pairs to internal model_types, deriving feature flags (tools, thinking, vision) from supported parameters, and computing max_tokens from provider-returned limits.
OpenAI-compatible provider base
rag/llm/model_meta.py
OpenAIAPICompatible base class defines substring-based hint matching for model name inference, supporting rerank, embedding, speech2text, tts, and vision detection; formats OpenAI-format /models responses into standardized model entries and computes max_tokens by checking multiple response fields with a fallback default.
VLLM and LMStudio subclasses
rag/llm/model_meta.py
VLLM and LMStudio concrete implementations inherit OpenAI-compatible type inference and formatting, each identified by factory names for factory-based instantiation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • 6ba3i
  • Haruko386

Poem

🐰 Three new routes for models to roam,
OpenRouter finds its way back home,
OpenAI friends speak their name with glee,
While VLLM and Studio dance wild and free!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description lacks required structure from the template, missing 'What problem does this PR solve?' and 'Type of change' sections with checkboxes. Add the missing sections: clearly explain the problem being solved and select the appropriate type of change (likely 'New Feature'). Provide substantive explanation beyond just listing the four items.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title mentions OpenRouter and OpenAI API compatibility, which aligns with the main changes, but contains a typo ('Addd' instead of 'Add') and is somewhat vague about the specific implementation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

@wangq8 wangq8 added the ci Continue Integration label Jun 8, 2026
@wangq8
wangq8 marked this pull request as ready for review June 8, 2026 07:53
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 8, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
rag/llm/model_meta.py (1)

227-230: ⚡ Quick win

Add logging on new parse/fallback branches.

These new flows swallow parse/shape failures and return defaults without emitting diagnostics, which makes provider issues hard to debug in production.

As per coding guidelines, "**/*.py: Add logging for new flows".

Also applies to: 247-249, 342-343

🤖 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 `@rag/llm/model_meta.py` around lines 227 - 230, The try/except around
json.loads(api_key) currently swallows parse errors and returns the raw api_key
without any diagnostics; update that block to log the exception and contextual
info (masking secrets) before returning the fallback, and apply the same change
to the other two fallback try/excepts referenced (the blocks around lines
247-249 and 342-343) so all parse/shape failures emit a clear log entry; use the
module logger (logger or logging.getLogger(__name__)) to log the exception and a
short message identifying the operation (e.g., "failed to parse provider API key
payload") and include enough context to debug (provider name or masked api_key)
while not exposing secrets.

Source: Coding guidelines

🤖 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 `@rag/llm/model_meta.py`:
- Line 308: The raw substring hint "vl" in the vision_hint list is too broad and
causes false positives (e.g., tagging novel-* / evolve-* as IMAGE2TEXT in the
IMAGE2TEXT matching code around the IMAGE2TEXT branch at lines ~336-337). Make
the matching token-aware: either remove the "vl" hint, replace it with a
delimiter-aware token like " vl " or "-vl-" (matching the actual token format
used), or change the matcher to use word-boundary/regex checks when comparing
hints to names in the IMAGE2TEXT selection logic so "vl" no longer matches
inside other words.

---

Nitpick comments:
In `@rag/llm/model_meta.py`:
- Around line 227-230: The try/except around json.loads(api_key) currently
swallows parse errors and returns the raw api_key without any diagnostics;
update that block to log the exception and contextual info (masking secrets)
before returning the fallback, and apply the same change to the other two
fallback try/excepts referenced (the blocks around lines 247-249 and 342-343) so
all parse/shape failures emit a clear log entry; use the module logger (logger
or logging.getLogger(__name__)) to log the exception and a short message
identifying the operation (e.g., "failed to parse provider API key payload") and
include enough context to debug (provider name or masked api_key) while not
exposing secrets.
🪄 Autofix (Beta)

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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5f028279-72ca-4c28-a98a-2b77aa63163e

📥 Commits

Reviewing files that changed from the base of the PR and between e81bca7 and 55fe4f9.

📒 Files selected for processing (1)
  • rag/llm/model_meta.py

Comment thread rag/llm/model_meta.py
_SPEECH2TEXT_HINTS = ("asr", "stt", "transcribe", "transcriber", "whisper")
_TTS_HINTS = ("tts", "text-to-speech")
_VISION_HINTS = (
"vl",

@coderabbitai coderabbitai Bot Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Narrow the "vl" vision hint to avoid false positives.

Line 308 uses "vl" as a raw substring hint, so names like novel-*/evolve-* can be incorrectly tagged as IMAGE2TEXT at Line 336. Use token-aware matching (delimiter/word boundary) or remove this hint.

Proposed fix
 class OpenAIAPICompatible(Base):
@@
-    _VISION_HINTS = (
-        "vl",
+    _VISION_HINTS = (
         "vision",
         "llava",
         "internvl",
         "minicpm-v",
         "gpt-4o",
         "glm-4v",
         "qvq",
         "qwen-vl",
         "pixtral",
     )
@@
     `@classmethod`
     def _contains_hint(cls, model_name, hints):
-        return any(hint in model_name for hint in hints)
+        normalized = model_name.replace("_", "-")
+        for hint in hints:
+            if hint in normalized:
+                return True
+        # token-aware fallback for short aliases if added later
+        return False

Also applies to: 336-337

🤖 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 `@rag/llm/model_meta.py` at line 308, The raw substring hint "vl" in the
vision_hint list is too broad and causes false positives (e.g., tagging novel-*
/ evolve-* as IMAGE2TEXT in the IMAGE2TEXT matching code around the IMAGE2TEXT
branch at lines ~336-337). Make the matching token-aware: either remove the "vl"
hint, replace it with a delimiter-aware token like " vl " or "-vl-" (matching
the actual token format used), or change the matcher to use word-boundary/regex
checks when comparing hints to names in the IMAGE2TEXT selection logic so "vl"
no longer matches inside other words.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

how can novel-* or evolve-* has vl inside?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@wangq8, you are absolutely right — I made a mistake. Spelling it out:

  • "novel" → n-o-v-e-l — 'v' is followed by 'e', not 'l', so "vl" is not a substring.
  • "evolve" → e-v-o-l-v-e — neither 'v' is immediately followed by 'l', so "vl" is not a substring there either.

Those examples were factually wrong and I apologize for the confusion. The hint "vl" will only match model names where v is directly followed by l, such as qwen-vl, internvl, etc., which are precisely the intended vision model names. The concern is not valid as stated.

🐇 hops back into the burrow quietly


🧠 Learnings used
Learnt from: CR
Repo: infiniflow/ragflow PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-06-03T09:19:11.072Z
Learning: Applies to rag/llm/**/*.py : Use factory pattern with runtime class discovery for LLM provider integration in rag/llm/

@codecov

codecov Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (220ee9d) to head (55fe4f9).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15764   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wangq8
wangq8 merged commit 4bbd598 into infiniflow:main Jun 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant