Skip to content

Refactor: completion -> completions#14584

Merged
wangq8 merged 1 commit intoinfiniflow:mainfrom
wangq8:refactor/completion-completions
May 6, 2026
Merged

Refactor: completion -> completions#14584
wangq8 merged 1 commit intoinfiniflow:mainfrom
wangq8:refactor/completion-completions

Conversation

@wangq8
Copy link
Copy Markdown
Collaborator

@wangq8 wangq8 commented May 6, 2026

What problem does this PR solve?

Keep only /completions, deprecated /completion

Type of change

  • Refactoring

@wangq8 wangq8 requested a review from buua436 May 6, 2026 07:57
@wangq8 wangq8 added the ci Continue Integration label May 6, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

📝 Walkthrough

Walkthrough

This PR standardizes API endpoint naming by renaming completion endpoints from singular to plural paths (/completion/completions) across agent and search APIs, updates corresponding client SDKs and test helpers, and adds new dataset-related API test helpers.

Changes

Chat & Search Completion Endpoint Standardization

Layer / File(s) Summary
API Route Definitions
api/apps/restful_apis/agent_api.py, api/apps/restful_apis/search_api.py
Routes updated from singular /completion to plural /completions for agent chat and search completion endpoints.
Backward Compatibility
api/apps/backward_compat.py, api/apps/services/canvas_replica_service.py
Deprecated endpoint references and internal docstrings updated to point to new /completions paths.
Client & SDK Updates
admin/client/ragflow_client.py, sdk/python/ragflow_sdk/modules/session.py
Client implementations updated to call /completions endpoints; chat_on_session also switches payload field from conversation_id to session_id and updates API base configuration.
Frontend API Utilities
web/src/utils/api.ts
API endpoint paths updated in searchCompletion and agentChatCompletion properties to use /completions.
Documentation & Tests
docs/references/http_api_reference.md, test/testcases/test_http_api/common.py, test/testcases/test_sdk_api/test_session_management/test_create_session_with_chat_assistant.py
HTTP API reference documentation and test expectations updated to reflect new endpoint paths; agent completions test helper updated.

Dataset API Test Helpers

Layer / File(s) Summary
Test Support Functions
test/testcases/test_http_api/common.py
Fifteen new helper functions added for dataset operations: get_dataset, get_ingestion_summary, list_ingestion_logs, get_ingestion_log, run_index, trace_index, delete_index, run_embedding, list_tags, aggregate_tags, delete_tags, rename_tag, get_flattened_metadata, and search_dataset.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • infiniflow/ragflow#14229: Updates chat completion endpoints to use /chat/completions and shifts session identifiers into request payloads, aligning with the endpoint standardization changes.
  • infiniflow/ragflow#14582: Modifies agent chat completion routing and backward-compatibility forwarding for the same endpoint refactoring.
  • infiniflow/ragflow#14222: Updates test HTTP helpers in the same file with dataset API additions and route changes.

Suggested labels

☯️ refactor, 🐖 api, 🧪 test, python, size:M


🐰 Hop along, dear friends, the paths are now plural!
Completions flow smoother, no longer singular.
From /completion to /completions we leap,
With datasets and sessions stacked neat in a heap. 🌾✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% 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
Title check ✅ Passed The title concisely describes the main refactoring objective: renaming completion endpoints from singular to plural form across the codebase.
Description check ✅ Passed The description addresses the problem (keeping only /completions, deprecating /completion) and correctly identifies the change type (Refactoring), meeting the template requirements.
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.

Warning

Review ran into problems

🔥 Problems

Timed out fetching pipeline failures after 30000ms

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 marked this pull request as ready for review May 6, 2026 07:58
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label May 6, 2026
@wangq8 wangq8 requested a review from xugangqiang May 6, 2026 07:58
Copy link
Copy Markdown
Contributor

@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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/references/http_api_reference.md (1)

