nsarrazin HF Staff commited on
Commit
a504517
·
1 Parent(s): 9f5281f

feat: aggregate model votes in metrics

Browse files
src/lib/server/metrics.ts CHANGED
@@ -14,6 +14,8 @@ interface Metrics {
14
  timePerOutputToken: Summary<Model["id"]>;
15
  timeToFirstToken: Summary<Model["id"]>;
16
  latency: Summary<Model["id"]>;
 
 
17
  };
18
 
19
  webSearch: {
@@ -106,6 +108,18 @@ export class MetricsServer {
106
  maxAgeSeconds: 5 * 60,
107
  ageBuckets: 5,
108
  }),
 
 
 
 
 
 
 
 
 
 
 
 
109
  },
110
  webSearch: {
111
  requestCount: new Counter({
 
14
  timePerOutputToken: Summary<Model["id"]>;
15
  timeToFirstToken: Summary<Model["id"]>;
16
  latency: Summary<Model["id"]>;
17
+ votesPositive: Counter<Model["id"]>;
18
+ votesNegative: Counter<Model["id"]>;
19
  };
20
 
21
  webSearch: {
 
108
  maxAgeSeconds: 5 * 60,
109
  ageBuckets: 5,
110
  }),
111
+ votesPositive: new Counter({
112
+ name: "model_votes_positive",
113
+ help: "Total number of positive votes on messages generated by the model",
114
+ labelNames: ["model"],
115
+ registers: [register],
116
+ }),
117
+ votesNegative: new Counter({
118
+ name: "model_votes_negative",
119
+ help: "Total number of negative votes on messages generated by the model",
120
+ labelNames: ["model"],
121
+ registers: [register],
122
+ }),
123
  },
124
  webSearch: {
125
  requestCount: new Counter({
src/routes/conversation/[id]/message/[messageId]/vote/+server.ts CHANGED
@@ -1,5 +1,6 @@
1
  import { authCondition } from "$lib/server/auth";
2
  import { collections } from "$lib/server/database";
 
3
  import { error } from "@sveltejs/kit";
4
  import { ObjectId } from "mongodb";
5
  import { z } from "zod";
@@ -13,6 +14,25 @@ export async function POST({ params, request, locals }) {
13
  const conversationId = new ObjectId(params.id);
14
  const messageId = params.messageId;
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  const document = await collections.conversations.updateOne(
17
  {
18
  _id: conversationId,
 
1
  import { authCondition } from "$lib/server/auth";
2
  import { collections } from "$lib/server/database";
3
+ import { MetricsServer } from "$lib/server/metrics.js";
4
  import { error } from "@sveltejs/kit";
5
  import { ObjectId } from "mongodb";
6
  import { z } from "zod";
 
14
  const conversationId = new ObjectId(params.id);
15
  const messageId = params.messageId;
16
 
17
+ // aggregate votes per model in order to detect model performance degradation
18
+ const model = await collections.conversations
19
+ .findOne(
20
+ {
21
+ _id: conversationId,
22
+ ...authCondition(locals),
23
+ },
24
+ { projection: { model: 1 } }
25
+ )
26
+ .then((c) => c?.model);
27
+
28
+ if (model) {
29
+ if (score === 1) {
30
+ MetricsServer.getMetrics().model.votesPositive.inc({ model });
31
+ } else {
32
+ MetricsServer.getMetrics().model.votesNegative.inc({ model });
33
+ }
34
+ }
35
+
36
  const document = await collections.conversations.updateOne(
37
  {
38
  _id: conversationId,