From f03a355f83898599d030903d584a7c5f34b9ed5d Mon Sep 17 00:00:00 2001 From: UtterDonkey <68461677+UtterDonkey@users.noreply.github.com> Date: Sun, 19 May 2024 13:56:57 +0100 Subject: [PATCH] Update index.ts Expose all flagged words rather than just highest scoring flagged word. --- vector-api/src/index.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/vector-api/src/index.ts b/vector-api/src/index.ts index 9f92e85..4127825 100644 --- a/vector-api/src/index.ts +++ b/vector-api/src/index.ts @@ -105,13 +105,15 @@ app.post('/', async (c) => { ]) if (flaggedFor.size > 0) { - const sorted = Array.from(flaggedFor).sort((a, b) => + const flaggedArr = Array.from(flaggedFor); + const sorted = flaggedArr.sort((a, b) => a.score > b.score ? -1 : 1 - )[0] + ) return c.json({ isProfanity: true, - score: sorted?.score, - flaggedFor: sorted?.text, + score: sorted[0]?.score, + flaggedFor: sorted[0]?.text, + flagged: flaggedArr }) } else { const mostProfaneChunk = vectorRes.sort((a, b) => @@ -121,6 +123,7 @@ app.post('/', async (c) => { return c.json({ isProfanity: false, score: mostProfaneChunk.score, + flagged: [] }) } } catch (err) {