4483-4606: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Agent completions section still mixes old route semantics with new route format.

Line 4483 still presents POST /api/v1/agents/{agent_id}/completions, while Line 4496 (and examples) use POST /api/v1/agents/chat/completions.
Also, Line 4603 documents agent_id as a Path parameter, but this endpoint now carries agent_id in the request body (Line 4507).
This is a contract mismatch and will mislead SDK/client implementers.

Suggested doc fix
-**POST** `/api/v1/agents/{agent_id}/completions`
+**POST** `/api/v1/agents/chat/completions`

@@
-##### Request parameters
-
-- `agent_id`: (*Path parameter*), `string`
-  The ID of the associated agent.
-- `"question"`: (*Body Parameter*), `string`, *Required*
-  The question to start an AI-powered conversation.
+##### Request parameters
+
+- `"agent_id"`: (*Body parameter*), `string`, *Required*
+  The ID of the associated agent.
+- `"query"`: (*Body parameter*), `string`, *Required*
+  The question to start an AI-powered conversation.
🤖 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 `@docs/references/http_api_reference.md` around lines 4483 - 4606, The docs mix
two endpoint semantics: remove the deprecated path-style route POST
/api/v1/agents/{agent_id}/completions and consistently document the new POST
/api/v1/agents/chat/completions route used in the examples; update all examples
and the "Request" section to show agent_id as a JSON body field (not a path
parameter), change the "Request parameters" entry that currently lists
`agent_id` as a Path parameter to a Body parameter, and ensure the documented
body fields (e.g., "agent_id", "query"/"question", "stream", etc.) and SSE
stream descriptions reference POST /api/v1/agents/chat/completions exclusively
so SDKs/clients are not misled.
🤖 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 `@api/apps/restful_apis/agent_api.py`:
- Around line 848-849: Remove the deprecated singular route decorator
"@manager.route(\"/agents/chat/completion\", methods=[\"POST\"])" from the
handler so only "/agents/chat/completions" is registered as the primary
endpoint; ensure the handler (the function decorated with manager.route for
completions) remains unchanged. Add a separate backward-compatibility wrapper
route elsewhere that registers "/agents/chat/completion" and calls the same
handler but logs/emits a deprecation warning (use the existing logging facility)
before forwarding the request. Make sure to reference the same handler function
when forwarding to avoid duplicating logic and keep only the plural route as
first-class.

In `@api/apps/restful_apis/search_api.py`:
- Around line 176-177: Remove the deprecated singular route by deleting the
`@manager.route`("/searches/<search_id>/completion", methods=["POST"]) decorator
in search_api.py so only the plural
`@manager.route`("/searches/<search_id>/completions", methods=["POST"]) remains;
if a compatibility shim is required, implement it only inside
api/apps/backward_compat.py (not in this module) and ensure that shim logs an
explicit deprecation warning when invoked.

---

Outside diff comments:
In `@docs/references/http_api_reference.md`:
- Around line 4483-4606: The docs mix two endpoint semantics: remove the
deprecated path-style route POST /api/v1/agents/{agent_id}/completions and
consistently document the new POST /api/v1/agents/chat/completions route used in
the examples; update all examples and the "Request" section to show agent_id as
a JSON body field (not a path parameter), change the "Request parameters" entry
that currently lists `agent_id` as a Path parameter to a Body parameter, and
ensure the documented body fields (e.g., "agent_id", "query"/"question",
"stream", etc.) and SSE stream descriptions reference POST
/api/v1/agents/chat/completions exclusively so SDKs/clients are not misled.
🪄 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: 835df4b6-7410-497e-a387-bb3b5e13e2d4

📥 Commits

Reviewing files that changed from the base of the PR and between a190a6d and b3c7811.

