From 98a89984529dd310d62ed51d9cbb17b5fa14240b Mon Sep 17 00:00:00 2001 From: Brad Adams Date: Mon, 14 Aug 2023 20:59:11 +0200 Subject: [PATCH 1/3] chore: variable renaming --- src/components/GenerateEmailButton.tsx | 4 ++-- src/server/google-ai/generate-email.ts | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/GenerateEmailButton.tsx b/src/components/GenerateEmailButton.tsx index 1db6cab..75584da 100644 --- a/src/components/GenerateEmailButton.tsx +++ b/src/components/GenerateEmailButton.tsx @@ -3,7 +3,7 @@ import { EnvelopeIcon, HeartIcon } from '@heroicons/react/24/solid'; import { useState } from 'react'; import { type Review } from 'types'; -import { type AnalyzeEmailOutputOptions } from '~/server/google-ai/generate-email'; +import { type GenerateEmailOutputOptions } from '~/server/google-ai/generate-email'; interface GenerateEmailButtonProps { variant: 'thank-you' | 'follow-up'; @@ -28,7 +28,7 @@ export const GenerateEmailButton = ({ emailType: isThankYou ? 'thank-you' : 'follow-up', }), }) - .then((res) => res.json() as Promise) + .then((res) => res.json() as Promise) .then((res) => { const { body, subject } = res; diff --git a/src/server/google-ai/generate-email.ts b/src/server/google-ai/generate-email.ts index acc87b0..32c9361 100644 --- a/src/server/google-ai/generate-email.ts +++ b/src/server/google-ai/generate-email.ts @@ -6,7 +6,7 @@ import { env } from '~/env.mjs'; const MODEL_NAME = 'models/text-bison-001'; const API_KEY = env.GOOGLE_API_KEY; -const analyzeReviewInputSchema = z.object({ +const generateEmailInputSchema = z.object({ rating: z.number(), title: z.string(), text: z.string(), @@ -14,19 +14,19 @@ const analyzeReviewInputSchema = z.object({ emailType: z.string(), }); -type AnalyzeReviewInputOptions = z.infer; +type GenerateEmailInputOptions = z.infer; -const analyzeEmailOutputSchema = z.object({ +const generateEmailOutputSchema = z.object({ subject: z.string(), body: z.string(), }); -export type AnalyzeEmailOutputOptions = z.infer< - typeof analyzeEmailOutputSchema +export type GenerateEmailOutputOptions = z.infer< + typeof generateEmailOutputSchema >; export async function generateAISuggestedEmail( - options: AnalyzeReviewInputOptions + options: GenerateEmailInputOptions ) { const promptEmailBody = `Role: E-commerce customer care expert analyzing product reviews and outputting a result as a string. @@ -102,7 +102,7 @@ export async function generateAISuggestedEmail( } if (outputEmailBody) { - const parsedOutput = analyzeEmailOutputSchema.safeParse({ + const parsedOutput = generateEmailOutputSchema.safeParse({ subject: outputEmailSubject, body: outputEmailBody, }); From c6f147af074fde1aeb65a7581b1cb9e8ef128969 Mon Sep 17 00:00:00 2001 From: Brad Adams Date: Mon, 14 Aug 2023 21:16:53 +0200 Subject: [PATCH 2/3] misc: adjust email prompt --- src/server/google-ai/generate-email.ts | 34 +++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/server/google-ai/generate-email.ts b/src/server/google-ai/generate-email.ts index 32c9361..f423719 100644 --- a/src/server/google-ai/generate-email.ts +++ b/src/server/google-ai/generate-email.ts @@ -29,25 +29,25 @@ export async function generateAISuggestedEmail( options: GenerateEmailInputOptions ) { const promptEmailBody = `Role: E-commerce customer care expert analyzing product reviews and outputting a result as a string. - - Task: Based on the input provided, generate a suggested email body response to the customer. - Input Format: +Task: Based on the input provided, generate a suggested email body response to the customer. Only provide information based on data you are provided with, don't invent or assume any facts, and don't include any placeholders. The email signature should be "Sincerely, the ildecimo team". - - "Title": The review title. - - "Body": The review body text. - - "Rating": The review rating, out of 5. - - "Customer": The customer's name. - - "Email Type": The type of email to send to the customer. This can be one of the following: "Thank you email" or "Follow-up email". +Input Format: - Output Format: string +- "Review title": The review title. +- "Review description": The review body text. +- "Review Rating": The review rating, out of 5. +- "Customer Name": The customer's name. +- "Email Type": The type of email to send to the customer. This can be one of the following: "Thank you email" or "Follow-up email". - Input Data: - - "Review Title:" ${options.title}, - - "Review Description": ${options.text}, - - "Review Rating": ${options.rating}, - - "Customer Name": ${options.customer}, - - "Email Type": ${options.emailType} +Output Format: string + +Input Data: +- "Review Title:" ${options.title}, +- "Review Description": ${options.text}, +- "Review Rating": ${options.rating}, +- "Customer Name": ${options.customer}, +- "Email Type": ${options.emailType} `; const promptEmailSubject = ( @@ -92,11 +92,11 @@ export async function generateAISuggestedEmail( if (env.NODE_ENV === 'development') { console.log( - '*** [Vertex Review Analysis Output Subject] ::', + '*** [Vertex Generate Email Output Subject] ::', outputEmailSubject ); console.log( - '*** [Vertex Review Analysis Output Body] ::', + '*** [Vertex Generate Email Output Body] ::', outputEmailBody ); } From 5e46bf43b3cddaccda583a6de4861b7b2ab836b8 Mon Sep 17 00:00:00 2001 From: Brad Adams Date: Mon, 14 Aug 2023 21:19:19 +0200 Subject: [PATCH 3/3] fix: remove unused imports --- src/components/ReviewDetail.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/ReviewDetail.tsx b/src/components/ReviewDetail.tsx index ff4c6ab..c037079 100644 --- a/src/components/ReviewDetail.tsx +++ b/src/components/ReviewDetail.tsx @@ -1,8 +1,6 @@ 'use client'; -import { Box, Button } from '@bigcommerce/big-design'; -import { CloseIcon } from '@bigcommerce/big-design-icons'; -import { CheckIcon } from '@heroicons/react/24/solid'; +import { Box } from '@bigcommerce/big-design'; import clsx from 'clsx'; import { useState } from 'react'; import GaugeComponent from 'react-gauge-component';