Skip to content

Commit

Permalink
Merge pull request #233 from yocxo/srizvi/issue231-patch
Browse files Browse the repository at this point in the history
fix: summarizer formatting #231
  • Loading branch information
srizvi committed Apr 14, 2024
2 parents be3f62c + f5a9c43 commit bd08a63
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 35 deletions.
20 changes: 5 additions & 15 deletions apps/web/src/content/warnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ interface Review {
serviceOutcomes: string[];
}

export function calculateNPSAndCounts(reviews: Review[]): {
export function calculateNPSAndCounts(): {
nps: number;
promoters: number;
passives: number;
Expand All @@ -83,20 +83,10 @@ export function calculateNPSAndCounts(reviews: Review[]): {
relativeNPS: number;
benchmarkNPS: number;
} {
const totalRespondents = reviews.length;
let promoters = 0;
let passives = 0;
let detractors = 0;

reviews.forEach((review) => {
if (review.nps >= 9) {
promoters++;
} else if (review.nps > 6 && review.nps < 9) {
passives++;
} else if (review.nps <= 6) {
detractors++;
}
});
const promoters = 58;
const passives = 0;
const detractors = 1;
const totalRespondents = promoters + passives + detractors;

const nps = ((promoters - detractors) / totalRespondents) * 100;
const benchmarkNPS = 76; // According to retently https://rizv.io/1iKd8T
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/lib/ai/ai-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const perplexity = new OpenAI({
});

export async function summarizeReviews() {
const npsData = calculateNPSAndCounts(mockWarningsForAiSummary);
const npsData = calculateNPSAndCounts();
const reviewsContent = mockWarningsForAiSummary
.map((review, i) => {
const reviewOutcomes = review.serviceOutcomes
Expand Down
26 changes: 11 additions & 15 deletions apps/web/src/ui/ai/ai-review-summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import {
CardTitle,
} from '@yocxo/ui/card';

import {
calculateNPSAndCounts,
mockWarningsForAiSummary,
} from '#/content/warnings';
import { calculateNPSAndCounts } from '#/content/warnings';
import perplexityAiImage from '#/images/llms/perplexity.jpg';

interface NPSData {
Expand All @@ -30,7 +27,7 @@ interface NPSData {
benchmarkNPS: number;
}

const getNPSData = (reviews: typeof mockWarningsForAiSummary): NPSData => {
const getNPSData = (): NPSData => {
const {
nps,
promoters,
Expand All @@ -39,7 +36,7 @@ const getNPSData = (reviews: typeof mockWarningsForAiSummary): NPSData => {
totalRespondents,
relativeNPS,
benchmarkNPS,
} = calculateNPSAndCounts(reviews);
} = calculateNPSAndCounts();
return {
nps,
promoters,
Expand All @@ -51,11 +48,7 @@ const getNPSData = (reviews: typeof mockWarningsForAiSummary): NPSData => {
};
};

interface Props {
summary: string;
}

export default function AIReviewSummary({ summary }: Props) {
export default function AIReviewSummary() {
const {
nps,
promoters,
Expand All @@ -64,7 +57,7 @@ export default function AIReviewSummary({ summary }: Props) {
totalRespondents,
relativeNPS,
benchmarkNPS,
} = getNPSData(mockWarningsForAiSummary);
} = getNPSData();

const npsEvaluation = nps > 76 ? 'pretty, pretty, pretty good' : 'horrible';

Expand All @@ -73,7 +66,7 @@ export default function AIReviewSummary({ summary }: Props) {
<CardHeader className="mt-4 items-center gap-4 space-y-0 p-0">
<div className="grid gap-1 text-center">
<CardTitle className="flex flex-col font-mono text-2xl font-semibold tracking-tighter">
Mock Net Promoter Score
Mock NPS Analysis
</CardTitle>
<CardDescription className="flex flex-col items-center gap-2">
<span className="flex justify-center text-xs">
Expand All @@ -87,8 +80,11 @@ export default function AIReviewSummary({ summary }: Props) {
</CardHeader>
<CardContent className="grid gap-4 p-0">
<div className="mt-2 text-pretty text-sm leading-loose text-secondary-foreground">
{summary} Yo! CXO&apos;s NPS of {nps} is {relativeNPS} points above
the relative{' '}
Clients of Yo! CXO say that their growth strategies are alright. They
only found a large untapped market segment and doubled the customer
base. But now the clients have to upgrade their CRM and customer
service platforms to accommodate the surge in users too. Yo!
CXO&apos;s NPS of {nps} is {relativeNPS} points above the relative{' '}
<a
className="hover:text-primary hover:underline hover:decoration-2 hover:underline-offset-4"
href="https://www.retently.com/blog/good-net-promoter-score/"
Expand Down
6 changes: 2 additions & 4 deletions apps/web/src/ui/warnings/warnings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
fetchWarnings,
fetchWarningsSectionIntro,
} from '#/basehub/warnings-queries';
import { summarizeReviews } from '#/lib/ai/ai-summary';
import AIReviewSummary from '#/ui/ai/ai-review-summary';
import { FadeIn, FadeInStagger } from '#/ui/fade-in';
import { SectionIntro } from '#/ui/section-intro';
Expand All @@ -23,10 +22,9 @@ function classNames(...classes: string[]) {
}

export async function Warnings() {
const [sectionIntro, warningsData, summary] = await Promise.all([
const [sectionIntro, warningsData] = await Promise.all([
fetchWarningsSectionIntro(),
fetchWarnings(),
summarizeReviews(),
]);

if (!sectionIntro || !warningsData) {
Expand Down Expand Up @@ -77,7 +75,7 @@ export async function Warnings() {
<RichText>{sectionIntro.description?.json.content}</RichText>
</SectionIntro>
<FadeIn className="mx-auto mt-16 grid max-w-2xl grid-cols-1 grid-rows-1 gap-8 sm:mt-20 sm:grid-cols-2 xl:mx-0 xl:max-w-none xl:grid-flow-col xl:grid-cols-4">
<AIReviewSummary summary={summary} />
<AIReviewSummary />
{warningColumns.map((columnWarnings, columnIndex) => (
<div
key={`${columnIndex}-${Math.random()}`}
Expand Down

0 comments on commit bd08a63

Please sign in to comment.