mirror of
https://github.com/kevinthedang/discord-ollama.git
synced 2025-12-12 11:56:06 -05:00
Delete Model Command (#150)
* Add: Delete Model Command * Update: version increment * Update: new command to tests
This commit is contained in:
@@ -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.7.5
|
image: kevinthedang/discord-ollama:0.8.0
|
||||||
environment:
|
environment:
|
||||||
CLIENT_TOKEN: ${CLIENT_TOKEN}
|
CLIENT_TOKEN: ${CLIENT_TOKEN}
|
||||||
OLLAMA_IP: ${OLLAMA_IP}
|
OLLAMA_IP: ${OLLAMA_IP}
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "discord-ollama",
|
"name": "discord-ollama",
|
||||||
"version": "0.7.5",
|
"version": "0.8.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "discord-ollama",
|
"name": "discord-ollama",
|
||||||
"version": "0.7.5",
|
"version": "0.8.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord.js": "^14.16.3",
|
"discord.js": "^14.16.3",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "discord-ollama",
|
"name": "discord-ollama",
|
||||||
"version": "0.7.5",
|
"version": "0.8.0",
|
||||||
"description": "Ollama Integration into discord",
|
"description": "Ollama Integration into discord",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"exports": "./build/index.js",
|
"exports": "./build/index.js",
|
||||||
|
|||||||
60
src/commands/deleteModel.ts
Normal file
60
src/commands/deleteModel.ts
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import { ApplicationCommandOptionType, Client, CommandInteraction } from 'discord.js'
|
||||||
|
import { UserCommand, SlashCommand } from '../utils/index.js'
|
||||||
|
import { ollama } from '../client.js'
|
||||||
|
import { ModelResponse } from 'ollama'
|
||||||
|
|
||||||
|
export const DeleteModel: SlashCommand = {
|
||||||
|
name: 'delete-model',
|
||||||
|
description: 'deletes a model from the local list of models. Administrator Only.',
|
||||||
|
|
||||||
|
// set available user options to pass to the command
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'model-name',
|
||||||
|
description: 'the name of the model to delete',
|
||||||
|
type: ApplicationCommandOptionType.String,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
// Delete Model locally stored
|
||||||
|
run: async (client: Client, interaction: CommandInteraction) => {
|
||||||
|
// defer reply to avoid timeout
|
||||||
|
await interaction.deferReply()
|
||||||
|
const modelInput: string = interaction.options.get('model-name')!!.value as string
|
||||||
|
|
||||||
|
// fetch channel and message
|
||||||
|
const channel = await client.channels.fetch(interaction.channelId)
|
||||||
|
if (!channel || !UserCommand.includes(channel.type)) return
|
||||||
|
|
||||||
|
// Admin Command
|
||||||
|
if (!interaction.memberPermissions?.has('Administrator')) {
|
||||||
|
interaction.reply({
|
||||||
|
content: `${interaction.commandName} is an admin command.\n\nPlease contact a server admin to pull the model you want.`,
|
||||||
|
ephemeral: true
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if model exists
|
||||||
|
const modelExists: boolean = await ollama.list()
|
||||||
|
.then(response => response.models.some((model: ModelResponse) => model.name.startsWith(modelInput)))
|
||||||
|
|
||||||
|
try {
|
||||||
|
// call ollama to delete model
|
||||||
|
if (modelExists) {
|
||||||
|
await ollama.delete({ model: modelInput })
|
||||||
|
interaction.editReply({
|
||||||
|
content: `**${modelInput}** was removed from the the library.`
|
||||||
|
})
|
||||||
|
} else
|
||||||
|
throw new Error()
|
||||||
|
} catch (error) {
|
||||||
|
// could not delete the model
|
||||||
|
interaction.reply({
|
||||||
|
content: `Could not delete the **${modelInput}** model. It probably doesn't exist or you spelled it incorrectly.\n\nPlease try again if this is a mistake.`,
|
||||||
|
ephemeral: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import { PrivateThreadCreate } from './threadPrivateCreate.js'
|
|||||||
import { ClearUserChannelHistory } from './cleanUserChannelHistory.js'
|
import { ClearUserChannelHistory } from './cleanUserChannelHistory.js'
|
||||||
import { PullModel } from './pullModel.js'
|
import { PullModel } from './pullModel.js'
|
||||||
import { SwitchModel } from './switchModel.js'
|
import { SwitchModel } from './switchModel.js'
|
||||||
|
import { DeleteModel } from './deleteModel.js'
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
ThreadCreate,
|
ThreadCreate,
|
||||||
@@ -18,5 +19,6 @@ export default [
|
|||||||
Capacity,
|
Capacity,
|
||||||
ClearUserChannelHistory,
|
ClearUserChannelHistory,
|
||||||
PullModel,
|
PullModel,
|
||||||
SwitchModel
|
SwitchModel,
|
||||||
|
DeleteModel
|
||||||
] as SlashCommand[]
|
] as SlashCommand[]
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
import { ApplicationCommandOptionType, Client, CommandInteraction } from "discord.js";
|
import { ApplicationCommandOptionType, Client, CommandInteraction } from "discord.js"
|
||||||
import { SlashCommand } from "../utils/commands.js";
|
import { ollama } from "../client.js"
|
||||||
import { ollama } from "../client.js";
|
import { ModelResponse } from "ollama"
|
||||||
import { ModelResponse } from "ollama";
|
import { UserCommand, SlashCommand } from "../utils/index.js"
|
||||||
import { UserCommand } from "../utils/index.js";
|
|
||||||
|
|
||||||
export const PullModel: SlashCommand = {
|
export const PullModel: SlashCommand = {
|
||||||
name: 'pull-model',
|
name: 'pull-model',
|
||||||
description: 'pulls a model from the ollama model library. Administrator Only',
|
description: 'pulls a model from the ollama model library. Administrator Only.',
|
||||||
|
|
||||||
// set available user options to pass to the command
|
// set available user options to pass to the command
|
||||||
options: [
|
options: [
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { Client, CommandInteraction, ApplicationCommandOptionType } from 'discord.js'
|
import { Client, CommandInteraction } from 'discord.js'
|
||||||
import { SlashCommand } from '../utils/commands.js'
|
import { AdminCommand, SlashCommand } from '../utils/index.js'
|
||||||
import { AdminCommand } from '../utils/index.js'
|
|
||||||
|
|
||||||
export const Shutoff: SlashCommand = {
|
export const Shutoff: SlashCommand = {
|
||||||
name: 'shutoff',
|
name: 'shutoff',
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import { ApplicationCommandOptionType, Client, CommandInteraction } from "discord.js";
|
import { ApplicationCommandOptionType, Client, CommandInteraction } from "discord.js"
|
||||||
import { SlashCommand } from "../utils/commands.js";
|
import { ollama } from "../client.js"
|
||||||
import { ollama } from "../client.js";
|
import { ModelResponse } from "ollama"
|
||||||
import { ModelResponse } from "ollama";
|
import { openConfig, UserCommand, SlashCommand } from "../utils/index.js"
|
||||||
import { openConfig, UserCommand } from "../utils/index.js";
|
|
||||||
|
|
||||||
export const SwitchModel: SlashCommand = {
|
export const SwitchModel: SlashCommand = {
|
||||||
name: 'switch-model',
|
name: 'switch-model',
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ describe('Commands Existence', () => {
|
|||||||
// test specific commands in the object
|
// test specific commands in the object
|
||||||
it('references specific commands', () => {
|
it('references specific commands', () => {
|
||||||
const commandsString = commands.map(e => e.name).join(', ')
|
const commandsString = commands.map(e => e.name).join(', ')
|
||||||
expect(commandsString).toBe('thread, private-thread, message-stream, toggle-chat, shutoff, modify-capacity, clear-user-channel-history, pull-model, switch-model')
|
expect(commandsString).toBe('thread, private-thread, message-stream, toggle-chat, shutoff, modify-capacity, clear-user-channel-history, pull-model, switch-model, delete-model')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user