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({
|
const request = await this._api.createChatCompletion({
|
||||||
model: 'gpt-3.5-turbo',
|
model: 'gpt-3.5-turbo',
|
||||||
messages: chatHistory,
|
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) => {
|
embed.forEach((item) => {
|
||||||
const message: ChatCompletionRequestMessage = {
|
const message: ChatCompletionRequestMessage = {
|
||||||
role: item.footer?.text === 'embed-question' ? 'user' : 'assistant',
|
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);
|
chatHistory.push(message);
|
||||||
@ -52,14 +52,14 @@ export const ChatCommand: Command = {
|
|||||||
|
|
||||||
const currentQuestion: ChatCompletionRequestMessage = {
|
const currentQuestion: ChatCompletionRequestMessage = {
|
||||||
role: 'user',
|
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);
|
chatHistory.push(currentQuestion);
|
||||||
|
|
||||||
const answer = await ai?.chatCompletion(chatHistory)
|
const answer = await ai?.chatCompletion(chatHistory)
|
||||||
.then((response) => response.content)
|
.then((response) => response.content)
|
||||||
.catch((error) => error);
|
.catch((error: Error) => error.message);
|
||||||
|
|
||||||
await interaction.followUp({
|
await interaction.followUp({
|
||||||
ephemeral,
|
ephemeral,
|
||||||
|
Loading…
Reference in New Issue
Block a user