Skip to main content

funera_orchestrate/
response.rs

1use serde_json::Value as JsonValue;
2
3#[derive(Debug, Clone)]
4pub struct ChatResponse {
5    pub content: String,
6    pub tool_calls: Vec<ToolCallInfo>,
7    pub iterations: usize,
8    pub finish_reason: Option<String>,
9}
10
11#[derive(Debug, Clone)]
12pub struct ToolCallInfo {
13    pub name: String,
14    pub args: JsonValue,
15    pub result: Result<String, String>,
16}
17
18#[cfg(test)]
19mod tests {
20    use super::*;
21
22    #[test]
23    fn chat_response_construct() {
24        let resp = ChatResponse {
25            content: "Hello".into(),
26            tool_calls: vec![],
27            iterations: 1,
28            finish_reason: Some("stop".into()),
29        };
30        assert_eq!(resp.content, "Hello");
31        assert_eq!(resp.iterations, 1);
32        assert_eq!(resp.finish_reason, Some("stop".into()));
33    }
34
35    #[test]
36    fn tool_call_info_ok() {
37        let info = ToolCallInfo {
38            name: "get_weather".into(),
39            args: serde_json::json!({"city": "Tokyo"}),
40            result: Ok("22°C".into()),
41        };
42        assert_eq!(info.name, "get_weather");
43        assert!(info.result.is_ok());
44    }
45
46    #[test]
47    fn tool_call_info_err() {
48        let info = ToolCallInfo {
49            name: "bad_tool".into(),
50            args: serde_json::json!({}),
51            result: Err("timeout".into()),
52        };
53        assert!(info.result.is_err());
54    }
55}