mirror of
https://github.com/katanemo/plano.git
synced 2026-06-17 15:25:17 +02:00
fixed serialization issues with enums on response
This commit is contained in:
parent
2fa983d50d
commit
0b41496c45
2 changed files with 14 additions and 1 deletions
|
|
@ -104,6 +104,19 @@ impl Iterator for ProviderStreamResponseIter {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to serialize only the inner struct, not the enum wrapper.
|
||||
// This avoids the problem where serde serializes the enum variant as a wrapper object in JSON.
|
||||
impl ProviderResponseType {
|
||||
/// Serialize the response as JSON bytes, omitting the enum wrapper.
|
||||
pub fn as_json_bytes(&self) -> Result<Vec<u8>, serde_json::Error> {
|
||||
match self {
|
||||
ProviderResponseType::ChatCompletionsResponse(resp) => serde_json::to_vec(resp),
|
||||
ProviderResponseType::MessagesResponse(resp) => serde_json::to_vec(resp),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ProviderResponse: Send + Sync {
|
||||
/// Get usage information if available - returns dynamic trait object
|
||||
fn usage(&self) -> Option<&dyn TokenUsage>;
|
||||
|
|
|
|||
|
|
@ -681,7 +681,7 @@ impl HttpContext for StreamContext {
|
|||
match (supported_api, self.resolved_api.as_ref()) {
|
||||
(Some(supported_api), Some(_)) => {
|
||||
match ProviderResponseType::try_from((&body[..], supported_api, &provider_id)) {
|
||||
Ok(response) => match serde_json::to_vec(&response) {
|
||||
Ok(response) => match response.as_json_bytes() {
|
||||
Ok(bytes) => {
|
||||
self.set_http_response_body(0, bytes.len(), &bytes);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue