Skip to content

Commit

Permalink
feat: Improve OpenAI API integration and response handling (#5)
Browse files Browse the repository at this point in the history
Co-authored-by: Hai Chang <haichang@microsoft.com>
  • Loading branch information
haha1903 and Hai Chang committed Apr 14, 2023
1 parent f330d9b commit 3977711
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export class ChatController {
stream,
);

if (response.status > 299 || response.status < 200) {
res.status(response.status);
res.send(response.data);
return;
}

// set response headers
for (const [key, value] of response.headers as AxiosHeaders) {
res.header[key] = value;
Expand Down
6 changes: 5 additions & 1 deletion src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ export class AppService {
config['responseType'] = 'stream';
}
const ret = this.httpService.post(url, body, config);
return await firstValueFrom(ret);
try {
return await firstValueFrom(ret);
} catch (e) {
return e.response;
}
}
private getDeploymentId(mapping: string, model: string): string {
this.logger.debug(`mapping: ${mapping}, model: ${model}`);
Expand Down

0 comments on commit 3977711

Please sign in to comment.