Merge pull request #403 from gitroomhq/bug-avoid-stacktrace-no-openai

bugfix: Console warning message instead of stacktrace if OPENAI_API_KEY is not set
This commit is contained in:
James Read 2024-10-28 23:43:13 +00:00 committed by GitHub
commit c404028291
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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(),