mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-05-05 01:52:33 +00:00
67 lines
2.9 KiB
Go
67 lines
2.9 KiB
Go
package interfaces
|
||
|
||
import (
|
||
"io"
|
||
"net/http"
|
||
|
||
"github.com/QuantumNous/new-api/dto"
|
||
relaycommon "github.com/QuantumNous/new-api/relay/common"
|
||
"github.com/QuantumNous/new-api/types"
|
||
"github.com/gin-gonic/gin"
|
||
)
|
||
|
||
// ChannelPlugin 定义Channel插件接口
|
||
// 继承原有的Adaptor接口,增加插件元数据
|
||
type ChannelPlugin interface {
|
||
// 插件元数据
|
||
Name() string
|
||
Version() string
|
||
Priority() int
|
||
|
||
// 原有Adaptor接口方法
|
||
Init(info *relaycommon.RelayInfo)
|
||
GetRequestURL(info *relaycommon.RelayInfo) (string, error)
|
||
SetupRequestHeader(c *gin.Context, req *http.Header, info *relaycommon.RelayInfo) error
|
||
ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayInfo, request *dto.GeneralOpenAIRequest) (any, error)
|
||
ConvertRerankRequest(c *gin.Context, relayMode int, request dto.RerankRequest) (any, error)
|
||
ConvertEmbeddingRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.EmbeddingRequest) (any, error)
|
||
ConvertAudioRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.AudioRequest) (io.Reader, error)
|
||
ConvertImageRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.ImageRequest) (any, error)
|
||
ConvertOpenAIResponsesRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.OpenAIResponsesRequest) (any, error)
|
||
DoRequest(c *gin.Context, info *relaycommon.RelayInfo, requestBody io.Reader) (any, error)
|
||
DoResponse(c *gin.Context, resp *http.Response, info *relaycommon.RelayInfo) (usage any, err *types.NewAPIError)
|
||
GetModelList() []string
|
||
GetChannelName() string
|
||
ConvertClaudeRequest(c *gin.Context, info *relaycommon.RelayInfo, request *dto.ClaudeRequest) (any, error)
|
||
ConvertGeminiRequest(c *gin.Context, info *relaycommon.RelayInfo, request *dto.GeminiChatRequest) (any, error)
|
||
}
|
||
|
||
// TaskChannelPlugin 定义Task类型的Channel插件接口
|
||
type TaskChannelPlugin interface {
|
||
// 插件元数据
|
||
Name() string
|
||
Version() string
|
||
Priority() int
|
||
|
||
// 原有TaskAdaptor接口方法
|
||
Init(info *relaycommon.RelayInfo)
|
||
ValidateRequestAndSetAction(c *gin.Context, info *relaycommon.RelayInfo) *dto.TaskError
|
||
BuildRequestURL(info *relaycommon.RelayInfo) (string, error)
|
||
BuildRequestHeader(c *gin.Context, req *http.Request, info *relaycommon.RelayInfo) error
|
||
BuildRequestBody(c *gin.Context, info *relaycommon.RelayInfo) (io.Reader, error)
|
||
DoRequest(c *gin.Context, info *relaycommon.RelayInfo, requestBody io.Reader) (*http.Response, error)
|
||
DoResponse(c *gin.Context, resp *http.Response, info *relaycommon.RelayInfo) (taskID string, taskData []byte, err *dto.TaskError)
|
||
GetModelList() []string
|
||
GetChannelName() string
|
||
FetchTask(baseUrl, key string, body map[string]any) (*http.Response, error)
|
||
ParseTaskResult(respBody []byte) (*relaycommon.TaskInfo, error)
|
||
}
|
||
|
||
// ChannelConfig 插件配置
|
||
type ChannelConfig struct {
|
||
Enabled bool `yaml:"enabled"`
|
||
Priority int `yaml:"priority"`
|
||
Config map[string]interface{} `yaml:"config"`
|
||
}
|
||
|