diff --git a/template/app/src/demo-ai-app/operations.ts b/template/app/src/demo-ai-app/operations.ts index 023ee05..1b8d4ae 100644 --- a/template/app/src/demo-ai-app/operations.ts +++ b/template/app/src/demo-ai-app/operations.ts @@ -15,11 +15,11 @@ import { SubscriptionStatus } from '../payment/plans'; import { ensureArgsSchemaOrThrowHttpError } from '../server/validation'; const openAi = getOpenAi(); -function getOpenAi(): OpenAI | null { +function getOpenAi(): OpenAI { if (process.env.OPENAI_API_KEY) { return new OpenAI({ apiKey: process.env.OPENAI_API_KEY }); } else { - return null; + throw new Error('OpenAI API key is not set'); } } @@ -38,12 +38,11 @@ export const generateGptResponse: GenerateGptResponse = async (_args, }; //#endregion -async function getDailyPlanFromGpt(tasks: Task[], hours: string): Promise { - if (openAi === null) { - return null; - } - +async function generateScheduleWithGpt(tasks: Task[], hours: string): Promise { const parsedTasks = tasks.map(({ description, time }) => ({ description, time, @@ -294,5 +291,5 @@ async function getDailyPlanFromGpt(tasks: Task[], hours: string): Promise