Skip to content

armgit / uzu

Public Imported from GitHub
0

A high-performance inference engine for AI models

1.8 KB
Raw Blame
import SwiftUI

struct ReplyStatsView: View {
    let stats: ReplyStats

    var body: some View {
        Rectangle()
            .fill(MiraiAsset.cardBorder.swiftUIColor)
            .frame(height: 1)
            .padding(.vertical, 4)

        VStack(alignment: .leading, spacing: 4) {
            metricRow(label: "Time to first token:", value: String(format: "%.3f s", stats.timeToFirstToken))
            if stats.tokensPerSecond > 0 {
                metricRow(label: "Tokens per second:", value: String(format: "%.3f t/s", stats.tokensPerSecond))
            }
            metricRow(label: "Memory used:", value: ReplyStatsFormat.memory(stats.memoryUsedBytes))
            if let energy = stats.totalEnergy {
                metricRow(label: "Total energy:", value: ReplyStatsFormat.energy(energy))
            }
            if let inputJoulesPerToken = stats.inputJoulesPerToken {
                metricRow(label: "Input energy / token:", value: ReplyStatsFormat.energyPerToken(inputJoulesPerToken))
            }
            if let outputJoulesPerToken = stats.outputJoulesPerToken {
                metricRow(label: "Output energy / token:", value: ReplyStatsFormat.energyPerToken(outputJoulesPerToken))
            }
            metricRow(label: "Total time:", value: String(format: "%.3f s", stats.totalTime))
        }
    }

    @ViewBuilder
    private func metricRow(label: String, value: String) -> some View {
        HStack(alignment: .firstTextBaseline, spacing: 6) {
            Text(label)
                .font(.monoCaption12)
                .foregroundStyle(MiraiAsset.secondary.swiftUIColor)
            Text(value)
                .font(.monoCaption12Semibold)
                .monospacedDigit()
                .lineLimit(1)
                .minimumScaleFactor(0.7)
        }
    }
}