Commit cd4448c
Ritiz Tambi
Fix Choice object deserialization in Trajectory validator
When trajectories are serialized and sent to the backend, Choice objects
become dicts with structure {'message': {...}, 'logprobs': {...}, ...}.
After deserialization, Pydantic doesn't reconstruct them back to Choice
objects, causing KeyError: 'role' in tokenize.py.
This adds a field_validator that detects serialized Choice dicts
(by checking for 'message' and 'finish_reason' keys) and reconstructs
them back into proper Choice objects using Choice.model_validate().1 parent f2415e5 commit cd4448c
1 file changed
+22
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
49 | 71 | | |
50 | 72 | | |
51 | 73 | | |
| |||
0 commit comments