diff --git a/src/api/index.ts b/src/api/index.ts index 2afb00b..751b2a3 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -31,8 +31,12 @@ export class Api implements AI, Runnable { const request = await this._api.createChatCompletion({ model: 'gpt-3.5-turbo', messages: chatHistory, - }); + }).then((response) => response.data.choices[0].message) + .catch((error: Error) => { + this._logger.service.error(error.message); + throw error; + }); - return (request.data.choices[0].message as ChatCompletionResponseMessage); + return (request as ChatCompletionResponseMessage); } } diff --git a/src/bot/commands/chatCommand.ts b/src/bot/commands/chatCommand.ts index 10ed0f8..e82b08d 100644 --- a/src/bot/commands/chatCommand.ts +++ b/src/bot/commands/chatCommand.ts @@ -40,7 +40,7 @@ export const ChatCommand: Command = { embed.forEach((item) => { const message: ChatCompletionRequestMessage = { role: item.footer?.text === 'embed-question' ? 'user' : 'assistant', - content: item.description || 'Please notify an error in process', + content: item.description || 'An error occurred during the process, please try again later.', }; chatHistory.push(message); @@ -52,14 +52,14 @@ export const ChatCommand: Command = { const currentQuestion: ChatCompletionRequestMessage = { role: 'user', - content: question || 'Please notify an error in process', + content: question || 'An error occurred during the process, please try again later.', }; chatHistory.push(currentQuestion); const answer = await ai?.chatCompletion(chatHistory) .then((response) => response.content) - .catch((error) => error); + .catch((error: Error) => error.message); await interaction.followUp({ ephemeral,