Repository navigation
fix(aimlapi): send attribution headers on every aimlapi.com request - #17491
Conversation
|
Important Review skippedNo new commits to review since the last review. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughA shared utility resolves AIMLAPI source and partner attribution from environment variables. Attribution headers are added to REST authorization flows, LLM clients, and model-list requests, with unit tests covering defaults and overrides. ChangesAIMLAPI attribution integration
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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`:
- Around line 566-575: Add structured logging in _get_raw_model_list for both
the missing URL early return and non-200 HTTP responses, including relevant
provider/request status context while excluding authorization headers, bearer
tokens, and other secrets. Preserve the existing None-return behavior and
successful JSON response handling.
- Around line 571-572: Update the AIMLAPI model-list request in the session.get
call to pass an explicit aiohttp.ClientTimeout bounded to the repository’s
60-second provider timeout pattern, while preserving the existing URL, headers,
and response handling.
🪄 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 Plus
Run ID: 3c3f3250-38e4-4982-bb3d-261dc35da396
📒 Files selected for processing (7)
api/apps/restful_apis/aimlapi_api.pycommon/aimlapi_utils.pyrag/llm/chat_model.pyrag/llm/cv_model.pyrag/llm/embedding_model.pyrag/llm/model_meta.pytest/unit_test/common/test_aimlapi_utils.py
7aaa60f to
8f53504
Compare
Requests to aimlapi.com carried no client identification, so the provider's traffic could not be attributed. Add a small shared helper that builds the X-AIMLAPI-Source / X-AIMLAPI-Partner-ID pair and send it from every call site: chat (sync + streaming), embeddings, vision, the /v1/models catalog and the agent-authorization endpoints. Both values keep RAGFlow's defaults and stay env-overridable (AIMLAPI_SOURCE, AIMLAPI_PARTNER_ID). The consent URL of the "Get API key" flow carries the same client identifier as a query parameter: consent (and any sign-up that happens during it) runs in a browser on AIMLAPI's side, which a request header cannot reach.
8f53504 to
b209721
Compare
|
@coderabbitai review Both findings are addressed in the latest push: the model-list fetch is now bounded by an explicit 60s |
🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo '--- PR diff for model metadata ---'
git diff --unified=80 HEAD^ HEAD -- rag/llm/model_meta.py || true
echo '--- Outline ---'
ast-grep outline rag/llm/model_meta.py --items all --match 'AIMLAPI|_get_raw_model_list|Model' || true
echo '--- AIMLAPI references and relevant request/logging context ---'
rg -n -C 10 'AIMLAPI|_get_raw_model_list|ClientTimeout|ClientSession|status|logger\.(warning|error|info)' rag/llm/model_meta.pyLength of output: 19508
If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! ✅ Action performedReview finished.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17491 +/- ##
=======================================
Coverage 90.65% 90.65%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 650 650
Misses 39 39
Partials 28 28 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…nfiniflow#17491) ### Summary The **aimlapi.com** provider added in infiniflow#17311 does not identify itself on any of its outgoing requests, so its traffic cannot be attributed to the integration. This PR adds the two headers AIMLAPI expects — `X-AIMLAPI-Source` and `X-AIMLAPI-Partner-ID` — to every request the provider makes.
…typed model rows Review (Lynn-Inf): - X-AIMLAPI-Source now honours AIMLAPI_SOURCE (default agent/ragflow), as common/aimlapi_utils.py did. - HTTP-Referer and X-Title are dropped. They were never part of the infiniflow#17491 contract, which is the two X-AIMLAPI-* headers. - An override set to an empty value turns its header off, as os.environ.get(name, default) did in Python: os.LookupEnv tells "set to empty" apart from "unset", so an unset variable still sends the default while AIMLAPI_PARTNER_ID="" omits the partner header. The same holds for AIMLAPI_SOURCE. The destination gate is unchanged: both headers go only to api.aimlapi.com. A live chat through the driver carries exactly X-AIMLAPI-Source and X-AIMLAPI-Partner-ID and nothing else. ListModels no longer drops a row the gateway publishes without a type: it is kept and typed from its name, like any other catalog miss. A typed row for the same id still decides its family, and rows of a known family this driver cannot call (image, video, audio, batches) are still dropped. Tests: AIMLAPI_SOURCE honoured; an empty override omits its header without touching the other; defaults when unset; HTTP-Referer and X-Title never sent, to the gateway or to an overridden base URL; untyped rows kept and outranked by a typed duplicate. Restoring each old behaviour fails its test.
Summary
The aimlapi.com provider added in #17311 does not identify itself on any of its outgoing requests, so its traffic cannot be attributed to the integration. This PR adds the two headers AIMLAPI expects —
X-AIMLAPI-SourceandX-AIMLAPI-Partner-ID— to every request the provider makes.Change
common/aimlapi_utils.py(new) — a small helper that builds the header pair. It lives incommon/rather thanrag/llm/becauseapi/apps/restful_apis/aimlapi_api.pyis a blueprint loaded at API startup, and importing from therag.llmpackage would pull in every model module with it.rag/llm/{chat,embedding,cv}_model.py— the AIMLAPI adapters attach the headers to their OpenAI clients viawith_options(default_headers=…)aftersuper().__init__(), so the base class's timeout and retry wiring is untouched. Both the sync and async clients are covered, so streaming chat and async vision carry the headers too.rag/llm/model_meta.py— theAIMLAPImodel-meta sends them on its/v1/modelscatalog fetch.api/apps/restful_apis/aimlapi_api.py— the two agent-authorization calls send them as well; the partner-id default moves to the shared helper so there is one source for it. The consent URL of the "Get API key" flow also carries the client identifier as asourcequery parameter: consent — and any sign-up that happens during it — runs in a browser on AIMLAPI's side, which a request header cannot reach.Configuration — unchanged in spirit: production defaults are compiled in and both values stay overridable through the environment (
AIMLAPI_SOURCE,AIMLAPI_PARTNER_ID), matching the existingAIMLAPI_*variables.Testing —
test/unit_test/common/test_aimlapi_utils.pycovers the defaults, the environment overrides and a blank partner id. End to end, the headers were confirmed on the wire for chat, streaming chat, embeddings and the model-catalog fetch against the live API.