bugfix: Console warning message instead of stacktrace if OPENAI_API_KEY is not set

This commit is contained in:
jamesread 2024-10-28 23:20:21 +00:00
parent 48634c554b
commit 87e7ee2ce9
1 changed files with 6 additions and 1 deletions

View File

@ -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(),