bunsen_tool/chat/chat_command_group/mod.rs
1//! `bunsen-tool chat`: the command group.
2
3mod chat_fetch;
4mod chat_generate_flags;
5mod chat_list;
6mod chat_repl;
7mod chat_run;
8mod family_command_group;
9
10use bunsen::errors::BunsenResult;
11pub use chat_fetch::*;
12pub use chat_generate_flags::*;
13pub use chat_list::*;
14pub use chat_repl::*;
15pub use chat_run::*;
16use clap::ArgMatches;
17pub use family_command_group::*;
18
19use crate::chat::{
20 ChatModelFamily,
21 ChatThinkFlags,
22};
23
24/// `bunsen-tool chat`'s commands: `chat <list|fetch|run|repl>` takes a
25/// checkpoint of any family, by its name; `chat family
26/// <qwen3|qwen3.5|gemma|nanochat> <list|fetch|run|repl>` runs one family's,
27/// its own default by default, with only the flags that apply to it.
28#[derive(clap::Args, Debug)]
29pub struct ChatCommandGroup {
30 #[clap(subcommand)]
31 command: ChatSubCommand,
32}
33
34#[derive(clap::Subcommand, Debug)]
35enum ChatSubCommand {
36 /// The checkpoints bunsen knows by name, every family's.
37 ///
38 /// Each one's origin, and each of its files' path in its repo and whether
39 /// it is cached.
40 List(ChatListCommand),
41
42 /// Brings every file of the named checkpoints into the weights cache.
43 ///
44 /// Each name is its own family's.
45 Fetch(ChatFetchCommand),
46
47 /// Answers one prompt, from the command line or stdin.
48 ///
49 /// The checkpoint is the one `--model` names, of whichever family.
50 Run(ChatRunCommand<ChatThinkFlags>),
51
52 /// Holds a conversation on stdin: `/reset` starts over, `/quit` leaves.
53 ///
54 /// The checkpoint is the one `--model` names, of whichever family; end of
55 /// input leaves too.
56 Repl(ChatReplCommand<ChatThinkFlags>),
57
58 /// The model families, each with its own `list`, `fetch`, `run` and `repl`.
59 ///
60 /// Each has its own default checkpoint, and only the flags that apply to
61 /// it.
62 Family(ChatFamilyCommandGroup),
63}
64
65impl ChatCommandGroup {
66 /// Runs the command; `matches` are the leaf command's own, for the
67 /// stage flags' order.
68 pub fn run(
69 &self,
70 matches: &ArgMatches,
71 ) -> BunsenResult<()> {
72 match &self.command {
73 ChatSubCommand::List(cmd) => cmd.run(&ChatModelFamily::ALL),
74 ChatSubCommand::Fetch(cmd) => cmd.run(None),
75 ChatSubCommand::Run(cmd) => cmd.run(None, matches),
76 ChatSubCommand::Repl(cmd) => cmd.run(None, matches),
77 ChatSubCommand::Family(cmd) => cmd.run(matches),
78 }
79 }
80}
81
82#[cfg(test)]
83mod tests;