Skip to content

Commit

Permalink
Merge pull request #403 from gitroomhq/bug-avoid-stacktrace-no-openai
Browse files Browse the repository at this point in the history
bugfix: Console warning message instead of stacktrace if OPENAI_API_KEY is not set
  • Loading branch information
jamesread authored Oct 28, 2024
2 parents 8fb0729 + 87e7ee2 commit c404028
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion apps/backend/src/api/routes/copilot.controller.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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(),
Expand Down

0 comments on commit c404028

Please sign in to comment.