mirror of
https://github.com/kevinthedang/discord-ollama.git
synced 2025-12-13 03:56:07 -05:00
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:
@@ -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.`
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user