mirror of
https://github.com/kevinthedang/discord-ollama.git
synced 2025-12-12 19:56:06 -05:00
Fix: Better Messages for Ollama service being offline
This commit is contained in:
@@ -22,6 +22,7 @@ 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.get('model-name')!!.value as string
|
const modelInput: string = interaction.options.get('model-name')!!.value as string
|
||||||
|
let modelExists: boolean
|
||||||
|
|
||||||
// fetch channel and message
|
// fetch channel and message
|
||||||
const channel = await client.channels.fetch(interaction.channelId)
|
const channel = await client.channels.fetch(interaction.channelId)
|
||||||
@@ -37,8 +38,16 @@ export const DeleteModel: SlashCommand = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if model exists
|
// check if model exists
|
||||||
const modelExists: boolean = await ollama.list()
|
try {
|
||||||
.then(response => response.models.some((model: ModelResponse) => model.name.startsWith(modelInput)))
|
modelExists = await ollama.list()
|
||||||
|
.then(response => response.models.some((model: ModelResponse) => model.name.startsWith(modelInput)))
|
||||||
|
} catch (error) {
|
||||||
|
interaction.editReply({
|
||||||
|
content: `The Ollama service is not running. Please turn on/download the [service](https://ollama.com/).`
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// call ollama to delete model
|
// call ollama to delete model
|
||||||
|
|||||||
@@ -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.get('model-to-pull')!!.value as string
|
const modelInput: string = interaction.options.get('model-to-pull')!!.value as string
|
||||||
|
let modelExists: boolean
|
||||||
|
|
||||||
// fetch channel and message
|
// fetch channel and message
|
||||||
const channel = await client.channels.fetch(interaction.channelId)
|
const channel = await client.channels.fetch(interaction.channelId)
|
||||||
@@ -36,9 +37,17 @@ export const PullModel: SlashCommand = {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if model was already pulled
|
// check if model was already pulled, if the ollama service isn't running throw error
|
||||||
const modelExists: boolean = await ollama.list()
|
try {
|
||||||
.then(response => response.models.some((model: ModelResponse) => model.name.startsWith(modelInput)))
|
modelExists = await ollama.list()
|
||||||
|
.then(response => response.models.some((model: ModelResponse) => model.name.startsWith(modelInput)))
|
||||||
|
} catch (error) {
|
||||||
|
interaction.editReply({
|
||||||
|
content: `The Ollama service is not running. Please turn on/download the [service](https://ollama.com/).`
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// call ollama to pull desired model
|
// call ollama to pull desired model
|
||||||
|
|||||||
@@ -56,10 +56,13 @@ export const SwitchModel: SlashCommand = {
|
|||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
content: `Could not find **${modelInput}** in local model library.\n\nPlease contact an server admin for access to this model.`
|
content: `Could not find **${modelInput}** in local model library.\n\nPlease contact an server admin for access to this model.`
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
// could not resolve user model switch
|
// could not resolve user model switch
|
||||||
|
if (error.message.includes("fetch failed") as string)
|
||||||
|
error.message = "The Ollama service is not running. Please turn on/download the [service](https://ollama.com/)."
|
||||||
|
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
content: `Unable to switch user preferred model to **${modelInput}**.\n\n${error}\n\nPossible solution is to request an server admin run \`/pull-model ${modelInput}\` and try again.`
|
content: `Unable to switch user preferred model to **${modelInput}**.\n\n${error.message}`
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user