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

) : (