Skip to content

支持Sora做为上游渠道 - #1997

Merged
Calcium-Ion merged 2 commits into
QuantumNous:mainfrom
feitianbubu:pr/add-sora-fetch-task
Oct 10, 2025
Merged

支持Sora做为上游渠道#1997
Calcium-Ion merged 2 commits into
QuantumNous:mainfrom
feitianbubu:pr/add-sora-fetch-task

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Oct 10, 2025

Copy link
Copy Markdown
Member
  1. 增加Sora任务查询接口
  2. 返回Sora标准结构
  3. 支持Sora做为上游渠道

Summary by CodeRabbit

  • New Features

    • Added GET /v1/videos/:task_id to retrieve video task results by ID.
    • Expanded video API to support fetching by ID via GET alongside existing POST flow.
  • Refactor

    • Updated video task responses to return the full task payload instead of only task_id.
    • Improved ID handling by accepting task_id in responses for better interoperability.

@coderabbitai

coderabbitai Bot commented Oct 10, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds GET support for fetching video tasks by ID in /v1/videos, sets relay mode accordingly without channel selection, and updates the Sora task adaptor to return a full response object with TaskID fallback. Introduces a new router route GET /videos/:task_id sharing the existing RelayTask handler.

Changes

Cohort / File(s) Summary
Routing and distributor updates
middleware/distributor.go, router/video-router.go
Adds GET handling for /v1/videos to fetch by task ID: sets relayMode to VideoFetchByID, disables channel selection, and registers GET /videos/:task_id using the existing RelayTask handler.
Sora task adaptor response handling
relay/channel/task/sora/adaptor.go
Replaces minimal response with full responseTask JSON; introduces TaskID field fallback to ID, errors if both empty; maintains compatibility with old interface while changing success payload structure.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor C as Client
    participant R as v1 Router
    participant D as Distributor (Middleware)
    participant H as RelayTask Handler
    participant A as Sora Adaptor
    participant S as Upstream Sora

    rect rgb(245,248,255)
    note over C,R: New flow: GET /v1/videos/:task_id
    C->>R: GET /videos/{task_id}
    R->>D: Route request
    D->>D: Set relayMode=VideoFetchByID<br/>shouldSelectChannel=false
    D->>H: Forward with task_id
    end

    H->>A: Fetch task by ID
    A->>S: Request task status/result
    S-->>A: Response
    A-->>H: Full responseTask JSON (with TaskID/ID)
    H-->>C: HTTP 200 + responseTask

    alt POST /v1/videos (existing)
      C->>R: POST /videos
      R->>D: Route request
      D->>D: Select channel (normal flow)
      D->>H: Create task
      H->>A: Submit generation task
      A->>S: Create task
      S-->>A: Ack with task_id
      A-->>H: responseTask JSON
      H-->>C: HTTP 200 + task info
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • seefs001
  • xyfacai

Poem

Thump-thump, I hop through routes anew,
A GET by ID, a tidy view.
Sora hums with fuller tales,
TaskID sails where ID fails.
Ears up, code’s in tidy queues—
Carrots for logs, and fewer 404 blues. 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 “支持Sora做为上游渠道” succinctly and accurately describes the primary change—adding support for Sora as an upstream channel—without extraneous details or ambiguity, making it clear to reviewers what the pull request implements.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@Calcium-Ion
Calcium-Ion merged commit 5a7f498 into QuantumNous:main Oct 10, 2025
1 check was pending

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

🧹 Nitpick comments (1)
relay/channel/task/sora/adaptor.go (1)

115-121: Improve error message clarity.

The error message at line 116 says "task_id is empty", but at this point both ID and TaskID are confirmed to be empty. The message should reflect that both identifiers are missing.

Apply this diff to clarify the error:

 	if dResp.ID == "" {
 		if dResp.TaskID == "" {
-			taskErr = service.TaskErrorWrapper(fmt.Errorf("task_id is empty"), "invalid_response", http.StatusInternalServerError)
+			taskErr = service.TaskErrorWrapper(fmt.Errorf("both id and task_id are empty"), "invalid_response", http.StatusInternalServerError)
 			return
 		}
 		dResp.ID = dResp.TaskID
 		dResp.TaskID = ""
 	}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f4d7bde and 4c1f138.

📒 Files selected for processing (3)
  • middleware/distributor.go (1 hunks)
  • relay/channel/task/sora/adaptor.go (2 hunks)
  • router/video-router.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
middleware/distributor.go (2)
dto/request_common.go (1)
  • Request (8-12)
relay/constant/relay_mode.go (1)
  • RelayModeVideoFetchByID (43-43)
relay/channel/task/sora/adaptor.go (1)
service/error.go (1)
  • TaskErrorWrapper (139-155)
router/video-router.go (1)
controller/relay.go (1)
  • RelayTask (383-426)
🔇 Additional comments (4)
router/video-router.go (1)

22-22: LGTM! Route follows established pattern.

The new GET route for /videos/:task_id correctly reuses the existing RelayTask handler and mirrors the pattern used for /video/generations/:task_id at line 16. This aligns with OpenAI's video API conventions.

middleware/distributor.go (1)

187-189: LGTM! Fetch-by-ID handling follows established pattern.

The GET request handling correctly:

  • Sets relay mode to VideoFetchByID
  • Disables channel selection (shouldSelectChannel = false)

This mirrors the pattern used for Midjourney (lines 131-135) and Suno (lines 159-161) fetch operations, where tasks are already associated with a channel.

relay/channel/task/sora/adaptor.go (2)

37-37: LGTM! Backward compatibility field added correctly.

The TaskID field with omitempty tag properly supports the old interface while the main ID field serves as the primary identifier. The omitempty ensures task_id only appears in responses when explicitly populated by upstream sources.


123-123: Confirm consumer compatibility with expanded response schema
GET /v1/videos/{task_id} now returns the full responseTask object instead of a minimal payload; verify all downstream consumers (SDKs, integrations, downstream services) can correctly process the expanded response format.

ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
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