From 6ccde6f4931cb61bc88561da4d7c12944829df59 Mon Sep 17 00:00:00 2001
From: Shree Krishna Lamichhane
Date: Sun, 21 Apr 2024 18:22:43 +0545
Subject: [PATCH] feat: response time in demo
---
www/src/actions/index.ts | 7 +++++++
www/src/components/Demo.tsx | 3 ++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/www/src/actions/index.ts b/www/src/actions/index.ts
index d4f122d..f79b33d 100644
--- a/www/src/actions/index.ts
+++ b/www/src/actions/index.ts
@@ -10,10 +10,13 @@ type APISuccess = {
isProfanity: boolean
score: number
flaggedFor: string[] | undefined
+ latency: number
}
export const checkProfanity = async ({ message }: { message: string }) => {
try {
+ const startCheckpoint = Date.now();
+
if (message.trim().split(/\s+/).length <= 1) {
return { error: 'Please enter a longer text, at least 2 words.' }
}
@@ -33,6 +36,10 @@ export const checkProfanity = async ({ message }: { message: string }) => {
return { error }
}
+ const endCheckpoint = Date.now()
+
+ json.latency = endCheckpoint - startCheckpoint
+
return json as APISuccess
} catch (err) {
return { error: 'Something went wrong, please try again.' }
diff --git a/www/src/components/Demo.tsx b/www/src/components/Demo.tsx
index 36b5fbb..feecf47 100644
--- a/www/src/components/Demo.tsx
+++ b/www/src/components/Demo.tsx
@@ -72,7 +72,8 @@ const Demo = () => {
- score (higher is worse): {successData.score.toFixed(3)}
+ score (higher is worse): {successData.score.toFixed(3)}
+ {" "} & took : {successData.latency} ms
) : (