fix(openai): streaming image relay + image edit (sync upstream pair) - #160
Closed
jjcc123312 wants to merge 2 commits into
Closed
fix(openai): streaming image relay + image edit (sync upstream pair)#160jjcc123312 wants to merge 2 commits into
jjcc123312 wants to merge 2 commits into
Conversation
…API (QuantumNous#4608) * fix(openai): support streaming image relay * fix(openai): keep image edit multipart body reusable * test(openai): cover image stream usage details * test(openai): cover image edit fallback stream field * fix(openai): wrap image json fallback as stream * fix(relay): support OpenAI image streaming * fix(openai): record image stream upstream error events * fix(openai): harden image stream relay * fix(openai): return image JSON errors * fix(relay): reset stream status per scanner run * fix(relay): drop upstream credit passthrough * fix(openai): keep image errors minimal * fix(openai): keep image error status from response --------- Co-authored-by: CaIon <i@caion.me>
Route OpenAI image streaming through shared stream handling, split image/realtime/usage helpers for maintainability, and include the related image request and rate limit updates. (cherry picked from commit 59a93cf) Fork adaptations during cherry-pick: - Keep dto.ImageRequest.Stream as *bool with Rule-5 pointer comment (already pointer on fork) - Keep blockrun-era ConvertImageRequest stripping of image stream fields on passthrough - Revert bundled GlobalApiRateLimitNum 360->180 and GlobalWebRateLimitNum 120->60 (prod uses env overrides) - Keep SSE DefaultMaxScannerBufferSize 128MB bump; fix stale 64MB comment Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Author
|
暂不同步:此 PR 同步的是上游代码,且 OpenCodeReview 指出上游实现存在质量问题(非本次合并引入)。当前无强需求,改为按需单独同步。先关闭,需要时再开。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Syncs the upstream OpenAI Images API streaming relay + image edit feature into the fork as a paired cherry-pick:
d2576ddcd— fix(openai): support streaming image relay and image edit for images API (fix(openai): support streaming image relay and image edit for images API QuantumNous/new-api#4608)59a93cf5c— fix(openai): align image streaming relay governance (splitsrelay-openai.gointorelay_image.go/relay_realtime.go/usage.go, routes image streaming through shared stream handling)These two commits are a pair and were applied in order (d2576 first).
Conflict resolutions
dto/openai_image.go— kept the fork'sStream *boolfield with the Rule-5 pointer comment. (Upstream's d2576 used a non-pointerbool; upstream's own follow-up 59a93 independently converts it to*bool+IsStreampointer-deref — matching what the fork already had.)relay/helper/valid_request.go— multipartstreamparsing assignsimageRequest.Stream = common.GetPointer(stream)(pointer form for the fork's*bool).relay/channel/openai/adaptor.go— took the upstream streaming branch inDoResponse(if info.IsStream { OpenaiImageStreamHandler } else { OpenaiImageHandler }, incl. theOpenaiHandlerWithUsage→OpenaiImageHandlerrename). Kept the fork's blockrun-eraConvertImageRequestbehavior that strips image streaming fields (stream/partial_images) on the passthrough conversion path — new-api only synthesizes SSE for opt-in channels (e.g. blockrun); forwarding those fields would 400 upstreams that don't support image streaming.relay/channel/openai/relay-openai.go— the 675-line deletion is functions moved to the new files. The fork's codex usage-chunk path stays here (OaiStreamHandler/sendStreamData) and is verified intact; the codexShouldIncludeUsagewiring inchat_via_responses.go/helper.gois untouched by this sync.TestConvertImageEditRequestMultipart(from 59a93) asserted upstream's stream-preservation behavior; updated it to assert the fork's deliberate strip behavior on the passthrough path. Other image stream/edit tests adapted to the*boolfield.Two bundled unrelated changes that rode along in 59a93
common/init.go— 59a93 bumpedGlobalApiRateLimitNum180→360 andGlobalWebRateLimitNum60→120. Reverted both back to 180 / 60 (kept code defaults; prod overrides these via env anyway, so this keeps the change minimal).relay/helper/stream_scanner.go— 59a93 bumpedDefaultMaxScannerBufferSize64MB→128MB. Kept the 128MB value (approved) and fixed the stale// 64MBcomment to// 128MB.Verification
go build ./relay/... ./common/... ./dto/...— exit 0go vet ./relay/... ./dto/...— no warnings in touched files (only pre-existing warnings in unrelated channel adaptors /common/custom-event.go, confirmed present onmain)relay/common/dtoGlobalApiRateLimitNum=180,GlobalWebRateLimitNum=60DefaultMaxScannerBufferSize = 128 << 20go test ./relay/channel/blockrun/... ./relay/channel/openai/... ./relay/helper/...— all pass (blockrun is a hot path built on the openai adaptor; its tests pass)🤖 Generated with Claude Code