Commit 28e3d0a
authored
Parse ints from floats in openai generic (#1746)
The SambaNova provider returns a float for the `"completed"` field of
the Completions generic API. This PR makes the Completions parser more
flexible, accepting both ints and floats, but always returning ints.
I have tested this locally - SambaNova and OpenAI requests now parse
correctly. I didn't check in the testing code, because we don't
necessarily want to mention lots of providers in our test suite.
<!-- ELLIPSIS_HIDDEN -->
----
> [!IMPORTANT]
> Enhance `ChatCompletionGeneric` to accept both int and float for
`created` field, ensuring consistent int return using
`deserialize_float_to_u32`.
>
> - **Behavior**:
> - `ChatCompletionGeneric` now accepts both `int` and `float` for
`created` field, always returning `int`.
> - Adds `deserialize_float_to_u32` function to handle deserialization
of `created` field.
> - **Code**:
> - Adds `deserialize_float_to_u32` function in `types.rs` to convert
floats to integers using `floor()`.
> - Updates `ChatCompletionGeneric` struct to use
`deserialize_float_to_u32` for `created` field.
>
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup>
for 0d334bd. It will automatically
update as commits are pushed.</sup>
<!-- ELLIPSIS_HIDDEN -->1 parent b0e79a2 commit 28e3d0a
1 file changed
Lines changed: 20 additions & 0 deletions
Lines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| |||
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
29 | 49 | | |
30 | 50 | | |
31 | 51 | | |
| |||
0 commit comments