UNPKG

@agentscope/studio

Version:

AgentScope Studio is a powerful local monitoring and visualization tool designed to provide real-time insights into your system's performance and behavior.

128 lines (127 loc) 5.79 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ModelInvocationView = void 0; const typeorm_1 = require("typeorm"); const Trace_1 = require("./Trace"); let ModelInvocationView = class ModelInvocationView extends typeorm_1.BaseEntity { }; exports.ModelInvocationView = ModelInvocationView; __decorate([ (0, typeorm_1.ViewColumn)(), __metadata("design:type", Number) ], ModelInvocationView.prototype, "totalModelInvocations", void 0); __decorate([ (0, typeorm_1.ViewColumn)(), __metadata("design:type", Number) ], ModelInvocationView.prototype, "totalTokens", void 0); __decorate([ (0, typeorm_1.ViewColumn)(), __metadata("design:type", Number) ], ModelInvocationView.prototype, "chatModelInvocations", void 0); __decorate([ (0, typeorm_1.ViewColumn)(), __metadata("design:type", Number) ], ModelInvocationView.prototype, "tokensWeekAgo", void 0); __decorate([ (0, typeorm_1.ViewColumn)(), __metadata("design:type", Number) ], ModelInvocationView.prototype, "tokensMonthAgo", void 0); __decorate([ (0, typeorm_1.ViewColumn)(), __metadata("design:type", Number) ], ModelInvocationView.prototype, "tokensYearAgo", void 0); __decorate([ (0, typeorm_1.ViewColumn)(), __metadata("design:type", Number) ], ModelInvocationView.prototype, "modelInvocationsWeekAgo", void 0); __decorate([ (0, typeorm_1.ViewColumn)(), __metadata("design:type", Number) ], ModelInvocationView.prototype, "modelInvocationsMonthAgo", void 0); __decorate([ (0, typeorm_1.ViewColumn)(), __metadata("design:type", Number) ], ModelInvocationView.prototype, "modelInvocationsYearAgo", void 0); exports.ModelInvocationView = ModelInvocationView = __decorate([ (0, typeorm_1.ViewEntity)({ expression: (dataSource) => dataSource .createQueryBuilder() .from(Trace_1.SpanTable, 'span') .innerJoin('run_table', 'run', 'run.id = span.conversationId') .select(`COUNT(CASE WHEN (span.operationName = 'chat' OR span.operationName = 'chat_model') THEN 1 END)`, 'totalModelInvocations') .addSelect(`COALESCE(SUM(CASE WHEN span.totalTokens IS NOT NULL AND (span.operationName = 'chat' OR span.operationName = 'chat_model') THEN CAST(span.totalTokens AS INTEGER) ELSE 0 END), 0)`, 'totalTokens') .addSelect(`COUNT(CASE WHEN span.totalTokens IS NOT NULL AND (span.operationName = 'chat' OR span.operationName = 'chat_model') THEN 1 END)`, 'chatModelInvocations') // A month ago .addSelect(`COALESCE(SUM(CASE WHEN span.totalTokens IS NOT NULL AND (span.operationName = 'chat' OR span.operationName = 'chat_model') AND span.startTimeUnixNano > (strftime('%s', 'now', '-1 month') * 1000000000) THEN CAST(span.totalTokens AS INTEGER) ELSE 0 END), 0)`, 'tokensMonthAgo') // A week ago .addSelect(`COALESCE(SUM(CASE WHEN span.totalTokens IS NOT NULL AND (span.operationName = 'chat' OR span.operationName = 'chat_model') AND span.startTimeUnixNano > (strftime('%s', 'now', '-7 days') * 1000000000) THEN CAST(span.totalTokens AS INTEGER) ELSE 0 END), 0)`, 'tokensWeekAgo') // A year ago .addSelect(`COALESCE(SUM(CASE WHEN span.totalTokens IS NOT NULL AND (span.operationName = 'chat' OR span.operationName = 'chat_model') AND span.startTimeUnixNano > (strftime('%s', 'now', '-1 year') * 1000000000) THEN CAST(span.totalTokens AS INTEGER) ELSE 0 END), 0)`, 'tokensYearAgo') // A month ago .addSelect(`COUNT(CASE WHEN (span.operationName = 'chat' OR span.operationName = 'chat_model') AND span.startTimeUnixNano > (strftime('%s', 'now', '-1 month') * 1000000000) THEN 1 END)`, 'modelInvocationsMonthAgo') // A week ago .addSelect(`COUNT(CASE WHEN (span.operationName = 'chat' OR span.operationName = 'chat_model') AND span.startTimeUnixNano > (strftime('%s', 'now', '-7 days') * 1000000000) THEN 1 END)`, 'modelInvocationsWeekAgo') // A year ago .addSelect(`COUNT(CASE WHEN (span.operationName = 'chat' OR span.operationName = 'chat_model') AND span.startTimeUnixNano > (strftime('%s', 'now', '-1 year') * 1000000000) THEN 1 END)`, 'modelInvocationsYearAgo'), }) ], ModelInvocationView);