systemprompt_models/ai/
response.rs1use super::tools::{CallToolResult, ToolCall};
2use serde::{Deserialize, Serialize};
3use uuid::Uuid;
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct AiResponse {
7 pub request_id: Uuid,
8 pub content: String,
9 pub provider: String,
10 pub model: String,
11 pub tokens_used: Option<u32>,
12 pub input_tokens: Option<u32>,
13 pub output_tokens: Option<u32>,
14 pub latency_ms: u64,
15 pub tool_calls: Vec<ToolCall>,
16 pub tool_results: Vec<CallToolResult>,
17 pub finish_reason: Option<String>,
18 pub cache_hit: bool,
19 pub cache_read_tokens: Option<u32>,
20 pub cache_creation_tokens: Option<u32>,
21 pub is_streaming: bool,
22}
23
24impl Default for AiResponse {
25 fn default() -> Self {
26 Self {
27 request_id: Uuid::nil(),
28 content: String::new(),
29 provider: String::new(),
30 model: String::new(),
31 tokens_used: None,
32 input_tokens: None,
33 output_tokens: None,
34 latency_ms: 0,
35 tool_calls: Vec::new(),
36 tool_results: Vec::new(),
37 finish_reason: None,
38 cache_hit: false,
39 cache_read_tokens: None,
40 cache_creation_tokens: None,
41 is_streaming: false,
42 }
43 }
44}
45
46impl AiResponse {
47 pub fn new(request_id: Uuid, content: String, provider: String, model: String) -> Self {
48 Self {
49 request_id,
50 content,
51 provider,
52 model,
53 ..Default::default()
54 }
55 }
56
57 pub const fn with_tokens(mut self, tokens_used: u32) -> Self {
58 self.tokens_used = Some(tokens_used);
59 self
60 }
61
62 pub const fn with_latency(mut self, latency_ms: u64) -> Self {
63 self.latency_ms = latency_ms;
64 self
65 }
66
67 pub fn with_tool_calls(mut self, tool_calls: Vec<ToolCall>) -> Self {
68 self.tool_calls = tool_calls;
69 self
70 }
71
72 pub fn with_tool_results(mut self, tool_results: Vec<CallToolResult>) -> Self {
73 self.tool_results = tool_results;
74 self
75 }
76
77 pub fn has_tool_calls(&self) -> bool {
78 !self.tool_calls.is_empty()
79 }
80
81 pub fn has_tool_results(&self) -> bool {
82 !self.tool_results.is_empty()
83 }
84}
85
86#[derive(Debug, Clone, Serialize, Deserialize)]
87pub struct WebSource {
88 pub title: String,
89 pub uri: String,
90 pub relevance: f32,
91}
92
93#[derive(Debug, Clone, Serialize, Deserialize)]
94pub struct UrlMetadata {
95 pub retrieved_url: String,
96 pub url_retrieval_status: String,
97}
98
99#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct SearchGroundedResponse {
101 pub content: String,
102 pub sources: Vec<WebSource>,
103 pub confidence_scores: Vec<f32>,
104 pub web_search_queries: Vec<String>,
105 pub url_context_metadata: Option<Vec<UrlMetadata>>,
106 pub tokens_used: Option<u32>,
107 pub latency_ms: u64,
108 pub finish_reason: Option<String>,
109 pub safety_ratings: Option<Vec<serde_json::Value>>,
110}