agentix/raw/openai/
response.rs1use serde::Deserialize;
2
3#[derive(Debug, Deserialize)]
4pub struct StreamChunk {
5 pub choices: Vec<ChunkChoice>,
6 #[serde(default)]
7 pub usage: Option<Usage>,
8}
9
10#[derive(Debug, Deserialize)]
11pub struct ChunkChoice {
12 pub delta: Delta,
13 pub finish_reason: Option<String>,
14}
15
16#[derive(Debug, Deserialize)]
17pub struct Delta {
18 #[serde(default)]
19 pub content: Option<String>,
20 #[serde(default)]
21 pub reasoning_content: Option<String>,
22 #[serde(default)]
23 pub tool_calls: Option<Vec<DeltaToolCall>>,
24}
25
26#[derive(Debug, Deserialize)]
27pub struct DeltaToolCall {
28 pub index: u32,
29 #[serde(default)]
30 pub id: Option<String>,
31 #[serde(default)]
32 pub function: Option<DeltaFunctionCall>,
33}
34
35#[derive(Debug, Deserialize)]
36pub struct DeltaFunctionCall {
37 #[serde(default)]
38 pub name: Option<String>,
39 #[serde(default)]
40 pub arguments: Option<String>,
41}
42
43#[derive(Debug, Deserialize)]
44pub struct Usage {
45 pub prompt_tokens: u32,
46 pub completion_tokens: u32,
47 pub total_tokens: u32,
48}
49
50#[derive(Debug, Deserialize)]
53pub struct CompleteResponse {
54 pub choices: Vec<CompleteChoice>,
55 #[serde(default)]
56 pub usage: Option<Usage>,
57}
58
59#[derive(Debug, Deserialize)]
60pub struct CompleteChoice {
61 pub message: CompleteMessage,
62}
63
64#[derive(Debug, Deserialize)]
65pub struct CompleteMessage {
66 #[serde(default)]
67 pub content: Option<String>,
68 #[serde(default)]
69 pub reasoning_content: Option<String>,
70 #[serde(default)]
71 pub tool_calls: Option<Vec<CompleteToolCall>>,
72}
73
74#[derive(Debug, Deserialize)]
75pub struct CompleteToolCall {
76 pub id: String,
77 pub function: CompleteFunctionCall,
78}
79
80#[derive(Debug, Deserialize)]
81pub struct CompleteFunctionCall {
82 pub name: String,
83 pub arguments: String,
84}
85
86impl From<Usage> for crate::types::UsageStats {
87 fn from(u: Usage) -> Self {
88 Self {
89 prompt_tokens: u.prompt_tokens as usize,
90 completion_tokens: u.completion_tokens as usize,
91 total_tokens: u.total_tokens as usize,
92 }
93 }
94}