agent_block_testkit/shapes/
openai.rs1use serde_json::{json, Value};
9use std::sync::atomic::{AtomicUsize, Ordering};
10
11static RESPONSE_SEQ: AtomicUsize = AtomicUsize::new(0);
12
13fn next_id(prefix: &str) -> String {
14 format!(
15 "{prefix}-{}",
16 RESPONSE_SEQ.fetch_add(1, Ordering::Relaxed) + 1
17 )
18}
19
20pub fn tool_call(id: &str, name: &str, arguments_json: &str) -> Value {
22 json!({
23 "id": id,
24 "type": "function",
25 "function": { "name": name, "arguments": arguments_json }
26 })
27}
28
29pub fn tool_call_object_args_no_id(name: &str, arguments: Value) -> Value {
35 json!({
36 "type": "function",
37 "function": { "name": name, "arguments": arguments }
38 })
39}
40
41pub fn tool_call_malformed_args(id: &str, name: &str) -> Value {
45 json!({
46 "id": id,
47 "type": "function",
48 "function": { "name": name, "arguments": "{not json" }
49 })
50}
51
52pub fn text_response(text: &str) -> Value {
54 json!({
55 "id": next_id("chatcmpl-testkit"),
56 "object": "chat.completion",
57 "choices": [{
58 "index": 0,
59 "message": { "role": "assistant", "content": text },
60 "finish_reason": "stop"
61 }],
62 "usage": { "prompt_tokens": 10, "completion_tokens": 10, "total_tokens": 20 }
63 })
64}
65
66pub fn tool_calls_response(calls: Vec<Value>) -> Value {
68 json!({
69 "id": next_id("chatcmpl-testkit"),
70 "object": "chat.completion",
71 "choices": [{
72 "index": 0,
73 "message": { "role": "assistant", "content": null, "tool_calls": calls },
74 "finish_reason": "tool_calls"
75 }],
76 "usage": { "prompt_tokens": 10, "completion_tokens": 10, "total_tokens": 20 }
77 })
78}