Commit 94d9ea3
committed
fix(usage): Normalize None token detail objects on Usage initialization
Extends #2034 to handle providers that return None for entire
input_tokens_details and output_tokens_details objects (not just the
fields within them). This affects non-streaming responses.
Related to #1179 (which fixed the streaming case).
Some providers like llama-stack return null for these optional fields
in their JSON responses. The OpenAI SDK maps these to None in Python.
Previously, passing None to the Usage constructor would fail Pydantic
validation before __post_init__ could normalize them.
This PR uses Pydantic's BeforeValidator to normalize None values at
the field level, before Pydantic's type validation runs.
Signed-off-by: Adrian Cole <[email protected]>1 parent 0d2d771 commit 94d9ea3
File tree
3 files changed
+38
-19
lines changed- src/agents
- models
- tests
3 files changed
+38
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
| 105 | + | |
| 106 | + | |
117 | 107 | | |
118 | 108 | | |
119 | 109 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
7 | 19 | | |
8 | 20 | | |
9 | 21 | | |
| |||
32 | 44 | | |
33 | 45 | | |
34 | 46 | | |
35 | | - | |
36 | | - | |
37 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
38 | 50 | | |
39 | 51 | | |
40 | 52 | | |
41 | 53 | | |
42 | | - | |
43 | | - | |
44 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
45 | 57 | | |
46 | 58 | | |
47 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
273 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
274 | 291 | | |
275 | 292 | | |
276 | 293 | | |
| |||
0 commit comments