From 87e7ee2ce9c8b77a4dbec2ba7ad8fe278c00c7b0 Mon Sep 17 00:00:00 2001 From: jamesread Date: Mon, 28 Oct 2024 23:20:21 +0000 Subject: [PATCH] bugfix: Console warning message instead of stacktrace if OPENAI_API_KEY is not set --- apps/backend/src/api/routes/copilot.controller.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/backend/src/api/routes/copilot.controller.ts b/apps/backend/src/api/routes/copilot.controller.ts index e66a13fd..65928b20 100644 --- a/apps/backend/src/api/routes/copilot.controller.ts +++ b/apps/backend/src/api/routes/copilot.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Post, Req, Res } from '@nestjs/common'; +import { Logger, Controller, Get, Post, Req, Res } from '@nestjs/common'; import { CopilotRuntime, OpenAIAdapter, @@ -13,6 +13,11 @@ export class CopilotController { constructor(private _subscriptionService: SubscriptionService) {} @Post('/chat') chat(@Req() req: Request, @Res() res: Response) { + if (process.env.OPENAI_API_KEY === undefined || process.env.OPENAI_API_KEY === '') { + Logger.warn('OpenAI API key not set, chat functionality will not work'); + return + } + const copilotRuntimeHandler = copilotRuntimeNestEndpoint({ endpoint: '/copilot/chat', runtime: new CopilotRuntime(),