adaptor.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. package openai
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "io"
  8. "mime/multipart"
  9. "net/http"
  10. "net/textproto"
  11. "one-api/common"
  12. "one-api/constant"
  13. "one-api/dto"
  14. "one-api/relay/channel"
  15. "one-api/relay/channel/ai360"
  16. "one-api/relay/channel/lingyiwanwu"
  17. "one-api/relay/channel/minimax"
  18. "one-api/relay/channel/moonshot"
  19. "one-api/relay/channel/openrouter"
  20. "one-api/relay/channel/xinference"
  21. relaycommon "one-api/relay/common"
  22. "one-api/relay/common_handler"
  23. relayconstant "one-api/relay/constant"
  24. "one-api/service"
  25. "one-api/types"
  26. "path/filepath"
  27. "strings"
  28. "github.com/gin-gonic/gin"
  29. )
  30. type Adaptor struct {
  31. ChannelType int
  32. ResponseFormat string
  33. }
  34. // parseReasoningEffortFromModelSuffix 从模型名称中解析推理级别
  35. // support OAI models: o1-mini/o3-mini/o4-mini/o1/o3 etc...
  36. // minimal effort only available in gpt-5
  37. func parseReasoningEffortFromModelSuffix(model string) (string, string) {
  38. effortSuffixes := []string{"-high", "-minimal", "-low", "-medium"}
  39. for _, suffix := range effortSuffixes {
  40. if strings.HasSuffix(model, suffix) {
  41. effort := strings.TrimPrefix(suffix, "-")
  42. originModel := strings.TrimSuffix(model, suffix)
  43. return effort, originModel
  44. }
  45. }
  46. return "", model
  47. }
  48. func (a *Adaptor) ConvertGeminiRequest(c *gin.Context, info *relaycommon.RelayInfo, request *dto.GeminiChatRequest) (any, error) {
  49. // 使用 service.GeminiToOpenAIRequest 转换请求格式
  50. openaiRequest, err := service.GeminiToOpenAIRequest(request, info)
  51. if err != nil {
  52. return nil, err
  53. }
  54. return a.ConvertOpenAIRequest(c, info, openaiRequest)
  55. }
  56. func (a *Adaptor) ConvertClaudeRequest(c *gin.Context, info *relaycommon.RelayInfo, request *dto.ClaudeRequest) (any, error) {
  57. //if !strings.Contains(request.Model, "claude") {
  58. // return nil, fmt.Errorf("you are using openai channel type with path /v1/messages, only claude model supported convert, but got %s", request.Model)
  59. //}
  60. //if common.DebugEnabled {
  61. // bodyBytes := []byte(common.GetJsonString(request))
  62. // err := os.WriteFile(fmt.Sprintf("claude_request_%s.txt", c.GetString(common.RequestIdKey)), bodyBytes, 0644)
  63. // if err != nil {
  64. // println(fmt.Sprintf("failed to save request body to file: %v", err))
  65. // }
  66. //}
  67. aiRequest, err := service.ClaudeToOpenAIRequest(*request, info)
  68. if err != nil {
  69. return nil, err
  70. }
  71. //if common.DebugEnabled {
  72. // println(fmt.Sprintf("convert claude to openai request result: %s", common.GetJsonString(aiRequest)))
  73. // // Save request body to file for debugging
  74. // bodyBytes := []byte(common.GetJsonString(aiRequest))
  75. // err = os.WriteFile(fmt.Sprintf("claude_to_openai_request_%s.txt", c.GetString(common.RequestIdKey)), bodyBytes, 0644)
  76. // if err != nil {
  77. // println(fmt.Sprintf("failed to save request body to file: %v", err))
  78. // }
  79. //}
  80. if info.SupportStreamOptions && info.IsStream {
  81. aiRequest.StreamOptions = &dto.StreamOptions{
  82. IncludeUsage: true,
  83. }
  84. }
  85. return a.ConvertOpenAIRequest(c, info, aiRequest)
  86. }
  87. func (a *Adaptor) Init(info *relaycommon.RelayInfo) {
  88. a.ChannelType = info.ChannelType
  89. // initialize ThinkingContentInfo when thinking_to_content is enabled
  90. if info.ChannelSetting.ThinkingToContent {
  91. info.ThinkingContentInfo = relaycommon.ThinkingContentInfo{
  92. IsFirstThinkingContent: true,
  93. SendLastThinkingContent: false,
  94. HasSentThinkingContent: false,
  95. }
  96. }
  97. }
  98. func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
  99. if info.RelayMode == relayconstant.RelayModeRealtime {
  100. if strings.HasPrefix(info.BaseUrl, "https://") {
  101. baseUrl := strings.TrimPrefix(info.BaseUrl, "https://")
  102. baseUrl = "wss://" + baseUrl
  103. info.BaseUrl = baseUrl
  104. } else if strings.HasPrefix(info.BaseUrl, "http://") {
  105. baseUrl := strings.TrimPrefix(info.BaseUrl, "http://")
  106. baseUrl = "ws://" + baseUrl
  107. info.BaseUrl = baseUrl
  108. }
  109. }
  110. switch info.ChannelType {
  111. case constant.ChannelTypeAzure:
  112. apiVersion := info.ApiVersion
  113. if apiVersion == "" {
  114. apiVersion = constant.AzureDefaultAPIVersion
  115. }
  116. // https://learn.microsoft.com/en-us/azure/cognitive-services/openai/chatgpt-quickstart?pivots=rest-api&tabs=command-line#rest-api
  117. requestURL := strings.Split(info.RequestURLPath, "?")[0]
  118. requestURL = fmt.Sprintf("%s?api-version=%s", requestURL, apiVersion)
  119. task := strings.TrimPrefix(requestURL, "/v1/")
  120. // 特殊处理 responses API
  121. if info.RelayMode == relayconstant.RelayModeResponses {
  122. requestURL = fmt.Sprintf("/openai/v1/responses?api-version=preview")
  123. return relaycommon.GetFullRequestURL(info.BaseUrl, requestURL, info.ChannelType), nil
  124. }
  125. model_ := info.UpstreamModelName
  126. // 2025年5月10日后创建的渠道不移除.
  127. if info.ChannelCreateTime < constant.AzureNoRemoveDotTime {
  128. model_ = strings.Replace(model_, ".", "", -1)
  129. }
  130. // https://github.com/songquanpeng/one-api/issues/67
  131. requestURL = fmt.Sprintf("/openai/deployments/%s/%s", model_, task)
  132. if info.RelayMode == relayconstant.RelayModeRealtime {
  133. requestURL = fmt.Sprintf("/openai/realtime?deployment=%s&api-version=%s", model_, apiVersion)
  134. }
  135. return relaycommon.GetFullRequestURL(info.BaseUrl, requestURL, info.ChannelType), nil
  136. case constant.ChannelTypeMiniMax:
  137. return minimax.GetRequestURL(info)
  138. case constant.ChannelTypeCustom:
  139. url := info.BaseUrl
  140. url = strings.Replace(url, "{model}", info.UpstreamModelName, -1)
  141. return url, nil
  142. default:
  143. if info.RelayFormat == relaycommon.RelayFormatClaude || info.RelayFormat == relaycommon.RelayFormatGemini {
  144. return fmt.Sprintf("%s/v1/chat/completions", info.BaseUrl), nil
  145. }
  146. return relaycommon.GetFullRequestURL(info.BaseUrl, info.RequestURLPath, info.ChannelType), nil
  147. }
  148. }
  149. func (a *Adaptor) SetupRequestHeader(c *gin.Context, header *http.Header, info *relaycommon.RelayInfo) error {
  150. channel.SetupApiRequestHeader(info, c, header)
  151. if info.ChannelType == constant.ChannelTypeAzure {
  152. header.Set("api-key", info.ApiKey)
  153. return nil
  154. }
  155. if info.ChannelType == constant.ChannelTypeOpenAI && "" != info.Organization {
  156. header.Set("OpenAI-Organization", info.Organization)
  157. }
  158. if info.RelayMode == relayconstant.RelayModeRealtime {
  159. swp := c.Request.Header.Get("Sec-WebSocket-Protocol")
  160. if swp != "" {
  161. items := []string{
  162. "realtime",
  163. "openai-insecure-api-key." + info.ApiKey,
  164. "openai-beta.realtime-v1",
  165. }
  166. header.Set("Sec-WebSocket-Protocol", strings.Join(items, ","))
  167. //req.Header.Set("Sec-WebSocket-Key", c.Request.Header.Get("Sec-WebSocket-Key"))
  168. //req.Header.Set("Sec-Websocket-Extensions", c.Request.Header.Get("Sec-Websocket-Extensions"))
  169. //req.Header.Set("Sec-Websocket-Version", c.Request.Header.Get("Sec-Websocket-Version"))
  170. } else {
  171. header.Set("openai-beta", "realtime=v1")
  172. header.Set("Authorization", "Bearer "+info.ApiKey)
  173. }
  174. } else {
  175. header.Set("Authorization", "Bearer "+info.ApiKey)
  176. }
  177. if info.ChannelType == constant.ChannelTypeOpenRouter {
  178. header.Set("HTTP-Referer", "https://www.newapi.ai")
  179. header.Set("X-Title", "New API")
  180. }
  181. return nil
  182. }
  183. func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayInfo, request *dto.GeneralOpenAIRequest) (any, error) {
  184. if request == nil {
  185. return nil, errors.New("request is nil")
  186. }
  187. if info.ChannelType != constant.ChannelTypeOpenAI && info.ChannelType != constant.ChannelTypeAzure {
  188. request.StreamOptions = nil
  189. }
  190. if info.ChannelType == constant.ChannelTypeOpenRouter {
  191. if len(request.Usage) == 0 {
  192. request.Usage = json.RawMessage(`{"include":true}`)
  193. }
  194. // 适配 OpenRouter 的 thinking 后缀
  195. if strings.HasSuffix(info.UpstreamModelName, "-thinking") {
  196. info.UpstreamModelName = strings.TrimSuffix(info.UpstreamModelName, "-thinking")
  197. request.Model = info.UpstreamModelName
  198. if len(request.Reasoning) == 0 {
  199. reasoning := map[string]any{
  200. "enabled": true,
  201. }
  202. if request.ReasoningEffort != "" && request.ReasoningEffort != "none" {
  203. reasoning["effort"] = request.ReasoningEffort
  204. }
  205. marshal, err := common.Marshal(reasoning)
  206. if err != nil {
  207. return nil, fmt.Errorf("error marshalling reasoning: %w", err)
  208. }
  209. request.Reasoning = marshal
  210. }
  211. } else {
  212. if len(request.Reasoning) == 0 {
  213. // 适配 OpenAI 的 ReasoningEffort 格式
  214. if request.ReasoningEffort != "" {
  215. reasoning := map[string]any{
  216. "enabled": true,
  217. }
  218. if request.ReasoningEffort != "none" {
  219. reasoning["effort"] = request.ReasoningEffort
  220. marshal, err := common.Marshal(reasoning)
  221. if err != nil {
  222. return nil, fmt.Errorf("error marshalling reasoning: %w", err)
  223. }
  224. request.Reasoning = marshal
  225. }
  226. }
  227. }
  228. }
  229. }
  230. if strings.HasPrefix(request.Model, "o") || strings.HasPrefix(request.Model, "gpt-5") {
  231. if request.MaxCompletionTokens == 0 && request.MaxTokens != 0 {
  232. request.MaxCompletionTokens = request.MaxTokens
  233. request.MaxTokens = 0
  234. }
  235. if strings.HasPrefix(request.Model, "o") {
  236. request.Temperature = nil
  237. }
  238. if strings.HasPrefix(request.Model, "gpt-5") {
  239. if request.Model != "gpt-5-chat-latest" {
  240. request.Temperature = nil
  241. }
  242. }
  243. // 转换模型推理力度后缀
  244. effort, originModel := parseReasoningEffortFromModelSuffix(request.Model)
  245. if effort != "" {
  246. request.ReasoningEffort = effort
  247. request.Model = originModel
  248. }
  249. info.ReasoningEffort = request.ReasoningEffort
  250. info.UpstreamModelName = request.Model
  251. // o系列模型developer适配(o1-mini除外)
  252. if !strings.HasPrefix(request.Model, "o1-mini") && !strings.HasPrefix(request.Model, "o1-preview") {
  253. //修改第一个Message的内容,将system改为developer
  254. if len(request.Messages) > 0 && request.Messages[0].Role == "system" {
  255. request.Messages[0].Role = "developer"
  256. }
  257. }
  258. }
  259. return request, nil
  260. }
  261. func (a *Adaptor) ConvertRerankRequest(c *gin.Context, relayMode int, request dto.RerankRequest) (any, error) {
  262. return request, nil
  263. }
  264. func (a *Adaptor) ConvertEmbeddingRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.EmbeddingRequest) (any, error) {
  265. return request, nil
  266. }
  267. func (a *Adaptor) ConvertAudioRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.AudioRequest) (io.Reader, error) {
  268. a.ResponseFormat = request.ResponseFormat
  269. if info.RelayMode == relayconstant.RelayModeAudioSpeech {
  270. jsonData, err := json.Marshal(request)
  271. if err != nil {
  272. return nil, fmt.Errorf("error marshalling object: %w", err)
  273. }
  274. return bytes.NewReader(jsonData), nil
  275. } else {
  276. var requestBody bytes.Buffer
  277. writer := multipart.NewWriter(&requestBody)
  278. writer.WriteField("model", request.Model)
  279. // 获取所有表单字段
  280. formData := c.Request.PostForm
  281. // 遍历表单字段并打印输出
  282. for key, values := range formData {
  283. if key == "model" {
  284. continue
  285. }
  286. for _, value := range values {
  287. writer.WriteField(key, value)
  288. }
  289. }
  290. // 添加文件字段
  291. file, header, err := c.Request.FormFile("file")
  292. if err != nil {
  293. return nil, errors.New("file is required")
  294. }
  295. defer file.Close()
  296. part, err := writer.CreateFormFile("file", header.Filename)
  297. if err != nil {
  298. return nil, errors.New("create form file failed")
  299. }
  300. if _, err := io.Copy(part, file); err != nil {
  301. return nil, errors.New("copy file failed")
  302. }
  303. // 关闭 multipart 编写器以设置分界线
  304. writer.Close()
  305. c.Request.Header.Set("Content-Type", writer.FormDataContentType())
  306. return &requestBody, nil
  307. }
  308. }
  309. func (a *Adaptor) ConvertImageRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.ImageRequest) (any, error) {
  310. switch info.RelayMode {
  311. case relayconstant.RelayModeImagesEdits:
  312. var requestBody bytes.Buffer
  313. writer := multipart.NewWriter(&requestBody)
  314. writer.WriteField("model", request.Model)
  315. // 获取所有表单字段
  316. formData := c.Request.PostForm
  317. // 遍历表单字段并打印输出
  318. for key, values := range formData {
  319. if key == "model" {
  320. continue
  321. }
  322. for _, value := range values {
  323. writer.WriteField(key, value)
  324. }
  325. }
  326. // Parse the multipart form to handle both single image and multiple images
  327. if err := c.Request.ParseMultipartForm(32 << 20); err != nil { // 32MB max memory
  328. return nil, errors.New("failed to parse multipart form")
  329. }
  330. if c.Request.MultipartForm != nil && c.Request.MultipartForm.File != nil {
  331. // Check if "image" field exists in any form, including array notation
  332. var imageFiles []*multipart.FileHeader
  333. var exists bool
  334. // First check for standard "image" field
  335. if imageFiles, exists = c.Request.MultipartForm.File["image"]; !exists || len(imageFiles) == 0 {
  336. // If not found, check for "image[]" field
  337. if imageFiles, exists = c.Request.MultipartForm.File["image[]"]; !exists || len(imageFiles) == 0 {
  338. // If still not found, iterate through all fields to find any that start with "image["
  339. foundArrayImages := false
  340. for fieldName, files := range c.Request.MultipartForm.File {
  341. if strings.HasPrefix(fieldName, "image[") && len(files) > 0 {
  342. foundArrayImages = true
  343. for _, file := range files {
  344. imageFiles = append(imageFiles, file)
  345. }
  346. }
  347. }
  348. // If no image fields found at all
  349. if !foundArrayImages && (len(imageFiles) == 0) {
  350. return nil, errors.New("image is required")
  351. }
  352. }
  353. }
  354. // Process all image files
  355. for i, fileHeader := range imageFiles {
  356. file, err := fileHeader.Open()
  357. if err != nil {
  358. return nil, fmt.Errorf("failed to open image file %d: %w", i, err)
  359. }
  360. defer file.Close()
  361. // If multiple images, use image[] as the field name
  362. fieldName := "image"
  363. if len(imageFiles) > 1 {
  364. fieldName = "image[]"
  365. }
  366. // Determine MIME type based on file extension
  367. mimeType := detectImageMimeType(fileHeader.Filename)
  368. // Create a form file with the appropriate content type
  369. h := make(textproto.MIMEHeader)
  370. h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="%s"; filename="%s"`, fieldName, fileHeader.Filename))
  371. h.Set("Content-Type", mimeType)
  372. part, err := writer.CreatePart(h)
  373. if err != nil {
  374. return nil, fmt.Errorf("create form part failed for image %d: %w", i, err)
  375. }
  376. if _, err := io.Copy(part, file); err != nil {
  377. return nil, fmt.Errorf("copy file failed for image %d: %w", i, err)
  378. }
  379. }
  380. // Handle mask file if present
  381. if maskFiles, exists := c.Request.MultipartForm.File["mask"]; exists && len(maskFiles) > 0 {
  382. maskFile, err := maskFiles[0].Open()
  383. if err != nil {
  384. return nil, errors.New("failed to open mask file")
  385. }
  386. defer maskFile.Close()
  387. // Determine MIME type for mask file
  388. mimeType := detectImageMimeType(maskFiles[0].Filename)
  389. // Create a form file with the appropriate content type
  390. h := make(textproto.MIMEHeader)
  391. h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="mask"; filename="%s"`, maskFiles[0].Filename))
  392. h.Set("Content-Type", mimeType)
  393. maskPart, err := writer.CreatePart(h)
  394. if err != nil {
  395. return nil, errors.New("create form file failed for mask")
  396. }
  397. if _, err := io.Copy(maskPart, maskFile); err != nil {
  398. return nil, errors.New("copy mask file failed")
  399. }
  400. }
  401. } else {
  402. return nil, errors.New("no multipart form data found")
  403. }
  404. // 关闭 multipart 编写器以设置分界线
  405. writer.Close()
  406. c.Request.Header.Set("Content-Type", writer.FormDataContentType())
  407. return bytes.NewReader(requestBody.Bytes()), nil
  408. default:
  409. return request, nil
  410. }
  411. }
  412. // detectImageMimeType determines the MIME type based on the file extension
  413. func detectImageMimeType(filename string) string {
  414. ext := strings.ToLower(filepath.Ext(filename))
  415. switch ext {
  416. case ".jpg", ".jpeg":
  417. return "image/jpeg"
  418. case ".png":
  419. return "image/png"
  420. case ".webp":
  421. return "image/webp"
  422. default:
  423. // Try to detect from extension if possible
  424. if strings.HasPrefix(ext, ".jp") {
  425. return "image/jpeg"
  426. }
  427. // Default to png as a fallback
  428. return "image/png"
  429. }
  430. }
  431. func (a *Adaptor) ConvertOpenAIResponsesRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.OpenAIResponsesRequest) (any, error) {
  432. // 转换模型推理力度后缀
  433. effort, originModel := parseReasoningEffortFromModelSuffix(request.Model)
  434. if effort != "" {
  435. request.Reasoning.Effort = effort
  436. request.Model = originModel
  437. }
  438. return request, nil
  439. }
  440. func (a *Adaptor) DoRequest(c *gin.Context, info *relaycommon.RelayInfo, requestBody io.Reader) (any, error) {
  441. if info.RelayMode == relayconstant.RelayModeAudioTranscription ||
  442. info.RelayMode == relayconstant.RelayModeAudioTranslation ||
  443. info.RelayMode == relayconstant.RelayModeImagesEdits {
  444. return channel.DoFormRequest(a, c, info, requestBody)
  445. } else if info.RelayMode == relayconstant.RelayModeRealtime {
  446. return channel.DoWssRequest(a, c, info, requestBody)
  447. } else {
  448. return channel.DoApiRequest(a, c, info, requestBody)
  449. }
  450. }
  451. func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, info *relaycommon.RelayInfo) (usage any, err *types.NewAPIError) {
  452. switch info.RelayMode {
  453. case relayconstant.RelayModeRealtime:
  454. err, usage = OpenaiRealtimeHandler(c, info)
  455. case relayconstant.RelayModeAudioSpeech:
  456. usage = OpenaiTTSHandler(c, resp, info)
  457. case relayconstant.RelayModeAudioTranslation:
  458. fallthrough
  459. case relayconstant.RelayModeAudioTranscription:
  460. err, usage = OpenaiSTTHandler(c, resp, info, a.ResponseFormat)
  461. case relayconstant.RelayModeImagesGenerations, relayconstant.RelayModeImagesEdits:
  462. usage, err = OpenaiHandlerWithUsage(c, info, resp)
  463. case relayconstant.RelayModeRerank:
  464. usage, err = common_handler.RerankHandler(c, info, resp)
  465. case relayconstant.RelayModeResponses:
  466. if info.IsStream {
  467. usage, err = OaiResponsesStreamHandler(c, info, resp)
  468. } else {
  469. usage, err = OaiResponsesHandler(c, info, resp)
  470. }
  471. default:
  472. if info.IsStream {
  473. usage, err = OaiStreamHandler(c, info, resp)
  474. } else {
  475. usage, err = OpenaiHandler(c, info, resp)
  476. }
  477. }
  478. return
  479. }
  480. func (a *Adaptor) GetModelList() []string {
  481. switch a.ChannelType {
  482. case constant.ChannelType360:
  483. return ai360.ModelList
  484. case constant.ChannelTypeMoonshot:
  485. return moonshot.ModelList
  486. case constant.ChannelTypeLingYiWanWu:
  487. return lingyiwanwu.ModelList
  488. case constant.ChannelTypeMiniMax:
  489. return minimax.ModelList
  490. case constant.ChannelTypeXinference:
  491. return xinference.ModelList
  492. case constant.ChannelTypeOpenRouter:
  493. return openrouter.ModelList
  494. default:
  495. return ModelList
  496. }
  497. }
  498. func (a *Adaptor) GetChannelName() string {
  499. switch a.ChannelType {
  500. case constant.ChannelType360:
  501. return ai360.ChannelName
  502. case constant.ChannelTypeMoonshot:
  503. return moonshot.ChannelName
  504. case constant.ChannelTypeLingYiWanWu:
  505. return lingyiwanwu.ChannelName
  506. case constant.ChannelTypeMiniMax:
  507. return minimax.ChannelName
  508. case constant.ChannelTypeXinference:
  509. return xinference.ChannelName
  510. case constant.ChannelTypeOpenRouter:
  511. return openrouter.ChannelName
  512. default:
  513. return ChannelName
  514. }
  515. }