Preserve parallel tool result identity and report greedy defaults
This commit is contained in:
@@ -993,9 +993,17 @@ fn render_request_prompt(request: &CreateRequest) -> Result<String, String> {
|
||||
.map(|(_, markup)| markup.as_str())
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
let output_text = outputs
|
||||
// Qwen's tool_response blocks carry no call_id. Restore
|
||||
// call order so parallel results cannot change identity.
|
||||
let output_text = calls
|
||||
.iter()
|
||||
.map(|(_, value)| format!("<tool_response>\n{value}\n</tool_response>"))
|
||||
.map(|(call_id, _)| {
|
||||
let (_, value) = outputs
|
||||
.iter()
|
||||
.find(|(id, _)| id == call_id)
|
||||
.expect("all distinct call IDs have an output");
|
||||
format!("<tool_response>\n{value}\n</tool_response>")
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
if let Some((Role::Assistant, content, thought)) = owned.last_mut() {
|
||||
@@ -1882,7 +1890,7 @@ impl ResponseTrace {
|
||||
"previous_response_id": request.previous_response_id,
|
||||
"reasoning": request.reasoning.clone().unwrap_or_else(|| json!({"effort": null, "summary": null})),
|
||||
"store": request.store.unwrap_or(true),
|
||||
"temperature": request.temperature.unwrap_or(1.0),
|
||||
"temperature": request.temperature.unwrap_or(0.0),
|
||||
"text": text,
|
||||
"tool_choice": request.tool_choice.clone().unwrap_or_else(|| json!("auto")),
|
||||
"tools": request.tools,
|
||||
@@ -2229,6 +2237,46 @@ mod tests {
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn response_reports_the_engines_greedy_default_sampling() {
|
||||
for (extra, temperature) in [(json!({}), 0.0), (json!({"temperature":0.6}), 0.6)] {
|
||||
let request = make_request(extra);
|
||||
let trace = ResponseTrace::build(
|
||||
&request,
|
||||
&[OutputItem::Text {
|
||||
deltas: vec!["OK".into()],
|
||||
}],
|
||||
usage(),
|
||||
"resp_sampling",
|
||||
1,
|
||||
2,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(trace.response["temperature"], temperature);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parallel_results_replay_by_call_identity_not_arrival_order() {
|
||||
let mut request = make_request(json!({"input":[
|
||||
{"role":"user","content":"Temperature in Oslo and Paris?"},
|
||||
{"type":"function_call","call_id":"oslo","name":"lookup","arguments":"{\"city\":\"Oslo\"}"},
|
||||
{"type":"function_call","call_id":"paris","name":"lookup","arguments":"{\"city\":\"Paris\"}"},
|
||||
{"type":"function_call_output","call_id":"oslo","output":"3°C"},
|
||||
{"type":"function_call_output","call_id":"paris","output":"17°C"}
|
||||
]}));
|
||||
let ordered = render_request_prompt(&request).unwrap();
|
||||
request.input.as_array_mut().unwrap().swap(3, 4);
|
||||
let reversed = render_request_prompt(&request).unwrap();
|
||||
assert_eq!(
|
||||
ordered, reversed,
|
||||
"arrival order must not swap city temperatures"
|
||||
);
|
||||
assert!(reversed.contains(
|
||||
"<tool_response>\n3°C\n</tool_response>\n<tool_response>\n17°C\n</tool_response>"
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn commentary_reasoning_and_tools_match_pinned_template_as_one_assistant_turn() {
|
||||
let golden: Value = serde_json::from_str(include_str!(
|
||||
|
||||
@@ -169,3 +169,12 @@ assistant turn, with their reasoning content attached. The commentary-to-call
|
||||
separator matches the pinned Qwen template, including trimming commentary's
|
||||
trailing whitespace. The sanitized `commentary-tool-prompt.json` fixture checks
|
||||
this against an independently rendered upstream template, byte for byte.
|
||||
|
||||
Parallel tool outputs are matched by `call_id` and replayed in their original
|
||||
call order. Qwen's tool-response markup has no ID field, so retaining arrival
|
||||
order would swap results when parallel tools finish in another order. A
|
||||
regression checks that ordered and reversed delivery produce identical prompts.
|
||||
|
||||
An omitted `temperature` uses the engine's greedy default (`0`), and response
|
||||
metadata reports `0`. Explicit temperature values are preserved. This reflects
|
||||
the existing engine protocol rather than changing sampling for console runs.
|
||||
|
||||
@@ -463,3 +463,11 @@ soak still remain; hosted Actions has not run.
|
||||
spacing. A sanitized golden fixture was generated using the pinned local
|
||||
template with Jinja2 3.1.6; native rendering matches it byte-for-byte. A fresh
|
||||
independent run is needed to qualify this revision.
|
||||
- Follow-up protocol checks preserve parallel result identity even when result
|
||||
delivery order differs: both histories render identically in call order.
|
||||
Response metadata now reports the actual greedy default temperature (`0`),
|
||||
confirmed in the running fork's source (`req_temperature = 0.0f`). This does
|
||||
not change sampling. The earlier console diagnostics used that greedy default.
|
||||
All 116 Rust tests, format and Clippy with warnings denied pass after these
|
||||
two checks. The full console run on the preceding revision is kept separate
|
||||
from the follow-up protocol fixture results.
|
||||
|
||||
Reference in New Issue
Block a user