Skip to content

Commit

Permalink
chore: error handling for chat/completions endpoint (#793)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan authored Jun 28, 2024
1 parent 3704025 commit f6e667f
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions cortex-js/src/infrastructure/controllers/chat.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,25 @@ export class ChatController {
const { stream } = createChatDto;

if (stream) {
res.header('Content-Type', 'text/event-stream');
this.chatService
.inference(createChatDto, headers)
.then((stream) => stream.pipe(res));
.then((stream) => {
res.header('Content-Type', 'text/event-stream');
stream.pipe(res);
})
.catch((error) =>
res.status(error.statusCode ?? 400).send(error.message),
);
} else {
res.header('Content-Type', 'application/json');
res.json(await this.chatService.inference(createChatDto, headers));
this.chatService
.inference(createChatDto, headers)
.then((response) => {
res.json(response);
})
.catch((error) =>
res.status(error.statusCode ?? 400).send(error.message),
);
}
}
}

0 comments on commit f6e667f

Please sign in to comment.