LifeVta commited on
Commit
2ed8df9
·
verified ·
1 Parent(s): 24822d8

Update app/dataplane/account/feedback.py

Browse files
Files changed (1) hide show
  1. app/dataplane/account/feedback.py +25 -5
app/dataplane/account/feedback.py CHANGED
@@ -171,15 +171,34 @@ def _adjust_health(table: AccountRuntimeTable, idx: int, factor: float) -> None:
171
  _MIN_HEALTH, float(table.health_by_idx[idx]) * factor
172
  )
173
 
174
- # 在已有的异步反馈函数结束位置(例如 success 或 fail 状态判定后)追加:
175
- def trigger_audit_log(token: str, quota_type: str, status: str, ctx: dict):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  log_rec = AuditLogRecord(
177
  token=token,
178
  device_ip=ctx.get("client_ip", "0.0.0.0"),
179
  user_agent=ctx.get("user_agent", "Unknown"),
180
  conversation_id=ctx.get("conversation_id"),
181
- quota_type=quota_type, # 通过传入的 mode 映射,比如 'fast' 或 'console'
182
- status=status # "SUCCESS" 或 "FAIL"
183
  )
184
  global_auditor.record(log_rec)
185
 
@@ -198,4 +217,5 @@ __all__ = [
198
  "decrement_inflight",
199
  "update_last_use",
200
  "update_last_fail",
201
- ]
 
 
171
  _MIN_HEALTH, float(table.health_by_idx[idx]) * factor
172
  )
173
 
174
+
175
+ # ---------------------------------------------------------------------------
176
+ # Audit Extension Logic (Memory-safe mode)
177
+ # ---------------------------------------------------------------------------
178
+
179
+ _MODE_ID_TO_NAME = {
180
+ 0: "auto",
181
+ 1: "fast",
182
+ 2: "expert",
183
+ 3: "heavy",
184
+ 4: "grok_4_3",
185
+ 5: "console"
186
+ }
187
+
188
+
189
+ def trigger_audit_log(token: str, quota_type: str | int, status: str, ctx: dict) -> None:
190
+ """Record a single API call metrics into the in-memory rolling queue."""
191
+ # If a raw integer mode_id is passed, map it automatically to its string name
192
+ if isinstance(quota_type, int):
193
+ quota_type = _MODE_ID_TO_NAME.get(quota_type, "unknown")
194
+
195
  log_rec = AuditLogRecord(
196
  token=token,
197
  device_ip=ctx.get("client_ip", "0.0.0.0"),
198
  user_agent=ctx.get("user_agent", "Unknown"),
199
  conversation_id=ctx.get("conversation_id"),
200
+ quota_type=str(quota_type),
201
+ status=status # "SUCCESS" or "FAIL"
202
  )
203
  global_auditor.record(log_rec)
204
 
 
217
  "decrement_inflight",
218
  "update_last_use",
219
  "update_last_fail",
220
+ "trigger_audit_log", # Exported properly for the upper layers
221
+ ]