mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
style(api): align struct field tags and fix string concatenation
- Fix JSON field alignment in error response and TrafficBucket struct - Add documentation comment and swagger annotations for Breakdown field - Remove unnecessary string concatenation spacing in SQL select
This commit is contained in:
@@ -568,8 +568,8 @@ func (h *Handler) logStatsByMinute(c *gin.Context, q *gorm.DB, sinceTime, untilT
|
|||||||
duration := untilTime.Sub(*sinceTime)
|
duration := untilTime.Sub(*sinceTime)
|
||||||
if duration > maxMinuteRangeDuration {
|
if duration > maxMinuteRangeDuration {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{
|
c.JSON(http.StatusBadRequest, gin.H{
|
||||||
"error": "time range too large for minute-level aggregation",
|
"error": "time range too large for minute-level aggregation",
|
||||||
"max_hours": 6,
|
"max_hours": 6,
|
||||||
"actual_hours": duration.Hours(),
|
"actual_hours": duration.Hours(),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
@@ -618,9 +618,10 @@ type TrafficMetrics struct {
|
|||||||
|
|
||||||
// TrafficBucket represents one time bucket with model breakdown
|
// TrafficBucket represents one time bucket with model breakdown
|
||||||
type TrafficBucket struct {
|
type TrafficBucket struct {
|
||||||
Time string `json:"time"`
|
Time string `json:"time"`
|
||||||
Timestamp int64 `json:"timestamp"`
|
Timestamp int64 `json:"timestamp"`
|
||||||
Breakdown map[string]TrafficMetrics `json:"breakdown"`
|
// Breakdown contains per-model metrics, keyed by model name (e.g. "gpt-4", "claude-3-opus", "other")
|
||||||
|
Breakdown map[string]TrafficMetrics `json:"breakdown" swaggertype:"object,object" example:"{\"gpt-4\":{\"count\":10,\"tokens_in\":1000,\"tokens_out\":500},\"claude-3-opus\":{\"count\":5,\"tokens_in\":800,\"tokens_out\":400},\"other\":{\"count\":3,\"tokens_in\":200,\"tokens_out\":100}}"`
|
||||||
Total TrafficMetrics `json:"total"`
|
Total TrafficMetrics `json:"total"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -734,7 +735,7 @@ func (h *Handler) GetTrafficChart(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
var rows []bucketModelStats
|
var rows []bucketModelStats
|
||||||
|
|
||||||
if err := q.Select(truncFunc+" as bucket, model_name, COUNT(*) as cnt, COALESCE(SUM(tokens_in),0) as tokens_in, COALESCE(SUM(tokens_out),0) as tokens_out").
|
if err := q.Select(truncFunc + " as bucket, model_name, COUNT(*) as cnt, COALESCE(SUM(tokens_in),0) as tokens_in, COALESCE(SUM(tokens_out),0) as tokens_out").
|
||||||
Group("bucket, model_name").
|
Group("bucket, model_name").
|
||||||
Order("bucket ASC, cnt DESC").
|
Order("bucket ASC, cnt DESC").
|
||||||
Scan(&rows).Error; err != nil {
|
Scan(&rows).Error; err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user