Commit 3851628a authored by erio's avatar erio
Browse files

fix: resolve golangci-lint issues

- Fix errcheck: defer rows.Close() with nolint
- Fix errcheck: type assertion with ok check in channel cache
- Fix staticcheck ST1005: lowercase error string
- Fix staticcheck SA5011: nil check cost before use in openai gateway
- Fix gofmt: format chatcompletions_to_responses.go
parent d72ac926
...@@ -230,7 +230,7 @@ func validatePricingBillingMode(pricing []service.ChannelModelPricing) error { ...@@ -230,7 +230,7 @@ func validatePricingBillingMode(pricing []service.ChannelModelPricing) error {
for _, p := range pricing { for _, p := range pricing {
if p.BillingMode == service.BillingModePerRequest || p.BillingMode == service.BillingModeImage { if p.BillingMode == service.BillingModePerRequest || p.BillingMode == service.BillingModeImage {
if p.PerRequestPrice == nil && len(p.Intervals) == 0 { if p.PerRequestPrice == nil && len(p.Intervals) == 0 {
return errors.New("Per-request price or intervals required for per_request/image billing mode") return errors.New("per-request price or intervals required for per_request/image billing mode")
} }
} }
} }
......
...@@ -27,13 +27,14 @@ func ChatCompletionsToResponses(req *ChatCompletionsRequest) (*ResponsesRequest, ...@@ -27,13 +27,14 @@ func ChatCompletionsToResponses(req *ChatCompletionsRequest) (*ResponsesRequest,
} }
out := &ResponsesRequest{ out := &ResponsesRequest{
Model: req.Model, Model: req.Model,
Input: inputJSON, Instructions: req.Instructions,
Temperature: req.Temperature, Input: inputJSON,
TopP: req.TopP, Temperature: req.Temperature,
Stream: true, // upstream always streams TopP: req.TopP,
Include: []string{"reasoning.encrypted_content"}, Stream: true, // upstream always streams
ServiceTier: req.ServiceTier, Include: []string{"reasoning.encrypted_content"},
ServiceTier: req.ServiceTier,
} }
storeFalse := false storeFalse := false
......
...@@ -443,7 +443,7 @@ func (r *channelRepository) GetGroupPlatforms(ctx context.Context, groupIDs []in ...@@ -443,7 +443,7 @@ func (r *channelRepository) GetGroupPlatforms(ctx context.Context, groupIDs []in
if err != nil { if err != nil {
return nil, fmt.Errorf("get group platforms: %w", err) return nil, fmt.Errorf("get group platforms: %w", err)
} }
defer rows.Close() defer rows.Close() //nolint:errcheck
result := make(map[int64]string, len(groupIDs)) result := make(map[int64]string, len(groupIDs))
for rows.Next() { for rows.Next() {
......
...@@ -176,7 +176,11 @@ func (s *ChannelService) loadCache(ctx context.Context) (*channelCache, error) { ...@@ -176,7 +176,11 @@ func (s *ChannelService) loadCache(ctx context.Context) (*channelCache, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return result.(*channelCache), nil cache, ok := result.(*channelCache)
if !ok {
return nil, fmt.Errorf("unexpected cache type")
}
return cache, nil
} }
// buildCache 从数据库构建渠道缓存。 // buildCache 从数据库构建渠道缓存。
......
...@@ -4261,22 +4261,24 @@ func (s *OpenAIGatewayService) RecordUsage(ctx context.Context, input *OpenAIRec ...@@ -4261,22 +4261,24 @@ func (s *OpenAIGatewayService) RecordUsage(ctx context.Context, input *OpenAIRec
CacheCreationTokens: result.Usage.CacheCreationInputTokens, CacheCreationTokens: result.Usage.CacheCreationInputTokens,
CacheReadTokens: result.Usage.CacheReadInputTokens, CacheReadTokens: result.Usage.CacheReadInputTokens,
ImageOutputTokens: result.Usage.ImageOutputTokens, ImageOutputTokens: result.Usage.ImageOutputTokens,
InputCost: cost.InputCost,
OutputCost: cost.OutputCost,
ImageOutputCost: cost.ImageOutputCost,
CacheCreationCost: cost.CacheCreationCost,
CacheReadCost: cost.CacheReadCost,
TotalCost: cost.TotalCost,
ActualCost: cost.ActualCost,
RateMultiplier: multiplier,
AccountRateMultiplier: &accountRateMultiplier,
BillingType: billingType,
Stream: result.Stream,
OpenAIWSMode: result.OpenAIWSMode,
DurationMs: &durationMs,
FirstTokenMs: result.FirstTokenMs,
CreatedAt: time.Now(),
} }
if cost != nil {
usageLog.InputCost = cost.InputCost
usageLog.OutputCost = cost.OutputCost
usageLog.ImageOutputCost = cost.ImageOutputCost
usageLog.CacheCreationCost = cost.CacheCreationCost
usageLog.CacheReadCost = cost.CacheReadCost
usageLog.TotalCost = cost.TotalCost
usageLog.ActualCost = cost.ActualCost
}
usageLog.RateMultiplier = multiplier
usageLog.AccountRateMultiplier = &accountRateMultiplier
usageLog.BillingType = billingType
usageLog.Stream = result.Stream
usageLog.OpenAIWSMode = result.OpenAIWSMode
usageLog.DurationMs = &durationMs
usageLog.FirstTokenMs = result.FirstTokenMs
usageLog.CreatedAt = time.Now()
// 设置渠道信息 // 设置渠道信息
usageLog.ChannelID = optionalInt64Ptr(input.ChannelID) usageLog.ChannelID = optionalInt64Ptr(input.ChannelID)
usageLog.ModelMappingChain = optionalTrimmedStringPtr(input.ModelMappingChain) usageLog.ModelMappingChain = optionalTrimmedStringPtr(input.ModelMappingChain)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment