Improved support for error handling
This commit is contained in:
parent
4884b7492f
commit
03aa9d0c82
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user