📒 Files selected for processing (10)
  • admin/client/ragflow_client.py
  • api/apps/backward_compat.py
  • api/apps/restful_apis/agent_api.py
  • api/apps/restful_apis/search_api.py
  • api/apps/services/canvas_replica_service.py
  • docs/references/http_api_reference.md
  • sdk/python/ragflow_sdk/modules/session.py
  • test/testcases/test_http_api/common.py
  • test/testcases/test_sdk_api/test_session_management/test_create_session_with_chat_assistant.py
  • web/src/utils/api.ts

Comment on lines 848 to +849
@manager.route("/agents/chat/completion", methods=["POST"]) # noqa: F821
@manager.route("/agents/chat/completions", methods=["POST"]) # noqa: F821
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

Deprecated singular agent route is still first-class in the main API.
Line 848 keeps /agents/chat/completion active without deprecation handling. That conflicts with the objective to keep only /completions. Recommend removing the singular decorator from this handler and serving old-path compatibility only via backward-compat routes with warnings.

Suggested diff
-@manager.route("/agents/chat/completion", methods=["POST"])  # noqa: F821
 `@manager.route`("/agents/chat/completions", methods=["POST"])  # noqa: F821
 `@login_required`
 `@add_tenant_id_to_kwargs`
 async def agent_chat_completion(tenant_id, agent_id=None):
🤖 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 `@api/apps/restful_apis/agent_api.py` around lines 848 - 849, Remove the
deprecated singular route decorator "@manager.route(\"/agents/chat/completion\",
methods=[\"POST\"])" from the handler so only "/agents/chat/completions" is
registered as the primary endpoint; ensure the handler (the function decorated
with manager.route for completions) remains unchanged. Add a separate
backward-compatibility wrapper route elsewhere that registers
"/agents/chat/completion" and calls the same handler but logs/emits a
deprecation warning (use the existing logging facility) before forwarding the
request. Make sure to reference the same handler function when forwarding to
avoid duplicating logic and keep only the plural route as first-class.

Comment on lines 176 to +177
@manager.route("/searches/<search_id>/completion", methods=["POST"]) # noqa: F821
@manager.route("/searches/<search_id>/completions", methods=["POST"]) # noqa: F821
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

Primary API still exposes deprecated singular /completion path.
Line 176 keeps the old route active in the main API module, which contradicts the stated migration goal (“keep only /completions and deprecate /completion”). Please remove the singular route here and keep any compatibility shim only in api/apps/backward_compat.py with explicit warning logs.

Suggested diff
-@manager.route("/searches/<search_id>/completion", methods=["POST"])  # noqa: F821
 `@manager.route`("/searches/<search_id>/completions", methods=["POST"])  # noqa: F821
 `@login_required`
 `@validate_request`("question")
 async def completion(search_id):
📝 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
@manager.route("/searches/<search_id>/completion", methods=["POST"]) # noqa: F821
@manager.route("/searches/<search_id>/completions", methods=["POST"]) # noqa: F821
`@manager.route`("/searches/<search_id>/completions", methods=["POST"]) # noqa: F821
🤖 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 `@api/apps/restful_apis/search_api.py` around lines 176 - 177, Remove the
deprecated singular route by deleting the
`@manager.route`("/searches/<search_id>/completion", methods=["POST"]) decorator
in search_api.py so only the plural
`@manager.route`("/searches/<search_id>/completions", methods=["POST"]) remains;
if a compatibility shim is required, implement it only inside
api/apps/backward_compat.py (not in this module) and ensure that shim logs an
explicit deprecation warning when invoked.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.16%. Comparing base (a190a6d) to head (b3c7811).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14584   +/-   ##
=======================================
  Coverage   94.16%   94.16%           
=======================================
  Files          10       10           
  Lines         703      703           
  Branches      112      112           
=======================================
  Hits          662      662           
  Misses         25       25           
  Partials       16       16           

☔ View full report in Codecov by Sentry.
📢 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.

@xugangqiang
Copy link
Copy Markdown
Contributor

LGTM

@wangq8 wangq8 merged commit f32034e into infiniflow:main May 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants