diff --git a/src/commands/deleteModel.ts b/src/commands/deleteModel.ts index 4812c6b..d1517db 100644 --- a/src/commands/deleteModel.ts +++ b/src/commands/deleteModel.ts @@ -22,7 +22,6 @@ export const DeleteModel: SlashCommand = { // defer reply to avoid timeout await interaction.deferReply() const modelInput: string = interaction.options.get('model-name')!!.value as string - let modelExists: boolean // fetch channel and message const channel = await client.channels.fetch(interaction.channelId) @@ -38,17 +37,21 @@ export const DeleteModel: SlashCommand = { } // check if model exists - try { - modelExists = await ollama.list() - .then(response => response.models.some((model: ModelResponse) => model.name.startsWith(modelInput))) - } catch (error) { + const modelExists = await ollama.list() + .then(response => response.models.some((model: ModelResponse) => model.name.startsWith(modelInput))) + .catch(error => { + console.error(`[Command: delete-model] Failed to connect with Ollama service. Error: ${error.message}`) + }) + + // Validate for any issue or if service is running + if (!modelExists) { interaction.editReply({ content: `The Ollama service is not running. Please turn on/download the [service](https://ollama.com/).` }) return } - + try { // call ollama to delete model if (modelExists) { diff --git a/src/commands/pullModel.ts b/src/commands/pullModel.ts index 9d5136c..2582d3f 100644 --- a/src/commands/pullModel.ts +++ b/src/commands/pullModel.ts @@ -22,7 +22,6 @@ export const PullModel: SlashCommand = { // defer reply to avoid timeout await interaction.deferReply() const modelInput: string = interaction.options.get('model-to-pull')!!.value as string - let modelExists: boolean // fetch channel and message const channel = await client.channels.fetch(interaction.channelId) @@ -38,10 +37,14 @@ export const PullModel: SlashCommand = { } // check if model was already pulled, if the ollama service isn't running throw error - try { - modelExists = await ollama.list() - .then(response => response.models.some((model: ModelResponse) => model.name.startsWith(modelInput))) - } catch (error) { + const modelExists = await ollama.list() + .then(response => response.models.some((model: ModelResponse) => model.name.startsWith(modelInput))) + .catch(error => { + console.error(`[Command: pull-model] Failed to connect with Ollama service. Error: ${error.message}`) + }) + + // Validate for any issue or if service is running + if (!modelExists) { interaction.editReply({ content: `The Ollama service is not running. Please turn on/download the [service](https://ollama.com/).` }) diff --git a/src/commands/switchModel.ts b/src/commands/switchModel.ts index aabb847..ef74b85 100644 --- a/src/commands/switchModel.ts +++ b/src/commands/switchModel.ts @@ -45,6 +45,9 @@ export const SwitchModel: SlashCommand = { } } }) + .catch(error => { + console.error(`[Command: switch-model] Failed to connect with Ollama service. Error: ${error.message}`) + }) // todo: problem can be here if async messes up if (switchSuccess) { // set model now that it exists