feat: add cli backend request specs
This commit is contained in:
1 parent
c1e196c5e3
commit
e313c88bdb
1 file changed
+64
-2
@@ -668,12 +668,74 @@ fn backend_invocation(cli: &Cli) -> BackendInvocation {
|
||||
fn backend_request(cli: &Cli) -> BackendRequest {
|
||||
match backend_invocation(cli) {
|
||||
BackendInvocation::SummaryOnly { command } => BackendRequest::SummaryOnly { command },
|
||||
BackendInvocation::HttpCall { .. } => BackendRequest::SummaryOnly {
|
||||
command: "request-unimplemented".to_owned(),
|
||||
BackendInvocation::HttpCall { method, url, .. } if method == "GET" => {
|
||||
BackendRequest::HttpRequest {
|
||||
method,
|
||||
url,
|
||||
headers: bearer_headers(cli),
|
||||
body: None,
|
||||
}
|
||||
}
|
||||
BackendInvocation::HttpCall { method, url, .. } if method == "POST" => {
|
||||
BackendRequest::HttpRequest {
|
||||
method,
|
||||
url,
|
||||
headers: json_headers(cli),
|
||||
body: Some(bench_request_body(cli)),
|
||||
}
|
||||
}
|
||||
BackendInvocation::HttpCall {
|
||||
method, url, body, ..
|
||||
} => BackendRequest::HttpRequest {
|
||||
method,
|
||||
url,
|
||||
headers: bearer_headers(cli),
|
||||
body,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn bearer_headers(cli: &Cli) -> Vec<(String, String)> {
|
||||
cli.api_key
|
||||
.as_ref()
|
||||
.map(|api_key| vec![("authorization".to_owned(), format!("Bearer {}", api_key))])
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn json_headers(cli: &Cli) -> Vec<(String, String)> {
|
||||
let mut headers = bearer_headers(cli);
|
||||
headers.push(("content-type".to_owned(), "application/json".to_owned()));
|
||||
headers
|
||||
}
|
||||
|
||||
fn bench_request_body(cli: &Cli) -> String {
|
||||
match &cli.command {
|
||||
Commands::Bench(bench) => match &bench.command {
|
||||
BenchSubcommand::Throughput(args) => serde_json::json!({
|
||||
"model": args.model,
|
||||
"stream": false,
|
||||
"temperature": 0.0,
|
||||
"top_p": 1.0,
|
||||
"max_completion_tokens": args.completion_tokens,
|
||||
"messages": [{
|
||||
"role": "user",
|
||||
"content": benchmark_prompt(args.prompt_tokens),
|
||||
}],
|
||||
})
|
||||
.to_string(),
|
||||
_ => "{}".to_owned(),
|
||||
},
|
||||
_ => "{}".to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
fn benchmark_prompt(prompt_tokens: u32) -> String {
|
||||
std::iter::repeat("benchmark token")
|
||||
.take((prompt_tokens / 2) as usize)
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ")
|
||||
}
|
||||
|
||||
fn command_summary(command: &Commands) -> String {
|
||||
match command {
|
||||
Commands::Status => "status".to_owned(),
|
||||
|
||||
Reference in new issue
Block a user