Skip to main content

error_envelope_value

Function error_envelope_value 

Source
pub fn error_envelope_value(value: &Value) -> Option<ErrorEnvelope>
Expand description

error_envelope of a body already parsed as JSON, for a caller that parsed it to tell an error from its other frames (an NDJSON line, an SSE event’s data). It recognises the same shapes, listed on error_envelope.

use allama_http::error_envelope_value;
use serde_json::json;

let line = json!({"error": "model 'llama9' not found"});
let envelope = error_envelope_value(&line).unwrap();
assert_eq!(envelope.message.as_deref(), Some("model 'llama9' not found"));
assert!(error_envelope_value(&json!({"message": {"role": "assistant"}})).is_none());