Pull/Switch Model Commands Fix (#137)

* Update: Channel checker and channel name gone

* Add: note of where problem can be

* Update: Check if model already exists for Pull Command

* Add: User/Admin Command Constants

* Update: version increment
This commit is contained in:
Kevin Dang
2024-11-08 20:09:01 -08:00
committed by GitHub
parent 1ccd1a012e
commit 33152b33f3
15 changed files with 67 additions and 40 deletions

View File

@@ -1,6 +1,8 @@
import { ApplicationCommandOptionType, ChannelType, Client, CommandInteraction } from "discord.js";
import { ApplicationCommandOptionType, Client, CommandInteraction } from "discord.js";
import { SlashCommand } from "../utils/commands.js";
import { ollama } from "../client.js";
import { ModelResponse } from "ollama";
import { UserCommand } from "../utils/index.js";
export const PullModel: SlashCommand = {
name: 'pull-model',
@@ -24,13 +26,16 @@ export const PullModel: SlashCommand = {
// fetch channel and message
const channel = await client.channels.fetch(interaction.channelId)
if (!channel || channel.type !== (ChannelType.PrivateThread && ChannelType.PublicThread && ChannelType.GuildText)) return
if (!channel || !UserCommand.includes(channel.type)) return
// check if model was already pulled
const modelExists: boolean = await ollama.list()
.then(response => response.models.some((model: ModelResponse) => model.name.startsWith(modelInput)))
try {
// call ollama to pull desired model
await ollama.pull({
model: modelInput
})
if (!modelExists)
await ollama.pull({ model: modelInput })
} catch (error) {
// could not resolve pull or model unfound
interaction.editReply({
@@ -39,9 +44,14 @@ export const PullModel: SlashCommand = {
return
}
// successful pull
interaction.editReply({
content: `Successfully added **${modelInput}** into your local model library.`
})
// successful interaction
if (modelExists)
interaction.editReply({
content: `**${modelInput}** is already in your local model library.`
})
else
interaction.editReply({
content: `Successfully added **${modelInput}** into your local model library.`
})
}
}