compatible_handler.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. package relay
  2. import (
  3. "bytes"
  4. "fmt"
  5. "io"
  6. "net/http"
  7. "strings"
  8. "time"
  9. "github.com/QuantumNous/new-api/common"
  10. "github.com/QuantumNous/new-api/constant"
  11. "github.com/QuantumNous/new-api/dto"
  12. "github.com/QuantumNous/new-api/logger"
  13. "github.com/QuantumNous/new-api/model"
  14. relaycommon "github.com/QuantumNous/new-api/relay/common"
  15. "github.com/QuantumNous/new-api/relay/helper"
  16. "github.com/QuantumNous/new-api/service"
  17. "github.com/QuantumNous/new-api/setting/model_setting"
  18. "github.com/QuantumNous/new-api/setting/operation_setting"
  19. "github.com/QuantumNous/new-api/types"
  20. "github.com/shopspring/decimal"
  21. "github.com/gin-gonic/gin"
  22. )
  23. func TextHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *types.NewAPIError) {
  24. info.InitChannelMeta(c)
  25. textReq, ok := info.Request.(*dto.GeneralOpenAIRequest)
  26. if !ok {
  27. return types.NewErrorWithStatusCode(fmt.Errorf("invalid request type, expected dto.GeneralOpenAIRequest, got %T", info.Request), types.ErrorCodeInvalidRequest, http.StatusBadRequest, types.ErrOptionWithSkipRetry())
  28. }
  29. request, err := common.DeepCopy(textReq)
  30. if err != nil {
  31. return types.NewError(fmt.Errorf("failed to copy request to GeneralOpenAIRequest: %w", err), types.ErrorCodeInvalidRequest, types.ErrOptionWithSkipRetry())
  32. }
  33. if request.WebSearchOptions != nil {
  34. c.Set("chat_completion_web_search_context_size", request.WebSearchOptions.SearchContextSize)
  35. }
  36. err = helper.ModelMappedHelper(c, info, request)
  37. if err != nil {
  38. return types.NewError(err, types.ErrorCodeChannelModelMappedError, types.ErrOptionWithSkipRetry())
  39. }
  40. includeUsage := true
  41. // 判断用户是否需要返回使用情况
  42. if request.StreamOptions != nil {
  43. includeUsage = request.StreamOptions.IncludeUsage
  44. }
  45. // 如果不支持StreamOptions,将StreamOptions设置为nil
  46. if !info.SupportStreamOptions || !request.Stream {
  47. request.StreamOptions = nil
  48. } else {
  49. // 如果支持StreamOptions,且请求中没有设置StreamOptions,根据配置文件设置StreamOptions
  50. if constant.ForceStreamOption {
  51. request.StreamOptions = &dto.StreamOptions{
  52. IncludeUsage: true,
  53. }
  54. }
  55. }
  56. info.ShouldIncludeUsage = includeUsage
  57. adaptor := GetAdaptor(info.ApiType)
  58. if adaptor == nil {
  59. return types.NewError(fmt.Errorf("invalid api type: %d", info.ApiType), types.ErrorCodeInvalidApiType, types.ErrOptionWithSkipRetry())
  60. }
  61. adaptor.Init(info)
  62. var requestBody io.Reader
  63. if model_setting.GetGlobalSettings().PassThroughRequestEnabled || info.ChannelSetting.PassThroughBodyEnabled {
  64. body, err := common.GetRequestBody(c)
  65. if err != nil {
  66. return types.NewErrorWithStatusCode(err, types.ErrorCodeReadRequestBodyFailed, http.StatusBadRequest, types.ErrOptionWithSkipRetry())
  67. }
  68. if common.DebugEnabled {
  69. println("requestBody: ", string(body))
  70. }
  71. requestBody = bytes.NewBuffer(body)
  72. } else {
  73. convertedRequest, err := adaptor.ConvertOpenAIRequest(c, info, request)
  74. if err != nil {
  75. return types.NewError(err, types.ErrorCodeConvertRequestFailed, types.ErrOptionWithSkipRetry())
  76. }
  77. if info.ChannelSetting.SystemPrompt != "" {
  78. // 如果有系统提示,则将其添加到请求中
  79. request, ok := convertedRequest.(*dto.GeneralOpenAIRequest)
  80. if ok {
  81. containSystemPrompt := false
  82. for _, message := range request.Messages {
  83. if message.Role == request.GetSystemRoleName() {
  84. containSystemPrompt = true
  85. break
  86. }
  87. }
  88. if !containSystemPrompt {
  89. // 如果没有系统提示,则添加系统提示
  90. systemMessage := dto.Message{
  91. Role: request.GetSystemRoleName(),
  92. Content: info.ChannelSetting.SystemPrompt,
  93. }
  94. request.Messages = append([]dto.Message{systemMessage}, request.Messages...)
  95. } else if info.ChannelSetting.SystemPromptOverride {
  96. common.SetContextKey(c, constant.ContextKeySystemPromptOverride, true)
  97. // 如果有系统提示,且允许覆盖,则拼接到前面
  98. for i, message := range request.Messages {
  99. if message.Role == request.GetSystemRoleName() {
  100. if message.IsStringContent() {
  101. request.Messages[i].SetStringContent(info.ChannelSetting.SystemPrompt + "\n" + message.StringContent())
  102. } else {
  103. contents := message.ParseContent()
  104. contents = append([]dto.MediaContent{
  105. {
  106. Type: dto.ContentTypeText,
  107. Text: info.ChannelSetting.SystemPrompt,
  108. },
  109. }, contents...)
  110. request.Messages[i].Content = contents
  111. }
  112. break
  113. }
  114. }
  115. }
  116. }
  117. }
  118. jsonData, err := common.Marshal(convertedRequest)
  119. if err != nil {
  120. return types.NewError(err, types.ErrorCodeJsonMarshalFailed, types.ErrOptionWithSkipRetry())
  121. }
  122. // remove disabled fields for OpenAI API
  123. jsonData, err = relaycommon.RemoveDisabledFields(jsonData, info.ChannelOtherSettings)
  124. if err != nil {
  125. return types.NewError(err, types.ErrorCodeConvertRequestFailed, types.ErrOptionWithSkipRetry())
  126. }
  127. // apply param override
  128. if len(info.ParamOverride) > 0 {
  129. jsonData, err = relaycommon.ApplyParamOverride(jsonData, info.ParamOverride, relaycommon.BuildParamOverrideContext(info))
  130. if err != nil {
  131. return types.NewError(err, types.ErrorCodeChannelParamOverrideInvalid, types.ErrOptionWithSkipRetry())
  132. }
  133. }
  134. logger.LogDebug(c, fmt.Sprintf("text request body: %s", string(jsonData)))
  135. requestBody = bytes.NewBuffer(jsonData)
  136. }
  137. var httpResp *http.Response
  138. resp, err := adaptor.DoRequest(c, info, requestBody)
  139. if err != nil {
  140. return types.NewOpenAIError(err, types.ErrorCodeDoRequestFailed, http.StatusInternalServerError)
  141. }
  142. statusCodeMappingStr := c.GetString("status_code_mapping")
  143. if resp != nil {
  144. httpResp = resp.(*http.Response)
  145. info.IsStream = info.IsStream || strings.HasPrefix(httpResp.Header.Get("Content-Type"), "text/event-stream")
  146. if httpResp.StatusCode != http.StatusOK {
  147. newApiErr := service.RelayErrorHandler(c.Request.Context(), httpResp, false)
  148. // reset status code 重置状态码
  149. service.ResetStatusCode(newApiErr, statusCodeMappingStr)
  150. return newApiErr
  151. }
  152. }
  153. usage, newApiErr := adaptor.DoResponse(c, httpResp, info)
  154. if newApiErr != nil {
  155. // reset status code 重置状态码
  156. service.ResetStatusCode(newApiErr, statusCodeMappingStr)
  157. return newApiErr
  158. }
  159. if strings.HasPrefix(info.OriginModelName, "gpt-4o-audio") {
  160. service.PostAudioConsumeQuota(c, info, usage.(*dto.Usage), "")
  161. } else {
  162. postConsumeQuota(c, info, usage.(*dto.Usage), "")
  163. }
  164. return nil
  165. }
  166. func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage *dto.Usage, extraContent string) {
  167. if usage == nil {
  168. usage = &dto.Usage{
  169. PromptTokens: relayInfo.GetEstimatePromptTokens(),
  170. CompletionTokens: 0,
  171. TotalTokens: relayInfo.GetEstimatePromptTokens(),
  172. }
  173. extraContent += "(可能是请求出错)"
  174. }
  175. useTimeSeconds := time.Now().Unix() - relayInfo.StartTime.Unix()
  176. promptTokens := usage.PromptTokens
  177. cacheTokens := usage.PromptTokensDetails.CachedTokens
  178. imageTokens := usage.PromptTokensDetails.ImageTokens
  179. audioTokens := usage.PromptTokensDetails.AudioTokens
  180. completionTokens := usage.CompletionTokens
  181. cachedCreationTokens := usage.PromptTokensDetails.CachedCreationTokens
  182. modelName := relayInfo.OriginModelName
  183. tokenName := ctx.GetString("token_name")
  184. completionRatio := relayInfo.PriceData.CompletionRatio
  185. cacheRatio := relayInfo.PriceData.CacheRatio
  186. imageRatio := relayInfo.PriceData.ImageRatio
  187. modelRatio := relayInfo.PriceData.ModelRatio
  188. groupRatio := relayInfo.PriceData.GroupRatioInfo.GroupRatio
  189. modelPrice := relayInfo.PriceData.ModelPrice
  190. cachedCreationRatio := relayInfo.PriceData.CacheCreationRatio
  191. // Convert values to decimal for precise calculation
  192. dPromptTokens := decimal.NewFromInt(int64(promptTokens))
  193. dCacheTokens := decimal.NewFromInt(int64(cacheTokens))
  194. dImageTokens := decimal.NewFromInt(int64(imageTokens))
  195. dAudioTokens := decimal.NewFromInt(int64(audioTokens))
  196. dCompletionTokens := decimal.NewFromInt(int64(completionTokens))
  197. dCachedCreationTokens := decimal.NewFromInt(int64(cachedCreationTokens))
  198. dCompletionRatio := decimal.NewFromFloat(completionRatio)
  199. dCacheRatio := decimal.NewFromFloat(cacheRatio)
  200. dImageRatio := decimal.NewFromFloat(imageRatio)
  201. dModelRatio := decimal.NewFromFloat(modelRatio)
  202. dGroupRatio := decimal.NewFromFloat(groupRatio)
  203. dModelPrice := decimal.NewFromFloat(modelPrice)
  204. dCachedCreationRatio := decimal.NewFromFloat(cachedCreationRatio)
  205. dQuotaPerUnit := decimal.NewFromFloat(common.QuotaPerUnit)
  206. ratio := dModelRatio.Mul(dGroupRatio)
  207. // openai web search 工具计费
  208. var dWebSearchQuota decimal.Decimal
  209. var webSearchPrice float64
  210. // response api 格式工具计费
  211. if relayInfo.ResponsesUsageInfo != nil {
  212. if webSearchTool, exists := relayInfo.ResponsesUsageInfo.BuiltInTools[dto.BuildInToolWebSearchPreview]; exists && webSearchTool.CallCount > 0 {
  213. // 计算 web search 调用的配额 (配额 = 价格 * 调用次数 / 1000 * 分组倍率)
  214. webSearchPrice = operation_setting.GetWebSearchPricePerThousand(modelName, webSearchTool.SearchContextSize)
  215. dWebSearchQuota = decimal.NewFromFloat(webSearchPrice).
  216. Mul(decimal.NewFromInt(int64(webSearchTool.CallCount))).
  217. Div(decimal.NewFromInt(1000)).Mul(dGroupRatio).Mul(dQuotaPerUnit)
  218. extraContent += fmt.Sprintf("Web Search 调用 %d 次,上下文大小 %s,调用花费 %s",
  219. webSearchTool.CallCount, webSearchTool.SearchContextSize, dWebSearchQuota.String())
  220. }
  221. } else if strings.HasSuffix(modelName, "search-preview") {
  222. // search-preview 模型不支持 response api
  223. searchContextSize := ctx.GetString("chat_completion_web_search_context_size")
  224. if searchContextSize == "" {
  225. searchContextSize = "medium"
  226. }
  227. webSearchPrice = operation_setting.GetWebSearchPricePerThousand(modelName, searchContextSize)
  228. dWebSearchQuota = decimal.NewFromFloat(webSearchPrice).
  229. Div(decimal.NewFromInt(1000)).Mul(dGroupRatio).Mul(dQuotaPerUnit)
  230. extraContent += fmt.Sprintf("Web Search 调用 1 次,上下文大小 %s,调用花费 %s",
  231. searchContextSize, dWebSearchQuota.String())
  232. }
  233. // claude web search tool 计费
  234. var dClaudeWebSearchQuota decimal.Decimal
  235. var claudeWebSearchPrice float64
  236. claudeWebSearchCallCount := ctx.GetInt("claude_web_search_requests")
  237. if claudeWebSearchCallCount > 0 {
  238. claudeWebSearchPrice = operation_setting.GetClaudeWebSearchPricePerThousand()
  239. dClaudeWebSearchQuota = decimal.NewFromFloat(claudeWebSearchPrice).
  240. Div(decimal.NewFromInt(1000)).Mul(dGroupRatio).Mul(dQuotaPerUnit).Mul(decimal.NewFromInt(int64(claudeWebSearchCallCount)))
  241. extraContent += fmt.Sprintf("Claude Web Search 调用 %d 次,调用花费 %s",
  242. claudeWebSearchCallCount, dClaudeWebSearchQuota.String())
  243. }
  244. // file search tool 计费
  245. var dFileSearchQuota decimal.Decimal
  246. var fileSearchPrice float64
  247. if relayInfo.ResponsesUsageInfo != nil {
  248. if fileSearchTool, exists := relayInfo.ResponsesUsageInfo.BuiltInTools[dto.BuildInToolFileSearch]; exists && fileSearchTool.CallCount > 0 {
  249. fileSearchPrice = operation_setting.GetFileSearchPricePerThousand()
  250. dFileSearchQuota = decimal.NewFromFloat(fileSearchPrice).
  251. Mul(decimal.NewFromInt(int64(fileSearchTool.CallCount))).
  252. Div(decimal.NewFromInt(1000)).Mul(dGroupRatio).Mul(dQuotaPerUnit)
  253. extraContent += fmt.Sprintf("File Search 调用 %d 次,调用花费 %s",
  254. fileSearchTool.CallCount, dFileSearchQuota.String())
  255. }
  256. }
  257. var dImageGenerationCallQuota decimal.Decimal
  258. var imageGenerationCallPrice float64
  259. if ctx.GetBool("image_generation_call") {
  260. imageGenerationCallPrice = operation_setting.GetGPTImage1PriceOnceCall(ctx.GetString("image_generation_call_quality"), ctx.GetString("image_generation_call_size"))
  261. dImageGenerationCallQuota = decimal.NewFromFloat(imageGenerationCallPrice).Mul(dGroupRatio).Mul(dQuotaPerUnit)
  262. extraContent += fmt.Sprintf("Image Generation Call 花费 %s", dImageGenerationCallQuota.String())
  263. }
  264. var quotaCalculateDecimal decimal.Decimal
  265. var audioInputQuota decimal.Decimal
  266. var audioInputPrice float64
  267. if !relayInfo.PriceData.UsePrice {
  268. baseTokens := dPromptTokens
  269. // 减去 cached tokens
  270. var cachedTokensWithRatio decimal.Decimal
  271. if !dCacheTokens.IsZero() {
  272. baseTokens = baseTokens.Sub(dCacheTokens)
  273. cachedTokensWithRatio = dCacheTokens.Mul(dCacheRatio)
  274. }
  275. var dCachedCreationTokensWithRatio decimal.Decimal
  276. if !dCachedCreationTokens.IsZero() {
  277. baseTokens = baseTokens.Sub(dCachedCreationTokens)
  278. dCachedCreationTokensWithRatio = dCachedCreationTokens.Mul(dCachedCreationRatio)
  279. }
  280. // 减去 image tokens
  281. var imageTokensWithRatio decimal.Decimal
  282. if !dImageTokens.IsZero() {
  283. baseTokens = baseTokens.Sub(dImageTokens)
  284. imageTokensWithRatio = dImageTokens.Mul(dImageRatio)
  285. }
  286. // 减去 Gemini audio tokens
  287. if !dAudioTokens.IsZero() {
  288. audioInputPrice = operation_setting.GetGeminiInputAudioPricePerMillionTokens(modelName)
  289. if audioInputPrice > 0 {
  290. // 重新计算 base tokens
  291. baseTokens = baseTokens.Sub(dAudioTokens)
  292. audioInputQuota = decimal.NewFromFloat(audioInputPrice).Div(decimal.NewFromInt(1000000)).Mul(dAudioTokens).Mul(dGroupRatio).Mul(dQuotaPerUnit)
  293. extraContent += fmt.Sprintf("Audio Input 花费 %s", audioInputQuota.String())
  294. }
  295. }
  296. promptQuota := baseTokens.Add(cachedTokensWithRatio).
  297. Add(imageTokensWithRatio).
  298. Add(dCachedCreationTokensWithRatio)
  299. completionQuota := dCompletionTokens.Mul(dCompletionRatio)
  300. quotaCalculateDecimal = promptQuota.Add(completionQuota).Mul(ratio)
  301. if !ratio.IsZero() && quotaCalculateDecimal.LessThanOrEqual(decimal.Zero) {
  302. quotaCalculateDecimal = decimal.NewFromInt(1)
  303. }
  304. } else {
  305. quotaCalculateDecimal = dModelPrice.Mul(dQuotaPerUnit).Mul(dGroupRatio)
  306. }
  307. // 添加 responses tools call 调用的配额
  308. quotaCalculateDecimal = quotaCalculateDecimal.Add(dWebSearchQuota)
  309. quotaCalculateDecimal = quotaCalculateDecimal.Add(dFileSearchQuota)
  310. // 添加 audio input 独立计费
  311. quotaCalculateDecimal = quotaCalculateDecimal.Add(audioInputQuota)
  312. // 添加 image generation call 计费
  313. quotaCalculateDecimal = quotaCalculateDecimal.Add(dImageGenerationCallQuota)
  314. quota := int(quotaCalculateDecimal.Round(0).IntPart())
  315. totalTokens := promptTokens + completionTokens
  316. var logContent string
  317. // record all the consume log even if quota is 0
  318. if totalTokens == 0 {
  319. // in this case, must be some error happened
  320. // we cannot just return, because we may have to return the pre-consumed quota
  321. quota = 0
  322. logContent += fmt.Sprintf("(可能是上游超时)")
  323. logger.LogError(ctx, fmt.Sprintf("total tokens is 0, cannot consume quota, userId %d, channelId %d, "+
  324. "tokenId %d, model %s, pre-consumed quota %d", relayInfo.UserId, relayInfo.ChannelId, relayInfo.TokenId, modelName, relayInfo.FinalPreConsumedQuota))
  325. } else {
  326. if !ratio.IsZero() && quota == 0 {
  327. quota = 1
  328. }
  329. model.UpdateUserUsedQuotaAndRequestCount(relayInfo.UserId, quota)
  330. model.UpdateChannelUsedQuota(relayInfo.ChannelId, quota)
  331. }
  332. quotaDelta := quota - relayInfo.FinalPreConsumedQuota
  333. //logger.LogInfo(ctx, fmt.Sprintf("request quota delta: %s", logger.FormatQuota(quotaDelta)))
  334. if quotaDelta > 0 {
  335. logger.LogInfo(ctx, fmt.Sprintf("预扣费后补扣费:%s(实际消耗:%s,预扣费:%s)",
  336. logger.FormatQuota(quotaDelta),
  337. logger.FormatQuota(quota),
  338. logger.FormatQuota(relayInfo.FinalPreConsumedQuota),
  339. ))
  340. } else if quotaDelta < 0 {
  341. logger.LogInfo(ctx, fmt.Sprintf("预扣费后返还扣费:%s(实际消耗:%s,预扣费:%s)",
  342. logger.FormatQuota(-quotaDelta),
  343. logger.FormatQuota(quota),
  344. logger.FormatQuota(relayInfo.FinalPreConsumedQuota),
  345. ))
  346. }
  347. if quotaDelta != 0 {
  348. err := service.PostConsumeQuota(relayInfo, quotaDelta, relayInfo.FinalPreConsumedQuota, true)
  349. if err != nil {
  350. logger.LogError(ctx, "error consuming token remain quota: "+err.Error())
  351. }
  352. }
  353. logModel := modelName
  354. if strings.HasPrefix(logModel, "gpt-4-gizmo") {
  355. logModel = "gpt-4-gizmo-*"
  356. logContent += fmt.Sprintf(",模型 %s", modelName)
  357. }
  358. if strings.HasPrefix(logModel, "gpt-4o-gizmo") {
  359. logModel = "gpt-4o-gizmo-*"
  360. logContent += fmt.Sprintf(",模型 %s", modelName)
  361. }
  362. if extraContent != "" {
  363. logContent += ", " + extraContent
  364. }
  365. other := service.GenerateTextOtherInfo(ctx, relayInfo, modelRatio, groupRatio, completionRatio, cacheTokens, cacheRatio, modelPrice, relayInfo.PriceData.GroupRatioInfo.GroupSpecialRatio)
  366. if imageTokens != 0 {
  367. other["image"] = true
  368. other["image_ratio"] = imageRatio
  369. other["image_output"] = imageTokens
  370. }
  371. if cachedCreationTokens != 0 {
  372. other["cache_creation_tokens"] = cachedCreationTokens
  373. other["cache_creation_ratio"] = cachedCreationRatio
  374. }
  375. if !dWebSearchQuota.IsZero() {
  376. if relayInfo.ResponsesUsageInfo != nil {
  377. if webSearchTool, exists := relayInfo.ResponsesUsageInfo.BuiltInTools[dto.BuildInToolWebSearchPreview]; exists {
  378. other["web_search"] = true
  379. other["web_search_call_count"] = webSearchTool.CallCount
  380. other["web_search_price"] = webSearchPrice
  381. }
  382. } else if strings.HasSuffix(modelName, "search-preview") {
  383. other["web_search"] = true
  384. other["web_search_call_count"] = 1
  385. other["web_search_price"] = webSearchPrice
  386. }
  387. } else if !dClaudeWebSearchQuota.IsZero() {
  388. other["web_search"] = true
  389. other["web_search_call_count"] = claudeWebSearchCallCount
  390. other["web_search_price"] = claudeWebSearchPrice
  391. }
  392. if !dFileSearchQuota.IsZero() && relayInfo.ResponsesUsageInfo != nil {
  393. if fileSearchTool, exists := relayInfo.ResponsesUsageInfo.BuiltInTools[dto.BuildInToolFileSearch]; exists {
  394. other["file_search"] = true
  395. other["file_search_call_count"] = fileSearchTool.CallCount
  396. other["file_search_price"] = fileSearchPrice
  397. }
  398. }
  399. if !audioInputQuota.IsZero() {
  400. other["audio_input_seperate_price"] = true
  401. other["audio_input_token_count"] = audioTokens
  402. other["audio_input_price"] = audioInputPrice
  403. }
  404. if !dImageGenerationCallQuota.IsZero() {
  405. other["image_generation_call"] = true
  406. other["image_generation_call_price"] = imageGenerationCallPrice
  407. }
  408. model.RecordConsumeLog(ctx, relayInfo.UserId, model.RecordConsumeLogParams{
  409. ChannelId: relayInfo.ChannelId,
  410. PromptTokens: promptTokens,
  411. CompletionTokens: completionTokens,
  412. ModelName: logModel,
  413. TokenName: tokenName,
  414. Quota: quota,
  415. Content: logContent,
  416. TokenId: relayInfo.TokenId,
  417. UseTimeSeconds: int(useTimeSeconds),
  418. IsStream: relayInfo.IsStream,
  419. Group: relayInfo.UsingGroup,
  420. Other: other,
  421. })
  422. }