bots-garden/razorbillpublic Fork
⑂ 2c18fab
Commits
⬇ Clone ▾
git clone https://git.rickub.com/bots-garden/razorbill.git
git clone ssh://git@rickub.com/bots-garden/razorbill.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP

TUI: Enter on the Models screen chats with the model; answers start under the model's name

Models: Enter opens the Chat screen with the selected model, under its
declared name when there is one (so the config's defaults and locks
apply), else its Hugging Face id; embedding models are refused. A model
chosen there stays current when the server's list arrives.
Chat: the model's name has a line of its own and the answer follows at
the full width, instead of being indented by a long repository id.
Docs EN+FR updated (reference, how-to, tutorial).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
k33g committed 2026-11-27T06:56:30+01:00 Browse files
2c18fab parent: 802366e
modified Sources/RazorbillTUI/ChatRenderer.swift +5 -4
@@ -57,18 +57,19 @@ public struct ChatRenderer: Sendable {
5757 }
5858 }
5959
60+ /// The model's name on a line of its own, then the answer at the full width: a long
61+ /// repository id would otherwise push every line of the answer to the right.
6062 func answer(
6163 _ entry: ChatEntry, display: ChatScreen.ReasoningDisplay, streaming: Bool, width: Int
6264 ) -> [String] {
63- let name = "\(entry.model ?? "model") › "
64- var lines: [String] = []
65+ var lines = [style.bold(TextLayout.truncate(entry.model ?? "model", width: width))]
6566 if !entry.reasoning.isEmpty {
6667 lines += reasoning(entry.reasoning, display: display, width: width)
6768 } else if streaming && entry.content.isEmpty {
6869 lines.append(style.dim(" ⋯ waiting for the model…"))
6970 }
70- if !entry.content.isEmpty || !streaming {
71- lines += labelled(style.bold(name), plainLabel: name, entry.content, width: width)
71+ if !entry.content.isEmpty {
72+ lines += TextLayout.wrap(entry.content, width: width)
7273 }
7374 if entry.stopped { lines.append(style.dim(" (stopped)")) }
7475 if let failure = entry.failure {
@@ -57,18 +57,19 @@ public struct ChatRenderer: Sendable {
57 }57 }
58 }58 }
59 59
60+ /// The model's name on a line of its own, then the answer at the full width: a long
61+ /// repository id would otherwise push every line of the answer to the right.
60 func answer(62 func answer(
61 _ entry: ChatEntry, display: ChatScreen.ReasoningDisplay, streaming: Bool, width: Int63 _ entry: ChatEntry, display: ChatScreen.ReasoningDisplay, streaming: Bool, width: Int
62 ) -> [String] {64 ) -> [String] {
63- let name = "\(entry.model ?? "model") › "65+ var lines = [style.bold(TextLayout.truncate(entry.model ?? "model", width: width))]
64- var lines: [String] = []
65 if !entry.reasoning.isEmpty {66 if !entry.reasoning.isEmpty {
66 lines += reasoning(entry.reasoning, display: display, width: width)67 lines += reasoning(entry.reasoning, display: display, width: width)
67 } else if streaming && entry.content.isEmpty {68 } else if streaming && entry.content.isEmpty {
68 lines.append(style.dim(" ⋯ waiting for the model…"))69 lines.append(style.dim(" ⋯ waiting for the model…"))
69 }70 }
70- if !entry.content.isEmpty || !streaming {71+ if !entry.content.isEmpty {
71- lines += labelled(style.bold(name), plainLabel: name, entry.content, width: width)72+ lines += TextLayout.wrap(entry.content, width: width)
72 }73 }
73 if entry.stopped { lines.append(style.dim(" (stopped)")) }74 if entry.stopped { lines.append(style.dim(" (stopped)")) }
74 if let failure = entry.failure {75 if let failure = entry.failure {
modified Sources/RazorbillTUI/ChatScreen.swift +16 -1
@@ -68,6 +68,8 @@ public struct ChatScreen: Sendable, Equatable {
6868 public private(set) var input = TextField()
6969 /// The model the next message goes to.
7070 public private(set) var model: String?
71+ /// `model` was chosen explicitly, not picked as the default.
72+ private var chosen = false
7173 /// The chat models the server offers.
7274 public private(set) var models: [String] = []
7375 /// The model list is open (Ctrl-P).
@@ -93,10 +95,12 @@ public struct ChatScreen: Sendable, Equatable {
9395
9496 public init() {}
9597
96- /// The server's chat models. The first loaded one becomes current when none is chosen.
98+ /// The server's chat models. The first loaded one becomes current when none is chosen; a
99+ /// model chosen from the Models screen stays current even if the list does not name it.
97100 public mutating func setModels(_ served: [ServedModel]) {
98101 let chatModels = served.filter { ($0.kind ?? "chat") == "chat" }
99102 models = chatModels.map(\.id)
103+ if let model, chosen, !models.contains(model) { models.append(model) }
100104 if model == nil || !models.contains(model ?? "") {
101105 model = chatModels.first { $0.loaded == true }?.id ?? models.first
102106 }
@@ -117,6 +121,16 @@ public struct ChatScreen: Sendable, Equatable {
117121 options = ChatOptions(preferences.chat)
118122 }
119123
124+ /// Makes `name` the current model (from the Models screen's Enter).
125+ public mutating func choose(_ name: String) {
126+ model = name
127+ chosen = true
128+ if !models.contains(name) { models.append(name) }
129+ picker.resize(to: models.count)
130+ if let index = models.firstIndex(of: name) { picker.select(index) }
131+ note("model: \(name)")
132+ }
133+
120134 // MARK: Keys
121135
122136 public mutating func handle(_ key: Key) -> Action {
@@ -152,6 +166,7 @@ public struct ChatScreen: Sendable, Equatable {
152166 picking = false
153167 if picker.selected < models.count {
154168 model = models[picker.selected]
169+ chosen = true
155170 note("model: \(models[picker.selected])")
156171 }
157172 default:
@@ -68,6 +68,8 @@ public struct ChatScreen: Sendable, Equatable {
68 public private(set) var input = TextField()68 public private(set) var input = TextField()
69 /// The model the next message goes to.69 /// The model the next message goes to.
70 public private(set) var model: String?70 public private(set) var model: String?
71+ /// `model` was chosen explicitly, not picked as the default.
72+ private var chosen = false
71 /// The chat models the server offers.73 /// The chat models the server offers.
72 public private(set) var models: [String] = []74 public private(set) var models: [String] = []
73 /// The model list is open (Ctrl-P).75 /// The model list is open (Ctrl-P).
@@ -93,10 +95,12 @@ public struct ChatScreen: Sendable, Equatable {
93 95
94 public init() {}96 public init() {}
95 97
96- /// The server's chat models. The first loaded one becomes current when none is chosen.98+ /// The server's chat models. The first loaded one becomes current when none is chosen; a
99+ /// model chosen from the Models screen stays current even if the list does not name it.
97 public mutating func setModels(_ served: [ServedModel]) {100 public mutating func setModels(_ served: [ServedModel]) {
98 let chatModels = served.filter { ($0.kind ?? "chat") == "chat" }101 let chatModels = served.filter { ($0.kind ?? "chat") == "chat" }
99 models = chatModels.map(\.id)102 models = chatModels.map(\.id)
103+ if let model, chosen, !models.contains(model) { models.append(model) }
100 if model == nil || !models.contains(model ?? "") {104 if model == nil || !models.contains(model ?? "") {
101 model = chatModels.first { $0.loaded == true }?.id ?? models.first105 model = chatModels.first { $0.loaded == true }?.id ?? models.first
102 }106 }
@@ -117,6 +121,16 @@ public struct ChatScreen: Sendable, Equatable {
117 options = ChatOptions(preferences.chat)121 options = ChatOptions(preferences.chat)
118 }122 }
119 123
124+ /// Makes `name` the current model (from the Models screen's Enter).
125+ public mutating func choose(_ name: String) {
126+ model = name
127+ chosen = true
128+ if !models.contains(name) { models.append(name) }
129+ picker.resize(to: models.count)
130+ if let index = models.firstIndex(of: name) { picker.select(index) }
131+ note("model: \(name)")
132+ }
133+
120 // MARK: Keys134 // MARK: Keys
121 135
122 public mutating func handle(_ key: Key) -> Action {136 public mutating func handle(_ key: Key) -> Action {
@@ -152,6 +166,7 @@ public struct ChatScreen: Sendable, Equatable {
152 picking = false166 picking = false
153 if picker.selected < models.count {167 if picker.selected < models.count {
154 model = models[picker.selected]168 model = models[picker.selected]
169+ chosen = true
155 note("model: \(models[picker.selected])")170 note("model: \(models[picker.selected])")
156 }171 }
157 default:172 default:
modified Sources/RazorbillTUI/ModelsRenderer.swift +1 -1
@@ -22,7 +22,7 @@ public struct ModelsRenderer: Sendable {
2222 var lines = [
2323 "",
2424 style.bold(" Models in the Hugging Face cache")
25- + style.dim(" ↑↓ select · p download · d remove · r refresh"),
25+ + style.dim(" ↑↓ select · Enter chat with it · p download · d remove · r refresh"),
2626 style.dim(" " + Self.header),
2727 ]
2828 let footer = footerLines(screen, memory: memory)
@@ -22,7 +22,7 @@ public struct ModelsRenderer: Sendable {
22 var lines = [22 var lines = [
23 "",23 "",
24 style.bold(" Models in the Hugging Face cache")24 style.bold(" Models in the Hugging Face cache")
25- + style.dim(" ↑↓ select · p download · d remove · r refresh"),25+ + style.dim(" ↑↓ select · Enter chat with it · p download · d remove · r refresh"),
26 style.dim(" " + Self.header),26 style.dim(" " + Self.header),
27 ]27 ]
28 let footer = footerLines(screen, memory: memory)28 let footer = footerLines(screen, memory: memory)
modified Sources/RazorbillTUI/ModelsScreen.swift +10 -0
@@ -63,6 +63,8 @@ public struct ModelsScreen: Sendable, Equatable {
6363 case refresh
6464 case pull(String)
6565 case remove(String)
66+ /// Open the Chat screen with this model (the name to put in `"model"`).
67+ case chat(String)
6668 }
6769
6870 public private(set) var rows: [ModelRow] = []
@@ -107,6 +109,14 @@ public struct ModelsScreen: Sendable, Equatable {
107109 return .redraw
108110 case .character("r"):
109111 return .refresh
112+ case .enter:
113+ guard let selected else { return .none }
114+ guard selected.kind != "embedding" else {
115+ notice = "\(selected.id) is an embedding model: it cannot chat"
116+ return .redraw
117+ }
118+ // The declared name, when there is one, gets the configuration's defaults and locks.
119+ return .chat(selected.declaredAs.first ?? selected.id)
110120 default:
111121 return .none
112122 }
@@ -63,6 +63,8 @@ public struct ModelsScreen: Sendable, Equatable {
63 case refresh63 case refresh
64 case pull(String)64 case pull(String)
65 case remove(String)65 case remove(String)
66+ /// Open the Chat screen with this model (the name to put in `"model"`).
67+ case chat(String)
66 }68 }
67 69
68 public private(set) var rows: [ModelRow] = []70 public private(set) var rows: [ModelRow] = []
@@ -107,6 +109,14 @@ public struct ModelsScreen: Sendable, Equatable {
107 return .redraw109 return .redraw
108 case .character("r"):110 case .character("r"):
109 return .refresh111 return .refresh
112+ case .enter:
113+ guard let selected else { return .none }
114+ guard selected.kind != "embedding" else {
115+ notice = "\(selected.id) is an embedding model: it cannot chat"
116+ return .redraw
117+ }
118+ // The declared name, when there is one, gets the configuration's defaults and locks.
119+ return .chat(selected.declaredAs.first ?? selected.id)
110 default:120 default:
111 return .none121 return .none
112 }122 }
modified Sources/RazorbillTUI/TUIApp+Models.swift +4 -0
@@ -11,6 +11,10 @@ extension TUIApp {
1111 case .refresh: refreshModels()
1212 case .pull(let id): Task { await pull(id) }
1313 case .remove(let id): Task { await remove(id) }
14+ case .chat(let name):
15+ chat.choose(name)
16+ state.screen = .chat
17+ if !modelsRequested { loadModels() }
1418 }
1519 }
1620
@@ -11,6 +11,10 @@ extension TUIApp {
11 case .refresh: refreshModels()11 case .refresh: refreshModels()
12 case .pull(let id): Task { await pull(id) }12 case .pull(let id): Task { await pull(id) }
13 case .remove(let id): Task { await remove(id) }13 case .remove(let id): Task { await remove(id) }
14+ case .chat(let name):
15+ chat.choose(name)
16+ state.screen = .chat
17+ if !modelsRequested { loadModels() }
14 }18 }
15 }19 }
16 20
modified Sources/RazorbillTUI/TUIApp.swift +3 -3
@@ -31,14 +31,14 @@ public actor TUIApp {
3131 var pollInterval: Duration
3232 private let startCommand: String
3333 private let now: @Sendable () -> Date
34- private var state: AppState
34+ var state: AppState
3535 var snapshot: StatusSnapshot?
3636 private var dashboard = DashboardScreen()
3737 var chat = ChatScreen()
3838 var models = ModelsScreen()
3939 var settings: SettingsScreen
4040 private var answer: Task<Void, Never>?
41- private var modelsRequested = false
41+ var modelsRequested = false
4242 /// False once `run` returns: work still in flight must not draw on the restored terminal.
4343 private var running = false
4444
@@ -145,7 +145,7 @@ public actor TUIApp {
145145
146146 // MARK: Chat screen
147147
148- private func loadModels() {
148+ func loadModels() {
149149 modelsRequested = true
150150 Task { await fetchModels() }
151151 }
@@ -31,14 +31,14 @@ public actor TUIApp {
31 var pollInterval: Duration31 var pollInterval: Duration
32 private let startCommand: String32 private let startCommand: String
33 private let now: @Sendable () -> Date33 private let now: @Sendable () -> Date
34- private var state: AppState34+ var state: AppState
35 var snapshot: StatusSnapshot?35 var snapshot: StatusSnapshot?
36 private var dashboard = DashboardScreen()36 private var dashboard = DashboardScreen()
37 var chat = ChatScreen()37 var chat = ChatScreen()
38 var models = ModelsScreen()38 var models = ModelsScreen()
39 var settings: SettingsScreen39 var settings: SettingsScreen
40 private var answer: Task<Void, Never>?40 private var answer: Task<Void, Never>?
41- private var modelsRequested = false41+ var modelsRequested = false
42 /// False once `run` returns: work still in flight must not draw on the restored terminal.42 /// False once `run` returns: work still in flight must not draw on the restored terminal.
43 private var running = false43 private var running = false
44 44
@@ -145,7 +145,7 @@ public actor TUIApp {
145 145
146 // MARK: Chat screen146 // MARK: Chat screen
147 147
148- private func loadModels() {148+ func loadModels() {
149 modelsRequested = true149 modelsRequested = true
150 Task { await fetchModels() }150 Task { await fetchModels() }
151 }151 }
modified Tests/RazorbillTUITests/DashboardAndChatTests.swift +26 -4
@@ -215,6 +215,14 @@ let plain = Style(colors: false)
215215 #expect(chat.turns().isEmpty)
216216 }
217217
218+ @Test func aChosenModelSurvivesTheServersList() {
219+ var chat = ChatScreen()
220+ chat.choose("org/picked")
221+ chat.setModels([ServedModel(id: "qwen", loaded: true, kind: "chat")])
222+ #expect(chat.model == "org/picked" && chat.models == ["qwen", "org/picked"])
223+ #expect(chat.entries.last?.content == "model: org/picked")
224+ }
225+
218226 @Test func failedAnswersAreNotResent() {
219227 var chat = ChatScreen()
220228 chat.setModels(["qwen"])
@@ -250,12 +258,13 @@ let plain = Style(colors: false)
250258 return chat
251259 }
252260
253- @Test func conversationWithFoldedReasoning() {
261+ @Test func conversationWithFoldedReasoning() throws {
254262 let (lines, cursor) = renderer.render(answered(), width: 60, height: 10)
255263 #expect(lines.count == 10)
256264 #expect(lines.contains("you › hello"))
257265 #expect(lines.contains(" ⋯ thinking (3 words) · Ctrl-R to show"))
258- #expect(lines.contains("qwen › Hi there"))
266+ let name = try #require(lines.firstIndex(of: "qwen"))
267+ #expect(lines[name + 2] == "Hi there")
259268 #expect(lines[9] == "› " && cursor.row == 9 && cursor.column == 2)
260269 #expect(lines[8].contains("Enter send"))
261270 }
@@ -283,6 +292,19 @@ let plain = Style(colors: false)
283292 #expect(lines[6].contains("Esc stop"))
284293 }
285294
295+ @Test func longModelIdsDoNotShiftTheAnswer() {
296+ var chat = ChatScreen()
297+ chat.setModels(["mlx-community/Qwen3-4B-4bit"])
298+ _ = chat.handle(.character("x"))
299+ _ = chat.handle(.enter)
300+ chat.receive(.content(String(repeating: "word ", count: 12)))
301+ chat.finish(generationSeconds: nil)
302+ let lines = renderer.render(chat, width: 30, height: 12).lines
303+ let name = lines.firstIndex(of: "mlx-community/Qwen3-4B-4bit")
304+ #expect(name != nil)
305+ #expect(lines[(name ?? 0) + 1].hasPrefix("word word word word word"))
306+ }
307+
286308 @Test func longInputShowsItsEnd() {
287309 var chat = ChatScreen()
288310 for character in String(repeating: "a", count: 50) + "XYZ" {
@@ -319,7 +341,7 @@ let plain = Style(colors: false)
319341 try await waitForScreen(terminal, containing: "Ctrl-P model: qwen")
320342 terminal.type("hello")
321343 terminal.press(.enter)
322- try await waitForScreen(terminal, containing: "qwen › Hi!")
344+ try await waitForScreen(terminal, containing: "qwen\nHi!")
323345 try await waitForScreen(terminal, containing: "5+2 tokens · 3 cached")
324346 #expect(server.conversations == [[ChatTurn(role: "user", content: "hello")]])
325347 terminal.press(.control("q"))
@@ -337,7 +359,7 @@ let plain = Style(colors: false)
337359 try await waitForScreen(terminal, containing: "Ctrl-P model: qwen")
338360 terminal.type("hi")
339361 terminal.press(.enter)
340- try await waitForScreen(terminal, containing: "qwen › partial")
362+ try await waitForScreen(terminal, containing: "qwen\npartial")
341363 terminal.press(.control("c"))
342364 try await waitForScreen(terminal, containing: "(stopped)")
343365 #expect(server.cancellations == 1)
@@ -215,6 +215,14 @@ let plain = Style(colors: false)
215 #expect(chat.turns().isEmpty)215 #expect(chat.turns().isEmpty)
216 }216 }
217 217
218+ @Test func aChosenModelSurvivesTheServersList() {
219+ var chat = ChatScreen()
220+ chat.choose("org/picked")
221+ chat.setModels([ServedModel(id: "qwen", loaded: true, kind: "chat")])
222+ #expect(chat.model == "org/picked" && chat.models == ["qwen", "org/picked"])
223+ #expect(chat.entries.last?.content == "model: org/picked")
224+ }
225+
218 @Test func failedAnswersAreNotResent() {226 @Test func failedAnswersAreNotResent() {
219 var chat = ChatScreen()227 var chat = ChatScreen()
220 chat.setModels(["qwen"])228 chat.setModels(["qwen"])
@@ -250,12 +258,13 @@ let plain = Style(colors: false)
250 return chat258 return chat
251 }259 }
252 260
253- @Test func conversationWithFoldedReasoning() {261+ @Test func conversationWithFoldedReasoning() throws {
254 let (lines, cursor) = renderer.render(answered(), width: 60, height: 10)262 let (lines, cursor) = renderer.render(answered(), width: 60, height: 10)
255 #expect(lines.count == 10)263 #expect(lines.count == 10)
256 #expect(lines.contains("you › hello"))264 #expect(lines.contains("you › hello"))
257 #expect(lines.contains(" ⋯ thinking (3 words) · Ctrl-R to show"))265 #expect(lines.contains(" ⋯ thinking (3 words) · Ctrl-R to show"))
258- #expect(lines.contains("qwen › Hi there"))266+ let name = try #require(lines.firstIndex(of: "qwen"))
267+ #expect(lines[name + 2] == "Hi there")
259 #expect(lines[9] == "› " && cursor.row == 9 && cursor.column == 2)268 #expect(lines[9] == "› " && cursor.row == 9 && cursor.column == 2)
260 #expect(lines[8].contains("Enter send"))269 #expect(lines[8].contains("Enter send"))
261 }270 }
@@ -283,6 +292,19 @@ let plain = Style(colors: false)
283 #expect(lines[6].contains("Esc stop"))292 #expect(lines[6].contains("Esc stop"))
284 }293 }
285 294
295+ @Test func longModelIdsDoNotShiftTheAnswer() {
296+ var chat = ChatScreen()
297+ chat.setModels(["mlx-community/Qwen3-4B-4bit"])
298+ _ = chat.handle(.character("x"))
299+ _ = chat.handle(.enter)
300+ chat.receive(.content(String(repeating: "word ", count: 12)))
301+ chat.finish(generationSeconds: nil)
302+ let lines = renderer.render(chat, width: 30, height: 12).lines
303+ let name = lines.firstIndex(of: "mlx-community/Qwen3-4B-4bit")
304+ #expect(name != nil)
305+ #expect(lines[(name ?? 0) + 1].hasPrefix("word word word word word"))
306+ }
307+
286 @Test func longInputShowsItsEnd() {308 @Test func longInputShowsItsEnd() {
287 var chat = ChatScreen()309 var chat = ChatScreen()
288 for character in String(repeating: "a", count: 50) + "XYZ" {310 for character in String(repeating: "a", count: 50) + "XYZ" {
@@ -319,7 +341,7 @@ let plain = Style(colors: false)
319 try await waitForScreen(terminal, containing: "Ctrl-P model: qwen")341 try await waitForScreen(terminal, containing: "Ctrl-P model: qwen")
320 terminal.type("hello")342 terminal.type("hello")
321 terminal.press(.enter)343 terminal.press(.enter)
322- try await waitForScreen(terminal, containing: "qwen › Hi!")344+ try await waitForScreen(terminal, containing: "qwen\nHi!")
323 try await waitForScreen(terminal, containing: "5+2 tokens · 3 cached")345 try await waitForScreen(terminal, containing: "5+2 tokens · 3 cached")
324 #expect(server.conversations == [[ChatTurn(role: "user", content: "hello")]])346 #expect(server.conversations == [[ChatTurn(role: "user", content: "hello")]])
325 terminal.press(.control("q"))347 terminal.press(.control("q"))
@@ -337,7 +359,7 @@ let plain = Style(colors: false)
337 try await waitForScreen(terminal, containing: "Ctrl-P model: qwen")359 try await waitForScreen(terminal, containing: "Ctrl-P model: qwen")
338 terminal.type("hi")360 terminal.type("hi")
339 terminal.press(.enter)361 terminal.press(.enter)
340- try await waitForScreen(terminal, containing: "qwen › partial")362+ try await waitForScreen(terminal, containing: "qwen\npartial")
341 terminal.press(.control("c"))363 terminal.press(.control("c"))
342 try await waitForScreen(terminal, containing: "(stopped)")364 try await waitForScreen(terminal, containing: "(stopped)")
343 #expect(server.cancellations == 1)365 #expect(server.cancellations == 1)
modified Tests/RazorbillTUITests/ModelsAndSettingsTests.swift +37 -0
@@ -84,6 +84,24 @@ func stored(_ id: String, size: Int64 = 1 << 30, loadable: Bool = true) -> Store
8484 #expect(empty.handle(.character("d")) == .none)
8585 }
8686
87+ @Test func enterChatsWithTheDeclaredNameElseTheId() {
88+ let config = ServerConfig(models: [
89+ ModelEntry(id: "q", source: .huggingFace(id: "org/a", revision: "main")),
90+ ModelEntry(
91+ id: "e", source: .huggingFace(id: "org/e", revision: "main"), kind: .embedding),
92+ ])
93+ var screen = ModelsScreen()
94+ screen.setRows(
95+ ModelRow.rows(
96+ [stored("org/a"), stored("org/b"), stored("org/e")], status: nil, config: config))
97+ #expect(screen.handle(.enter) == .chat("q"))
98+ _ = screen.handle(.arrowDown)
99+ #expect(screen.handle(.enter) == .chat("org/b"))
100+ _ = screen.handle(.arrowDown)
101+ #expect(screen.handle(.enter) == .redraw)
102+ #expect(screen.notice == "org/e is an embedding model: it cannot chat")
103+ }
104+
87105 @Test func rendersColumnsDownloadsHintAndPrompt() {
88106 var screen = screen(["org/big"])
89107 screen.downloads["org/new"] = 0.42
@@ -211,6 +229,25 @@ func stored(_ id: String, size: Int64 = 1 << 30, loadable: Bool = true) -> Store
211229 await running.value
212230 }
213231
232+ @Test func enterOnAModelOpensTheChatWithIt() async throws {
233+ let terminal = FakeTerminal(rows: 24, columns: 120)
234+ let environment = testEnvironment()
235+ try cache("org/other", size: 1024, in: environment.store)
236+ let server = ScriptedServer(.success(snapshot()))
237+ let app = app(terminal, server, environment)
238+ let running = Task { await app.run() }
239+ terminal.press(.function(3))
240+ try await waitForScreen(terminal, containing: "org/other")
241+ terminal.press(.enter)
242+ try await waitForScreen(terminal, containing: "Ctrl-P model: org/other")
243+ #expect(await app.currentState.screen == .chat)
244+ terminal.type("hi")
245+ terminal.press(.enter)
246+ try await waitForScreen(terminal, containing: "org/other\nHi!")
247+ terminal.press(.control("q"))
248+ await running.value
249+ }
250+
214251 @Test func removingALoadedModelUnloadsItFirst() async throws {
215252 let terminal = FakeTerminal(rows: 24, columns: 120)
216253 let environment = testEnvironment()
@@ -84,6 +84,24 @@ func stored(_ id: String, size: Int64 = 1 << 30, loadable: Bool = true) -> Store
84 #expect(empty.handle(.character("d")) == .none)84 #expect(empty.handle(.character("d")) == .none)
85 }85 }
86 86
87+ @Test func enterChatsWithTheDeclaredNameElseTheId() {
88+ let config = ServerConfig(models: [
89+ ModelEntry(id: "q", source: .huggingFace(id: "org/a", revision: "main")),
90+ ModelEntry(
91+ id: "e", source: .huggingFace(id: "org/e", revision: "main"), kind: .embedding),
92+ ])
93+ var screen = ModelsScreen()
94+ screen.setRows(
95+ ModelRow.rows(
96+ [stored("org/a"), stored("org/b"), stored("org/e")], status: nil, config: config))
97+ #expect(screen.handle(.enter) == .chat("q"))
98+ _ = screen.handle(.arrowDown)
99+ #expect(screen.handle(.enter) == .chat("org/b"))
100+ _ = screen.handle(.arrowDown)
101+ #expect(screen.handle(.enter) == .redraw)
102+ #expect(screen.notice == "org/e is an embedding model: it cannot chat")
103+ }
104+
87 @Test func rendersColumnsDownloadsHintAndPrompt() {105 @Test func rendersColumnsDownloadsHintAndPrompt() {
88 var screen = screen(["org/big"])106 var screen = screen(["org/big"])
89 screen.downloads["org/new"] = 0.42107 screen.downloads["org/new"] = 0.42
@@ -211,6 +229,25 @@ func stored(_ id: String, size: Int64 = 1 << 30, loadable: Bool = true) -> Store
211 await running.value229 await running.value
212 }230 }
213 231
232+ @Test func enterOnAModelOpensTheChatWithIt() async throws {
233+ let terminal = FakeTerminal(rows: 24, columns: 120)
234+ let environment = testEnvironment()
235+ try cache("org/other", size: 1024, in: environment.store)
236+ let server = ScriptedServer(.success(snapshot()))
237+ let app = app(terminal, server, environment)
238+ let running = Task { await app.run() }
239+ terminal.press(.function(3))
240+ try await waitForScreen(terminal, containing: "org/other")
241+ terminal.press(.enter)
242+ try await waitForScreen(terminal, containing: "Ctrl-P model: org/other")
243+ #expect(await app.currentState.screen == .chat)
244+ terminal.type("hi")
245+ terminal.press(.enter)
246+ try await waitForScreen(terminal, containing: "org/other\nHi!")
247+ terminal.press(.control("q"))
248+ await running.value
249+ }
250+
214 @Test func removingALoadedModelUnloadsItFirst() async throws {251 @Test func removingALoadedModelUnloadsItFirst() async throws {
215 let terminal = FakeTerminal(rows: 24, columns: 120)252 let terminal = FakeTerminal(rows: 24, columns: 120)
216 let environment = testEnvironment()253 let environment = testEnvironment()
modified Tests/RazorbillTUITests/ServerClientTests.swift +1 -1
@@ -203,7 +203,7 @@ extension ServerClientError {
203203 terminal.press(.enter)
204204 terminal.type("ping")
205205 terminal.press(.enter)
206- try await waitForScreen(terminal, containing: "echo › echo: ping")
206+ try await waitForScreen(terminal, containing: "echo\necho: ping")
207207 try await waitForScreen(terminal, containing: "tokens")
208208 terminal.press(.control("q"))
209209 await running.value
@@ -203,7 +203,7 @@ extension ServerClientError {
203 terminal.press(.enter)203 terminal.press(.enter)
204 terminal.type("ping")204 terminal.type("ping")
205 terminal.press(.enter)205 terminal.press(.enter)
206- try await waitForScreen(terminal, containing: "echo › echo: ping")206+ try await waitForScreen(terminal, containing: "echo\necho: ping")
207 try await waitForScreen(terminal, containing: "tokens")207 try await waitForScreen(terminal, containing: "tokens")
208 terminal.press(.control("q"))208 terminal.press(.control("q"))
209 await running.value209 await running.value
modified docs/en/how-to/manage-models-from-the-tui.md +4 -0
@@ -17,6 +17,10 @@ The download is the one `rzb models pull` makes, with the same rule: only models
1717
1818 When the server has the model loaded, it is unloaded first. If a request is using it, nothing is removed and the screen says why: try again once the Dashboard shows it idle.
1919
20+## Chat with a model
21+
22+Select it and press `Enter`: the Chat screen opens with that model. A model the configuration declares is used under its declared name, so the configuration's defaults and locks apply.
23+
2024 ## Check that a model fits before loading it
2125
2226 Select it: the line under the list gives its size and the server's memory in use over its limit, and says `more than is free now` when it would not fit beside the models already loaded. The server then unloads idle models to make room, or answers 503 when it cannot.
@@ -17,6 +17,10 @@ The download is the one `rzb models pull` makes, with the same rule: only models
17 17
18 When the server has the model loaded, it is unloaded first. If a request is using it, nothing is removed and the screen says why: try again once the Dashboard shows it idle.18 When the server has the model loaded, it is unloaded first. If a request is using it, nothing is removed and the screen says why: try again once the Dashboard shows it idle.
19 19
20+## Chat with a model
21+
22+Select it and press `Enter`: the Chat screen opens with that model. A model the configuration declares is used under its declared name, so the configuration's defaults and locks apply.
23+
20 ## Check that a model fits before loading it24 ## Check that a model fits before loading it
21 25
22 Select it: the line under the list gives its size and the server's memory in use over its limit, and says `more than is free now` when it would not fit beside the models already loaded. The server then unloads idle models to make room, or answers 503 when it cannot.26 Select it: the line under the list gives its size and the server's memory in use over its limit, and says `more than is free now` when it would not fit beside the models already loaded. The server then unloads idle models to make room, or answers 503 when it cannot.
modified docs/en/reference/tui.md +2 -1
@@ -52,7 +52,7 @@ The server's version, uptime and address; the engine's memory as a gauge of acti
5252
5353 ## Chat (F1)
5454
55-A streamed conversation with a chat model of the server. The conversation is kept by `rzb tui` and resent whole with each message; the server's prompt cache makes that cheap. The model is the first loaded chat model of `/v1/models`, else the first chat model listed. After each answer: prompt+completion tokens, cached prompt tokens, tokens per second from the first piece to the last.
55+A streamed conversation with a chat model of the server. Each answer starts with the model's name on a line of its own; the answer follows at the full width. The conversation is kept by `rzb tui` and resent whole with each message; the server's prompt cache makes that cheap. The model is the first loaded chat model of `/v1/models`, else the first chat model listed. After each answer: prompt+completion tokens, cached prompt tokens, tokens per second from the first piece to the last.
5656
5757 | Key | Effect |
5858 | --- | --- |
@@ -91,6 +91,7 @@ The hint gives the selected model's size and the server's memory in use over its
9191 | Key | Effect |
9292 | --- | --- |
9393 | `↑` `↓` `PgUp` `PgDn` `Home` `End` | Select a model |
94+| `Enter` | Open the Chat screen with the selected model, under its declared name when it has one, else its Hugging Face id (embedding models are refused) |
9495 | `p` | Type a Hugging Face id (`org/name`), `Enter` downloads it with the engine of the build (progress shown), `Esc` cancels |
9596 | `d`, `Delete` | Remove the selected model from the disk after `y` (any other key keeps it). A loaded model is unloaded first; while the server is using it, nothing is removed |
9697 | `r` | Read the cache again |
@@ -52,7 +52,7 @@ The server's version, uptime and address; the engine's memory as a gauge of acti
52 52
53 ## Chat (F1)53 ## Chat (F1)
54 54
55-A streamed conversation with a chat model of the server. The conversation is kept by `rzb tui` and resent whole with each message; the server's prompt cache makes that cheap. The model is the first loaded chat model of `/v1/models`, else the first chat model listed. After each answer: prompt+completion tokens, cached prompt tokens, tokens per second from the first piece to the last.55+A streamed conversation with a chat model of the server. Each answer starts with the model's name on a line of its own; the answer follows at the full width. The conversation is kept by `rzb tui` and resent whole with each message; the server's prompt cache makes that cheap. The model is the first loaded chat model of `/v1/models`, else the first chat model listed. After each answer: prompt+completion tokens, cached prompt tokens, tokens per second from the first piece to the last.
56 56
57 | Key | Effect |57 | Key | Effect |
58 | --- | --- |58 | --- | --- |
@@ -91,6 +91,7 @@ The hint gives the selected model's size and the server's memory in use over its
91 | Key | Effect |91 | Key | Effect |
92 | --- | --- |92 | --- | --- |
93 | `↑` `↓` `PgUp` `PgDn` `Home` `End` | Select a model |93 | `↑` `↓` `PgUp` `PgDn` `Home` `End` | Select a model |
94+| `Enter` | Open the Chat screen with the selected model, under its declared name when it has one, else its Hugging Face id (embedding models are refused) |
94 | `p` | Type a Hugging Face id (`org/name`), `Enter` downloads it with the engine of the build (progress shown), `Esc` cancels |95 | `p` | Type a Hugging Face id (`org/name`), `Enter` downloads it with the engine of the build (progress shown), `Esc` cancels |
95 | `d`, `Delete` | Remove the selected model from the disk after `y` (any other key keeps it). A loaded model is unloaded first; while the server is using it, nothing is removed |96 | `d`, `Delete` | Remove the selected model from the disk after `y` (any other key keeps it). A loaded model is unloaded first; while the server is using it, nothing is removed |
96 | `r` | Read the cache again |97 | `r` | Read the cache again |
modified docs/en/tutorials/chat-from-the-terminal.md +1 -1
@@ -65,7 +65,7 @@ In the first terminal, press `F1`. The Chat screen says `Model: qwen`. Type:
6565 Say hi in five words.
6666 ```
6767
68-and press `Enter`. The first answer takes a few seconds while the server loads the model: you see `⋯ waiting for the model…`. Then Qwen3 thinks before answering: a line `⋯ thinking (… words) · Ctrl-R to show` appears, then the answer after `qwen ›`, then a dim line such as `23+41 tokens · 85.3 tok/s`. The exact words and numbers differ on your Mac.
68+and press `Enter`. The first answer takes a few seconds while the server loads the model: you see `⋯ waiting for the model…`. Then Qwen3 thinks before answering: a line `⋯ thinking (… words) · Ctrl-R to show` appears, then the answer, under the model's name `qwen`, then a dim line such as `23+41 tokens · 85.3 tok/s`. The exact words and numbers differ on your Mac.
6969
7070 We have chatted with a model on the GPU, through the server's OpenAI API.
7171
@@ -65,7 +65,7 @@ In the first terminal, press `F1`. The Chat screen says `Model: qwen`. Type:
65 Say hi in five words.65 Say hi in five words.
66 ```66 ```
67 67
68-and press `Enter`. The first answer takes a few seconds while the server loads the model: you see `⋯ waiting for the model…`. Then Qwen3 thinks before answering: a line `⋯ thinking (… words) · Ctrl-R to show` appears, then the answer after `qwen ›`, then a dim line such as `23+41 tokens · 85.3 tok/s`. The exact words and numbers differ on your Mac.68+and press `Enter`. The first answer takes a few seconds while the server loads the model: you see `⋯ waiting for the model…`. Then Qwen3 thinks before answering: a line `⋯ thinking (… words) · Ctrl-R to show` appears, then the answer, under the model's name `qwen`, then a dim line such as `23+41 tokens · 85.3 tok/s`. The exact words and numbers differ on your Mac.
69 69
70 We have chatted with a model on the GPU, through the server's OpenAI API.70 We have chatted with a model on the GPU, through the server's OpenAI API.
71 71
modified docs/fr/how-to/gerer-les-modeles-depuis-la-tui.md +4 -0
@@ -17,6 +17,10 @@ Le téléchargement est celui que fait `rzb models pull`, avec la même règle :
1717
1818 Quand le serveur a ce modèle chargé, il est d'abord déchargé. Si une requête l'utilise, rien n'est supprimé et l'écran dit pourquoi : réessaie quand le Dashboard le montre au repos.
1919
20+## Discuter avec un modèle
21+
22+Choisis-le et appuie sur `Entrée` : l'écran Chat s'ouvre avec ce modèle. Un modèle que la configuration déclare est utilisé sous son nom déclaré, pour que les valeurs par défaut et les verrous de la configuration s'appliquent.
23+
2024 ## Vérifier qu'un modèle tient avant de le charger
2125
2226 Choisis-le : la ligne sous la liste donne sa taille et la mémoire du serveur utilisée sur sa limite, et indique `more than is free now` quand il ne tiendrait pas à côté des modèles déjà chargés. Le serveur décharge alors les modèles au repos pour faire de la place, ou répond 503 quand il ne peut pas.
@@ -17,6 +17,10 @@ Le téléchargement est celui que fait `rzb models pull`, avec la même règle :
17 17
18 Quand le serveur a ce modèle chargé, il est d'abord déchargé. Si une requête l'utilise, rien n'est supprimé et l'écran dit pourquoi : réessaie quand le Dashboard le montre au repos.18 Quand le serveur a ce modèle chargé, il est d'abord déchargé. Si une requête l'utilise, rien n'est supprimé et l'écran dit pourquoi : réessaie quand le Dashboard le montre au repos.
19 19
20+## Discuter avec un modèle
21+
22+Choisis-le et appuie sur `Entrée` : l'écran Chat s'ouvre avec ce modèle. Un modèle que la configuration déclare est utilisé sous son nom déclaré, pour que les valeurs par défaut et les verrous de la configuration s'appliquent.
23+
20 ## Vérifier qu'un modèle tient avant de le charger24 ## Vérifier qu'un modèle tient avant de le charger
21 25
22 Choisis-le : la ligne sous la liste donne sa taille et la mémoire du serveur utilisée sur sa limite, et indique `more than is free now` quand il ne tiendrait pas à côté des modèles déjà chargés. Le serveur décharge alors les modèles au repos pour faire de la place, ou répond 503 quand il ne peut pas.26 Choisis-le : la ligne sous la liste donne sa taille et la mémoire du serveur utilisée sur sa limite, et indique `more than is free now` quand il ne tiendrait pas à côté des modèles déjà chargés. Le serveur décharge alors les modèles au repos pour faire de la place, ou répond 503 quand il ne peut pas.
modified docs/fr/reference/tui.md +2 -1
@@ -52,7 +52,7 @@ La version, la durée de fonctionnement et l'adresse du serveur ; la mémoire du
5252
5353 ## Chat (F1)
5454
55-Une conversation en flux avec un modèle de chat du serveur. La conversation est gardée par `rzb tui` et renvoyée entière à chaque message ; le cache de prompt du serveur rend cela peu coûteux. Le modèle est le premier modèle de chat chargé de `/v1/models`, sinon le premier modèle de chat listé. Après chaque réponse : tokens prompt+complétion, tokens du prompt repris du cache, tokens par seconde du premier morceau au dernier.
55+Une conversation en flux avec un modèle de chat du serveur. Chaque réponse commence par le nom du modèle sur une ligne à lui ; la réponse suit sur toute la largeur. La conversation est gardée par `rzb tui` et renvoyée entière à chaque message ; le cache de prompt du serveur rend cela peu coûteux. Le modèle est le premier modèle de chat chargé de `/v1/models`, sinon le premier modèle de chat listé. Après chaque réponse : tokens prompt+complétion, tokens du prompt repris du cache, tokens par seconde du premier morceau au dernier.
5656
5757 | Touche | Effet |
5858 | --- | --- |
@@ -91,6 +91,7 @@ L'indication donne la taille du modèle choisi et la mémoire du serveur utilis
9191 | Touche | Effet |
9292 | --- | --- |
9393 | `↑` `↓` `PgUp` `PgDn` `Home` `End` | Choisir un modèle |
94+| `Entrée` | Ouvrir l'écran Chat avec le modèle choisi, sous son nom déclaré s'il en a un, sinon sous son id Hugging Face (les modèles d'embedding sont refusés) |
9495 | `p` | Taper un id Hugging Face (`org/nom`) ; `Entrée` le télécharge avec le moteur de la compilation (progression affichée), `Échap` annule |
9596 | `d`, `Suppr` | Supprimer du disque le modèle choisi après `y` (toute autre touche le garde). Un modèle chargé est d'abord déchargé ; tant que le serveur l'utilise, rien n'est supprimé |
9697 | `r` | Relire le cache |
@@ -52,7 +52,7 @@ La version, la durée de fonctionnement et l'adresse du serveur ; la mémoire du
52 52
53 ## Chat (F1)53 ## Chat (F1)
54 54
55-Une conversation en flux avec un modèle de chat du serveur. La conversation est gardée par `rzb tui` et renvoyée entière à chaque message ; le cache de prompt du serveur rend cela peu coûteux. Le modèle est le premier modèle de chat chargé de `/v1/models`, sinon le premier modèle de chat listé. Après chaque réponse : tokens prompt+complétion, tokens du prompt repris du cache, tokens par seconde du premier morceau au dernier.55+Une conversation en flux avec un modèle de chat du serveur. Chaque réponse commence par le nom du modèle sur une ligne à lui ; la réponse suit sur toute la largeur. La conversation est gardée par `rzb tui` et renvoyée entière à chaque message ; le cache de prompt du serveur rend cela peu coûteux. Le modèle est le premier modèle de chat chargé de `/v1/models`, sinon le premier modèle de chat listé. Après chaque réponse : tokens prompt+complétion, tokens du prompt repris du cache, tokens par seconde du premier morceau au dernier.
56 56
57 | Touche | Effet |57 | Touche | Effet |
58 | --- | --- |58 | --- | --- |
@@ -91,6 +91,7 @@ L'indication donne la taille du modèle choisi et la mémoire du serveur utilis
91 | Touche | Effet |91 | Touche | Effet |
92 | --- | --- |92 | --- | --- |
93 | `↑` `↓` `PgUp` `PgDn` `Home` `End` | Choisir un modèle |93 | `↑` `↓` `PgUp` `PgDn` `Home` `End` | Choisir un modèle |
94+| `Entrée` | Ouvrir l'écran Chat avec le modèle choisi, sous son nom déclaré s'il en a un, sinon sous son id Hugging Face (les modèles d'embedding sont refusés) |
94 | `p` | Taper un id Hugging Face (`org/nom`) ; `Entrée` le télécharge avec le moteur de la compilation (progression affichée), `Échap` annule |95 | `p` | Taper un id Hugging Face (`org/nom`) ; `Entrée` le télécharge avec le moteur de la compilation (progression affichée), `Échap` annule |
95 | `d`, `Suppr` | Supprimer du disque le modèle choisi après `y` (toute autre touche le garde). Un modèle chargé est d'abord déchargé ; tant que le serveur l'utilise, rien n'est supprimé |96 | `d`, `Suppr` | Supprimer du disque le modèle choisi après `y` (toute autre touche le garde). Un modèle chargé est d'abord déchargé ; tant que le serveur l'utilise, rien n'est supprimé |
96 | `r` | Relire le cache |97 | `r` | Relire le cache |
modified docs/fr/tutorials/discuter-depuis-le-terminal.md +1 -1
@@ -65,7 +65,7 @@ Dans le premier terminal, appuie sur `F1`. L'écran Chat indique `Model: qwen`.
6565 Say hi in five words.
6666 ```
6767
68-et appuie sur `Entrée`. La première réponse prend quelques secondes, le temps que le serveur charge le modèle : tu vois `⋯ waiting for the model…`. Puis Qwen3 réfléchit avant de répondre : une ligne `⋯ thinking (… words) · Ctrl-R to show` apparaît, puis la réponse après `qwen ›`, puis une ligne atténuée comme `23+41 tokens · 85.3 tok/s`. Les mots et les chiffres exacts diffèrent sur ton Mac.
68+et appuie sur `Entrée`. La première réponse prend quelques secondes, le temps que le serveur charge le modèle : tu vois `⋯ waiting for the model…`. Puis Qwen3 réfléchit avant de répondre : une ligne `⋯ thinking (… words) · Ctrl-R to show` apparaît, puis la réponse, sous le nom du modèle `qwen`, puis une ligne atténuée comme `23+41 tokens · 85.3 tok/s`. Les mots et les chiffres exacts diffèrent sur ton Mac.
6969
7070 Nous avons discuté avec un modèle sur le GPU, à travers l'API OpenAI du serveur.
7171
@@ -65,7 +65,7 @@ Dans le premier terminal, appuie sur `F1`. L'écran Chat indique `Model: qwen`.
65 Say hi in five words.65 Say hi in five words.
66 ```66 ```
67 67
68-et appuie sur `Entrée`. La première réponse prend quelques secondes, le temps que le serveur charge le modèle : tu vois `⋯ waiting for the model…`. Puis Qwen3 réfléchit avant de répondre : une ligne `⋯ thinking (… words) · Ctrl-R to show` apparaît, puis la réponse après `qwen ›`, puis une ligne atténuée comme `23+41 tokens · 85.3 tok/s`. Les mots et les chiffres exacts diffèrent sur ton Mac.68+et appuie sur `Entrée`. La première réponse prend quelques secondes, le temps que le serveur charge le modèle : tu vois `⋯ waiting for the model…`. Puis Qwen3 réfléchit avant de répondre : une ligne `⋯ thinking (… words) · Ctrl-R to show` apparaît, puis la réponse, sous le nom du modèle `qwen`, puis une ligne atténuée comme `23+41 tokens · 85.3 tok/s`. Les mots et les chiffres exacts diffèrent sur ton Mac.
69 69
70 Nous avons discuté avec un modèle sur le GPU, à travers l'API OpenAI du serveur.70 Nous avons discuté avec un modèle sur le GPU, à travers l'API OpenAI du serveur.
71 71