Skip to content

Commit

Permalink
Improve model commands
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbuker committed May 26, 2024
1 parent d0a7274 commit 3b4f2f1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions lib/discord_bot/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def set_model(channel_id:, model:)
instance.set_model(channel_id: channel_id, model: model)
end

def current_model(channel_id:)
instance.model(channel_id)
end

def reset_system_prompt(channel_id:)
instance.reset_system_prompt(channel_id: channel_id)
end
Expand Down
22 changes: 16 additions & 6 deletions lib/discord_bot/commands/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def register
subcommand.string(:model, 'What model to use', required: true)
end
command.subcommand(:list, 'List the available models')
command.subcommand(:current, 'Show the currently loaded model')
end
end

Expand All @@ -39,6 +40,10 @@ def handle
Bot.command_callback(command_name).subcommand(:list) do |event|
list_available_models(DiscordBot::Events::Command.new(event))
end

Bot.command_callback(command_name).subcommand(:current) do |event|
print_current_model(DiscordBot::Events::Command.new(event))
end
end

def run(command)
Expand All @@ -48,7 +53,8 @@ def run(command)
def reset_model(command)
Logger.info "#{command.whois} has reset the LLM model to default for #{command.channel_name}"
Bot.reset_model(channel_id: command.channel_id)
command.respond_with('Reset the LLM model to default')
default_model = DiscordBot::LLM::Model.new
command.respond_with("Reset the LLM model to default:\n#{default_model.about}")
end

def pull_model(command)
Expand Down Expand Up @@ -81,20 +87,24 @@ def set_model(command)
if model.available?
Logger.info "#{command.whois} has set the LLM model to #{requested_model} for \##{command.channel_name}"
Bot.set_model(channel_id: command.channel_id, model: model)
command.respond_with("Set LLM model to \"#{requested_model}\"")
command.respond_with("Set LLM model to:\n\"#{model.about}\"")
else
command.respond_with("That model is currently unavailable. Try running `/model pull #{requested_model}` first")
end
end

def print_current_model(command)
Logger.info "#{command.whois} inspected the current model"
model = Bot.current_model(channel_id: command.channel_id)
command.respond_with("The currently loaded model for \##{command.channel_name} is:\n#{model.about}")
end

def list_available_models(command)
Logger.info "#{command.whois} requested a list of the available models"
models = DiscordBot::LLM::Model.available_models
# TODO: Also show file size, parameter size, and quantization level
formatted_list = models.map do |model|
"- Name: `#{model.name}` - File size: `#{model.file_size}` - Parameter size: `#{model.parameter_size}`"
end.join("\n")
command.respond_with("The currently available models are:\n#{formatted_list}")
formatted_list = models.map{ |model| "- #{model.about}" }.join("\n")
command.respond_with("The currently available models are:\n#{formatted_list}\n\nMore can be found at: https://ollama.com/library")
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/discord_bot/llm/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def available?
false
end

def about
"Name: `#{name}` - File size: `#{file_size}` - Parameter size: `#{parameter_size}` - Quantization level: `#{quantization_level}`"
end

# TODO: Add automatic retry with backoff
def pull
return if available?
Expand Down

0 comments on commit 3b4f2f1

Please sign in to comment.