Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev -> main #26

Merged
merged 3 commits into from
Aug 15, 2023
Merged
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
4 changes: 2 additions & 2 deletions src/components/GenerateEmailButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -28,7 +28,7 @@ export const GenerateEmailButton = ({
emailType: isThankYou ? 'thank-you' : 'follow-up',
}),
})
.then((res) => res.json() as Promise<AnalyzeEmailOutputOptions>)
.then((res) => res.json() as Promise<GenerateEmailOutputOptions>)
.then((res) => {
const { body, subject } = res;

Expand Down
4 changes: 1 addition & 3 deletions src/components/ReviewDetail.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
48 changes: 24 additions & 24 deletions src/server/google-ai/generate-email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,48 @@ 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(),
customer: z.string(),
emailType: z.string(),
});

type AnalyzeReviewInputOptions = z.infer<typeof analyzeReviewInputSchema>;
type GenerateEmailInputOptions = z.infer<typeof generateEmailInputSchema>;

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.

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 = (
Expand Down Expand Up @@ -92,17 +92,17 @@ 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
);
}

if (outputEmailBody) {
const parsedOutput = analyzeEmailOutputSchema.safeParse({
const parsedOutput = generateEmailOutputSchema.safeParse({
subject: outputEmailSubject,
body: outputEmailBody,
});
Expand Down