feat: add cli backend response previews
This commit is contained in:
1 parent
bf985ea9ea
commit
71274e26ce
1 file changed
+28
-10
@@ -747,23 +747,41 @@ fn backend_request(cli: &Cli) -> BackendRequest {
|
||||
}
|
||||
}
|
||||
|
||||
fn backend_response_preview(cli: &Cli, _status_code: u16, _body: &str) -> BackendResponsePreview {
|
||||
fn backend_response_preview(cli: &Cli, _status_code: u16, body: &str) -> BackendResponsePreview {
|
||||
match &cli.command {
|
||||
Commands::Status => BackendResponsePreview::SummaryOnly {
|
||||
command: "response-unimplemented".to_owned(),
|
||||
},
|
||||
Commands::Models(models) => match &models.command {
|
||||
ModelsSubcommand::List => BackendResponsePreview::SummaryOnly {
|
||||
Commands::Status => serde_json::from_str::<CliHealthResponse>(body)
|
||||
.map(|health| BackendResponsePreview::Health {
|
||||
status: health.status,
|
||||
model_loaded: health.model_loaded,
|
||||
model_id: health.model_id,
|
||||
uptime_secs: health.uptime_secs,
|
||||
})
|
||||
.unwrap_or_else(|_| BackendResponsePreview::SummaryOnly {
|
||||
command: "response-unimplemented".to_owned(),
|
||||
},
|
||||
}),
|
||||
Commands::Models(models) => match &models.command {
|
||||
ModelsSubcommand::List => serde_json::from_str::<CliModelList>(body)
|
||||
.map(|models| BackendResponsePreview::Models {
|
||||
count: models.data.len(),
|
||||
ids: models.data.into_iter().map(|model| model.id).collect(),
|
||||
})
|
||||
.unwrap_or_else(|_| BackendResponsePreview::SummaryOnly {
|
||||
command: "response-unimplemented".to_owned(),
|
||||
}),
|
||||
_ => BackendResponsePreview::SummaryOnly {
|
||||
command: command_summary(&cli.command),
|
||||
},
|
||||
},
|
||||
Commands::Bench(bench) => match &bench.command {
|
||||
BenchSubcommand::Throughput(_) => BackendResponsePreview::SummaryOnly {
|
||||
command: "response-unimplemented".to_owned(),
|
||||
},
|
||||
BenchSubcommand::Throughput(args) => serde_json::from_str::<CliBenchResponse>(body)
|
||||
.map(|response| BackendResponsePreview::Throughput {
|
||||
model: args.model.clone(),
|
||||
total_tokens: response.usage.total_tokens,
|
||||
tokens_per_second: response.usage.tokens_per_second,
|
||||
})
|
||||
.unwrap_or_else(|_| BackendResponsePreview::SummaryOnly {
|
||||
command: "response-unimplemented".to_owned(),
|
||||
}),
|
||||
_ => BackendResponsePreview::SummaryOnly {
|
||||
command: command_summary(&cli.command),
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user