Skip to content

Commit 4120471

Browse files
committed
Sync AI stats and create a new merging function to facilitate
1 parent 10befa2 commit 4120471

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

aikido_zen/background_process/commands/sync_data.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ def process_sync_data(connection_manager, data, conn, queue=None):
4646
# Sync stats
4747
connection_manager.statistics.import_from_record(data.get("stats", {}))
4848

49+
# Sync ai stats
50+
connection_manager.ai_stats.import_list(data.get("ai_stats", []))
51+
4952
if connection_manager.conf.last_updated_at > 0:
5053
# Only report data if the config has been fetched.
5154
return {

aikido_zen/storage/ai_statistics.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ def on_ai_call(self, provider, model, input_tokens, output_tokens):
3737
def get_stats(self):
3838
return [copy.deepcopy(stats) for stats in self.calls.values()]
3939

40+
def import_list(self, ai_stats_list):
41+
for new_entry in ai_stats_list:
42+
existing_entry = self.ensure_provider_stats(
43+
new_entry["provider"], new_entry["model"]
44+
)
45+
existing_entry["calls"] += new_entry["calls"]
46+
existing_entry["tokens"]["input"] = new_entry["tokens"]["input"]
47+
existing_entry["tokens"]["output"] = new_entry["tokens"]["output"]
48+
existing_entry["tokens"]["total"] = new_entry["tokens"]["total"]
49+
4050
def clear(self):
4151
self.calls.clear()
4252

0 commit comments

Comments
 (0)