use serde_json::{json, Value};
use std::sync::atomic::{AtomicUsize, Ordering};
static RESPONSE_SEQ: AtomicUsize = AtomicUsize::new(0);
fn next_id(prefix: &str) -> String {
format!(
"{prefix}-{}",
RESPONSE_SEQ.fetch_add(1, Ordering::Relaxed) + 1
)
}
pub fn tool_call(id: &str, name: &str, arguments_json: &str) -> Value {
json!({
"id": id,
"type": "function",
"function": { "name": name, "arguments": arguments_json }
})
}
pub fn tool_call_object_args_no_id(name: &str, arguments: Value) -> Value {
json!({
"type": "function",
"function": { "name": name, "arguments": arguments }
})
}
pub fn tool_call_malformed_args(id: &str, name: &str) -> Value {
json!({
"id": id,
"type": "function",
"function": { "name": name, "arguments": "{not json" }
})
}
pub fn text_response(text: &str) -> Value {
json!({
"id": next_id("chatcmpl-testkit"),
"object": "chat.completion",
"choices": [{
"index": 0,
"message": { "role": "assistant", "content": text },
"finish_reason": "stop"
}],
"usage": { "prompt_tokens": 10, "completion_tokens": 10, "total_tokens": 20 }
})
}
pub fn tool_calls_response(calls: Vec<Value>) -> Value {
json!({
"id": next_id("chatcmpl-testkit"),
"object": "chat.completion",
"choices": [{
"index": 0,
"message": { "role": "assistant", "content": null, "tool_calls": calls },
"finish_reason": "tool_calls"
}],
"usage": { "prompt_tokens": 10, "completion_tokens": 10, "total_tokens": 20 }
})
}