mirror of
https://github.com/kevinthedang/discord-ollama.git
synced 2025-12-12 11:56:06 -05:00
Fix: Ollama offline failsafes trigger
This commit is contained in:
@@ -22,6 +22,8 @@ export const DeleteModel: SlashCommand = {
|
|||||||
// defer reply to avoid timeout
|
// defer reply to avoid timeout
|
||||||
await interaction.deferReply()
|
await interaction.deferReply()
|
||||||
const modelInput: string = interaction.options.getString('model-name') as string
|
const modelInput: string = interaction.options.getString('model-name') as string
|
||||||
|
let ollamaOffline: boolean = false
|
||||||
|
|
||||||
// fetch channel and message
|
// fetch channel and message
|
||||||
const channel = await client.channels.fetch(interaction.channelId)
|
const channel = await client.channels.fetch(interaction.channelId)
|
||||||
if (!channel || !UserCommand.includes(channel.type)) return
|
if (!channel || !UserCommand.includes(channel.type)) return
|
||||||
@@ -39,11 +41,12 @@ export const DeleteModel: SlashCommand = {
|
|||||||
const modelExists = await ollama.list()
|
const modelExists = await ollama.list()
|
||||||
.then(response => response.models.some((model: ModelResponse) => model.name.startsWith(modelInput)))
|
.then(response => response.models.some((model: ModelResponse) => model.name.startsWith(modelInput)))
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
ollamaOffline = true
|
||||||
console.error(`[Command: delete-model] Failed to connect with Ollama service. Error: ${error.message}`)
|
console.error(`[Command: delete-model] Failed to connect with Ollama service. Error: ${error.message}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Validate for any issue or if service is running
|
// Validate for any issue or if service is running
|
||||||
if (!modelExists) {
|
if (ollamaOffline) {
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
content: `The Ollama service is not running. Please turn on/download the [service](https://ollama.com/).`
|
content: `The Ollama service is not running. Please turn on/download the [service](https://ollama.com/).`
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export const PullModel: SlashCommand = {
|
|||||||
// defer reply to avoid timeout
|
// defer reply to avoid timeout
|
||||||
await interaction.deferReply()
|
await interaction.deferReply()
|
||||||
const modelInput: string = interaction.options.getString('model-to-pull') as string
|
const modelInput: string = interaction.options.getString('model-to-pull') as string
|
||||||
|
let ollamaOffline: boolean = false
|
||||||
|
|
||||||
// fetch channel and message
|
// fetch channel and message
|
||||||
const channel = await client.channels.fetch(interaction.channelId)
|
const channel = await client.channels.fetch(interaction.channelId)
|
||||||
@@ -40,11 +41,12 @@ export const PullModel: SlashCommand = {
|
|||||||
const modelExists = await ollama.list()
|
const modelExists = await ollama.list()
|
||||||
.then(response => response.models.some((model: ModelResponse) => model.name.startsWith(modelInput)))
|
.then(response => response.models.some((model: ModelResponse) => model.name.startsWith(modelInput)))
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
ollamaOffline = true
|
||||||
console.error(`[Command: pull-model] Failed to connect with Ollama service. Error: ${error.message}`)
|
console.error(`[Command: pull-model] Failed to connect with Ollama service. Error: ${error.message}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Validate for any issue or if service is running
|
// Validate for any issue or if service is running
|
||||||
if (!modelExists) {
|
if (ollamaOffline) {
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
content: `The Ollama service is not running. Please turn on/download the [service](https://ollama.com/).`
|
content: `The Ollama service is not running. Please turn on/download the [service](https://ollama.com/).`
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user