Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions www/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.' }
}
Expand All @@ -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.' }
Expand Down
3 changes: 2 additions & 1 deletion www/src/components/Demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ const Demo = () => {
</p>

<p className='text-sm text-zinc-700'>
score (higher is worse): {successData.score.toFixed(3)}
score (higher is worse): <b>{successData.score.toFixed(3)}</b>
{" "} & took : <b>{successData.latency} ms</b>
</p>
</div>
) : (
Expand Down