mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-08-09 02:54:37 +00:00
fix revenue tracking problems
This commit is contained in:
@@ -231,7 +231,10 @@ class LogManager:
|
||||
if "received proxy request" in message:
|
||||
model_stats[model]["requests"] += 1
|
||||
|
||||
if "token adjustment completed" in message:
|
||||
if (
|
||||
"completed for streaming" in message
|
||||
or "completed for non-streaming" in message
|
||||
):
|
||||
model_stats[model]["successful"] += 1
|
||||
cost_data = entry.get("cost_data")
|
||||
if isinstance(cost_data, dict):
|
||||
@@ -321,7 +324,10 @@ class LogManager:
|
||||
if "received proxy request" in message:
|
||||
stats["total_requests"] += 1
|
||||
|
||||
if "token adjustment completed" in message:
|
||||
if (
|
||||
"completed for streaming" in message
|
||||
or "completed for non-streaming" in message
|
||||
):
|
||||
stats["successful_chat_completions"] += 1
|
||||
|
||||
if "upstream request failed" in message or "revert payment" in message:
|
||||
@@ -338,7 +344,10 @@ class LogManager:
|
||||
if isinstance(model, str) and model != "unknown":
|
||||
stats["unique_models"].add(model)
|
||||
|
||||
if "token adjustment completed" in message:
|
||||
if (
|
||||
"completed for streaming" in message
|
||||
or "completed for non-streaming" in message
|
||||
):
|
||||
cost_data = entry.get("cost_data")
|
||||
if isinstance(cost_data, dict):
|
||||
actual_cost = cost_data.get("total_msats", 0)
|
||||
@@ -426,7 +435,10 @@ class LogManager:
|
||||
if level == "ERROR":
|
||||
bucket["errors"] += 1
|
||||
|
||||
if "token adjustment completed" in message:
|
||||
if (
|
||||
"completed for streaming" in message
|
||||
or "completed for non-streaming" in message
|
||||
):
|
||||
cost_data = entry.get("cost_data")
|
||||
if isinstance(cost_data, dict):
|
||||
actual_cost = cost_data.get("total_msats", 0)
|
||||
|
||||
@@ -10,8 +10,8 @@ DO NOT modify or remove these messages without updating the usage tracking logic
|
||||
- Used to count total incoming requests
|
||||
- Includes model information in context
|
||||
|
||||
2. "Token adjustment completed for streaming" (INFO) - routstr/upstream/base.py
|
||||
"Token adjustment completed for non-streaming" (INFO) - routstr/upstream/base.py
|
||||
2. "Payment adjustment completed for streaming" (INFO) - routstr/upstream/base.py
|
||||
"Payment adjustment completed for non-streaming" (INFO) - routstr/upstream/base.py
|
||||
- Used to track successful completions and revenue
|
||||
- The 'cost_data.total_msats' field is extracted for revenue calculation
|
||||
- Must include 'cost_data' in extra dict
|
||||
|
||||
@@ -453,11 +453,12 @@ class BaseUpstreamProvider:
|
||||
)
|
||||
usage_finalized = True
|
||||
logger.info(
|
||||
"Token adjustment completed for streaming",
|
||||
"Payment adjustment completed for streaming",
|
||||
extra={
|
||||
"key_hash": key.hashed_key[:8]
|
||||
+ "...",
|
||||
"cost_data": cost_data,
|
||||
"model": last_model_seen,
|
||||
"balance_after_adjustment": fresh_key.balance,
|
||||
},
|
||||
)
|
||||
@@ -556,7 +557,7 @@ class BaseUpstreamProvider:
|
||||
response_json["cost"] = cost_data
|
||||
|
||||
logger.info(
|
||||
"Token adjustment completed for non-streaming",
|
||||
"Payment adjustment completed for non-streaming",
|
||||
extra={
|
||||
"key_hash": key.hashed_key[:8] + "...",
|
||||
"cost_data": cost_data,
|
||||
|
||||
Reference in New Issue
Block a user