mirror of
https://gh-proxy.org/https://github.com/klinsmaya/new-api.git
synced 2026-11-08 01:17:09 +08:00
Add the synchronous openai_image host protocol so a task plugin can claim POST /v1/images/generations and /v1/images/edits; the host submits the task, polls it inside the request and lets the plugin render the OpenAI image response. Unclaimed models still fall back to the HTTP image relay. - Migrate Ali (Bailian) image models to the alibaba plugin and remove the ali channel image/wan adaptors and the qwen model setting - Add Doubao Seedream image generation to the doubao plugin - Support retainResult on routes and indexed multipart file references - Settle image counts from upstream usage or image payloads; document the rule in the billing conventions and plugin API docs - Show billing source and task artifacts in usage logs; rename the DoubaoVideo channel display name to Doubao and refresh the favicon
61 lines
2.7 KiB
Go
61 lines
2.7 KiB
Go
package router
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/QuantumNous/new-api/controller"
|
|
"github.com/QuantumNous/new-api/middleware"
|
|
pluginruntime "github.com/QuantumNous/new-api/pkg/jsplugin"
|
|
"github.com/QuantumNous/new-api/relaykit/types"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func SetTaskPluginProtocolRouter(router *gin.Engine) {
|
|
for _, protocol := range pluginruntime.HostProtocols() {
|
|
for _, operation := range protocol.Operations {
|
|
for _, method := range operation.Methods {
|
|
handlers, err := taskPluginProtocolHandlers(protocol.Name, operation.Name)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
router.Handle(method, operation.Path, handlers...)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func taskPluginProtocolHandlers(protocol, operation string) ([]gin.HandlerFunc, error) {
|
|
switch protocol + "." + operation {
|
|
case "openai_responses.create":
|
|
return []gin.HandlerFunc{
|
|
middleware.RouteTag("relay"), middleware.SystemPerformanceCheck(), middleware.TokenAuth(),
|
|
middleware.ModelRequestRateLimit(), middleware.PinTaskPluginEndpoint(), middleware.PrepareTaskPluginEndpoint(), middleware.Distribute(),
|
|
func(c *gin.Context) {
|
|
controller.RelayTaskPluginEndpoint(c, func(c *gin.Context) { controller.Relay(c, types.RelayFormatOpenAIResponses) })
|
|
},
|
|
}, nil
|
|
case "openai_image.generate", "openai_image.edit":
|
|
return []gin.HandlerFunc{
|
|
middleware.RouteTag("relay"), middleware.SystemPerformanceCheck(), middleware.TokenAuth(),
|
|
middleware.ModelRequestRateLimit(), middleware.PinTaskPluginEndpoint(), middleware.PrepareTaskPluginEndpoint(), middleware.Distribute(),
|
|
func(c *gin.Context) {
|
|
controller.RelayTaskPluginEndpoint(c, func(c *gin.Context) { controller.Relay(c, types.RelayFormatOpenAIImage) })
|
|
},
|
|
}, nil
|
|
case "openai_video.create":
|
|
return []gin.HandlerFunc{
|
|
middleware.RouteTag("relay"), middleware.TokenAuth(), middleware.SystemPerformanceCheck(),
|
|
middleware.PinTaskPluginEndpoint(), middleware.TaskPluginEndpointOnly(middleware.ModelRequestRateLimit()), middleware.PrepareTaskPluginEndpoint(), middleware.Distribute(),
|
|
func(c *gin.Context) { controller.RelayTaskPluginEndpoint(c, controller.RelayTask) },
|
|
}, nil
|
|
case "openai_responses.retrieve":
|
|
return []gin.HandlerFunc{middleware.RouteTag("relay"), middleware.TokenAuth(), controller.RetrieveTaskPluginResponse}, nil
|
|
case "openai_video.retrieve":
|
|
return []gin.HandlerFunc{middleware.RouteTag("relay"), middleware.TokenAuth(), middleware.Distribute(), controller.RelayTaskFetch}, nil
|
|
case "openai_video.content":
|
|
return []gin.HandlerFunc{middleware.RouteTag("relay"), middleware.TokenAuth(), controller.VideoProxy}, nil
|
|
default:
|
|
return nil, fmt.Errorf("host protocol registry operation %s.%s has no handler", protocol, operation)
|
|
}
|
|
}
|