(c *gin.Context)
| 213 | } |
| 214 | |
| 215 | func GenRelayInfo(c *gin.Context) *RelayInfo { |
| 216 | channelType := common.GetContextKeyInt(c, constant.ContextKeyChannelType) |
| 217 | channelId := common.GetContextKeyInt(c, constant.ContextKeyChannelId) |
| 218 | paramOverride := common.GetContextKeyStringMap(c, constant.ContextKeyChannelParamOverride) |
| 219 | |
| 220 | tokenId := common.GetContextKeyInt(c, constant.ContextKeyTokenId) |
| 221 | tokenKey := common.GetContextKeyString(c, constant.ContextKeyTokenKey) |
| 222 | userId := common.GetContextKeyInt(c, constant.ContextKeyUserId) |
| 223 | tokenUnlimited := common.GetContextKeyBool(c, constant.ContextKeyTokenUnlimited) |
| 224 | startTime := common.GetContextKeyTime(c, constant.ContextKeyRequestStartTime) |
| 225 | // firstResponseTime = time.Now() - 1 second |
| 226 | |
| 227 | apiType, _ := common.ChannelType2APIType(channelType) |
| 228 | |
| 229 | info := &RelayInfo{ |
| 230 | UserQuota: common.GetContextKeyInt(c, constant.ContextKeyUserQuota), |
| 231 | UserEmail: common.GetContextKeyString(c, constant.ContextKeyUserEmail), |
| 232 | isFirstResponse: true, |
| 233 | RelayMode: relayconstant.Path2RelayMode(c.Request.URL.Path), |
| 234 | BaseUrl: common.GetContextKeyString(c, constant.ContextKeyChannelBaseUrl), |
| 235 | RequestURLPath: c.Request.URL.String(), |
| 236 | ChannelType: channelType, |
| 237 | ChannelId: channelId, |
| 238 | TokenId: tokenId, |
| 239 | TokenKey: tokenKey, |
| 240 | UserId: userId, |
| 241 | UsingGroup: common.GetContextKeyString(c, constant.ContextKeyUsingGroup), |
| 242 | UserGroup: common.GetContextKeyString(c, constant.ContextKeyUserGroup), |
| 243 | TokenUnlimited: tokenUnlimited, |
| 244 | StartTime: startTime, |
| 245 | FirstResponseTime: startTime.Add(-time.Second), |
| 246 | OriginModelName: common.GetContextKeyString(c, constant.ContextKeyOriginalModel), |
| 247 | UpstreamModelName: common.GetContextKeyString(c, constant.ContextKeyOriginalModel), |
| 248 | //RecodeModelName: c.GetString("original_model"), |
| 249 | IsModelMapped: false, |
| 250 | ApiType: apiType, |
| 251 | ApiVersion: c.GetString("api_version"), |
| 252 | ApiKey: common.GetContextKeyString(c, constant.ContextKeyChannelKey), |
| 253 | Organization: c.GetString("channel_organization"), |
| 254 | |
| 255 | ChannelCreateTime: c.GetInt64("channel_create_time"), |
| 256 | ParamOverride: paramOverride, |
| 257 | RelayFormat: RelayFormatOpenAI, |
| 258 | ThinkingContentInfo: ThinkingContentInfo{ |
| 259 | IsFirstThinkingContent: true, |
| 260 | SendLastThinkingContent: false, |
| 261 | }, |
| 262 | } |
| 263 | if strings.HasPrefix(c.Request.URL.Path, "/pg") { |
| 264 | info.IsPlayground = true |
| 265 | info.RequestURLPath = strings.TrimPrefix(info.RequestURLPath, "/pg") |
| 266 | info.RequestURLPath = "/v1" + info.RequestURLPath |
| 267 | } |
| 268 | if info.BaseUrl == "" { |
| 269 | info.BaseUrl = constant.ChannelBaseURLs[channelType] |
| 270 | } |
| 271 | if info.ChannelType == constant.ChannelTypeAzure { |
| 272 | info.ApiVersion = GetAPIVersion(c) |
no test coverage detected