3 Commits

Author SHA1 Message Date
Kevin Dang
1b7c927a3a Update: same catch method for redis 2025-06-17 07:06:41 -07:00
Kevin Dang
9a2744f646 Update: Use built-in catch method for logging 2025-06-17 07:03:23 -07:00
Kevin Dang
c7f9f19c88 Fix: verion typo 2025-06-17 06:50:21 -07:00
5 changed files with 31 additions and 21 deletions

View File

@@ -7,7 +7,7 @@ services:
build: ./ # find docker file in designated path build: ./ # find docker file in designated path
container_name: discord container_name: discord
restart: always # rebuild container always restart: always # rebuild container always
image: kevinthedang/discord-ollama:0.8.5s image: kevinthedang/discord-ollama:0.8.5
environment: environment:
CLIENT_TOKEN: ${CLIENT_TOKEN} CLIENT_TOKEN: ${CLIENT_TOKEN}
OLLAMA_IP: ${OLLAMA_IP} OLLAMA_IP: ${OLLAMA_IP}

View File

@@ -33,15 +33,16 @@ const messageHistory: Queue<UserMessage> = new Queue<UserMessage>
registerEvents(client, Events, messageHistory, ollama, Keys.defaultModel) registerEvents(client, Events, messageHistory, ollama, Keys.defaultModel)
// Try to connect to redis // Try to connect to redis
try { await redis.connect()
await redis.connect() .then(response => {
console.log('[Redis] Successfully Connected') console.log('[Redis] Successfully Connected')
} catch(error) { })
console.error('[Redis] Connection Error. See error below:\n', error) .catch(error => {
console.warn('[Redis] Failed to connect to Redis Database, using local system') console.error('[Redis] Connection Error. See error below:\n', error)
// TODO: create boolean flag that will probably be used in messageCreate.ts if redis database is down console.warn('[Redis] Failed to connect to Redis Database, using local system')
// When implementing this boolean flag, move connection to database BEFORE the registerEvents method // TODO: create boolean flag that will probably be used in messageCreate.ts if redis database is down
} // When implementing this boolean flag, move connection to database BEFORE the registerEvents method
})
// Try to log in the client // Try to log in the client
await client.login(Keys.clientToken) await client.login(Keys.clientToken)

View File

@@ -22,7 +22,6 @@ 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)
@@ -38,17 +37,21 @@ export const DeleteModel: SlashCommand = {
} }
// check if model exists // check if model exists
try { const modelExists = await ollama.list()
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) { 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({ 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/).`
}) })
return return
} }
try { try {
// call ollama to delete model // call ollama to delete model
if (modelExists) { if (modelExists) {

View File

@@ -22,7 +22,6 @@ 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)
@@ -38,10 +37,14 @@ export const PullModel: SlashCommand = {
} }
// check if model was already pulled, if the ollama service isn't running throw error // check if model was already pulled, if the ollama service isn't running throw error
try { const modelExists = await ollama.list()
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) { 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({ 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/).`
}) })

View File

@@ -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 // todo: problem can be here if async messes up
if (switchSuccess) { if (switchSuccess) {
// set model now that it exists // set model now that it exists