Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ harness-gateway-client = { path = "crates/harness-gateway-client" }
# The chat-completions client, from its own repository, pinned by commit.
# `version` beside `git` keeps cargo-deny's wildcard check quiet. The
# `harness-gateway-client` adapter converts its types to the Engine's.
gateway-client = { version = "0.1.0", git = "https://github.com/cppalliance/gateway-client", rev = "91e4685c4bdbd70cc89a10fa791e1a37641f728f" }
gateway-client = { version = "0.1.0", git = "https://github.com/cppalliance/gateway-client", rev = "46ead80f5f2f16677a6a4d6530d9e37271bebfff" }
runvil-lua = { path = "crates/runvil-internal/lua" }
runvil-markdown = { path = "crates/runvil-internal/markdown" }
runvil-model-client = { path = "crates/runvil-internal/model-client" }
Expand Down
2 changes: 1 addition & 1 deletion crates/harness-gateway-client/src/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl InferenceBroker for GatewayBroker {
.complete(&messages, tools, &options, on_delta)
.await
.map_err(into_error)?;
into_engine_reply(&reply).map(Box::new)
into_engine_reply(reply).map(Box::new)
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/harness-gateway-client/src/convert-tests-reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async fn round_of(payloads: &[Value]) -> Completion {
.complete(&[Message::user("hi")], None, &openai_options(), |_| {})
.await
.expect("a complete turn finishes");
into_engine_reply(&reply).expect("the reply converts")
into_engine_reply(reply).expect("the reply converts")
}

fn text_and_stop() -> [Value; 2] {
Expand Down Expand Up @@ -79,7 +79,7 @@ async fn streamed_text_usage_timings_and_client_timing_accumulate() {
})
.await
.expect("a streamed text turn completes");
let completion = into_engine_reply(&reply).expect("the reply converts");
let completion = into_engine_reply(reply).expect("the reply converts");
assert_eq!(
completion.result(),
&CompletionResult::Text("Hello!".to_owned())
Expand Down
45 changes: 25 additions & 20 deletions crates/harness-gateway-client/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,38 +234,46 @@ fn parse_section<T: DeserializeOwned>(

/// Builds the Engine's `Completion` from a client `Reply`, through the
/// Engine's own constructors, so the Engine's checks run on every turn.
pub(crate) fn into_engine_reply(reply: &Reply) -> Result<Completion, Error> {
let result = match reply.outcome() {
Outcome::Text(text) => CompletionResult::Text(text.clone()),
pub(crate) fn into_engine_reply(reply: Reply) -> Result<Completion, Error> {
let Reply {
outcome,
model,
finish_reason,
reasoning,
usage,
timing,
diagnostics,
request,
response,
} = reply;
let result = match outcome {
Outcome::Text(text) => CompletionResult::Text(text),
Outcome::ToolCalls(calls) => {
let mut parts = Vec::with_capacity(calls.len());
for call in calls {
let arguments = Value::Object(call.arguments().clone());
parts.push(
ToolCall::from_parts(call.id(), call.name(), arguments).map_err(decoded)?,
);
let arguments = Value::Object(call.arguments);
parts.push(ToolCall::from_parts(call.id, call.name, arguments).map_err(decoded)?);
}
CompletionResult::ToolCalls(parts)
}
};
let mut completion = Completion::from_result(result, reply.model()).map_err(decoded)?;
let mut completion = Completion::from_result(result, model).map_err(decoded)?;

// The model and usage diagnostics came from the client, in today's
// order. Bound and control-escape them before the llama.cpp and vLLM
// sections come next.
let mut diagnostics: Vec<String> = reply
.diagnostics()
let mut diagnostics: Vec<String> = diagnostics
.iter()
.map(|line| bound_diagnostic(line))
.collect();
let llama = parse_section::<LlamaTimings>(reply.response(), "timings", &mut diagnostics);
let vllm = parse_section::<VllmMetrics>(reply.response(), "metrics", &mut diagnostics);
let usage = reply.usage().map(|u| {
let llama = parse_section::<LlamaTimings>(&response, "timings", &mut diagnostics);
let vllm = parse_section::<VllmMetrics>(&response, "metrics", &mut diagnostics);
let usage = usage.map(|u| {
Usage::new(u.prompt_tokens, u.completion_tokens, u.total_tokens)
.with_cached_tokens(u.cached_tokens)
.with_reasoning_tokens(u.reasoning_tokens)
});
let timing = reply.timing().map(|t| {
let timing = timing.map(|t| {
ClientTiming::new(t.e2e_ms)
.with_ttft_ms(t.ttft_ms)
.with_mean_itl_ms(t.mean_itl_ms)
Expand All @@ -278,19 +286,16 @@ pub(crate) fn into_engine_reply(reply: &Reply) -> Result<Completion, Error> {
.with_client(timing);

completion = completion.with_metadata_diagnostics(diagnostics);
if let Some(reason) = reply.finish_reason() {
if let Some(reason) = finish_reason {
completion = completion.with_finish_reason(reason);
}
if let Some(reasoning) = reply.reasoning() {
if let Some(reasoning) = reasoning {
completion = completion.with_reasoning_content(reasoning);
}
if measured {
completion = completion.with_metrics(metrics);
}
Ok(completion.with_raw(RawExchange::new(
reply.request().clone(),
reply.response().clone(),
)))
Ok(completion.with_raw(RawExchange::new(request, response)))
}

#[cfg(test)]
Expand Down
Loading