From 12db36d03bbdb4f9f58c25fd74a8f4d1d263cb11 Mon Sep 17 00:00:00 2001 From: Kevin Dang Date: Thu, 19 Jun 2025 22:39:15 -0700 Subject: [PATCH] Fix: Ollama offline failsafes trigger --- src/commands/deleteModel.ts | 5 ++++- src/commands/pullModel.ts | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/commands/deleteModel.ts b/src/commands/deleteModel.ts index 5cc7c5b..39e349e 100644 --- a/src/commands/deleteModel.ts +++ b/src/commands/deleteModel.ts @@ -22,6 +22,8 @@ export const DeleteModel: SlashCommand = { // defer reply to avoid timeout await interaction.deferReply() const modelInput: string = interaction.options.getString('model-name') as string + let ollamaOffline: boolean = false + // fetch channel and message const channel = await client.channels.fetch(interaction.channelId) if (!channel || !UserCommand.includes(channel.type)) return @@ -39,11 +41,12 @@ export const DeleteModel: SlashCommand = { const modelExists = await ollama.list() .then(response => response.models.some((model: ModelResponse) => model.name.startsWith(modelInput))) .catch(error => { + ollamaOffline = true 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) { + if (ollamaOffline) { interaction.editReply({ content: `The Ollama service is not running. Please turn on/download the [service](https://ollama.com/).` }) diff --git a/src/commands/pullModel.ts b/src/commands/pullModel.ts index 7fb912c..48f8601 100644 --- a/src/commands/pullModel.ts +++ b/src/commands/pullModel.ts @@ -22,6 +22,7 @@ export const PullModel: SlashCommand = { // defer reply to avoid timeout await interaction.deferReply() const modelInput: string = interaction.options.getString('model-to-pull') as string + let ollamaOffline: boolean = false // fetch channel and message const channel = await client.channels.fetch(interaction.channelId) @@ -40,11 +41,12 @@ export const PullModel: SlashCommand = { const modelExists = await ollama.list() .then(response => response.models.some((model: ModelResponse) => model.name.startsWith(modelInput))) .catch(error => { + ollamaOffline = true 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) { + if (ollamaOffline) { interaction.editReply({ content: `The Ollama service is not running. Please turn on/download the [service](https://ollama.com/).` })