| Crates.io | batch-mode-batch-schema |
| lib.rs | batch-mode-batch-schema |
| version | 0.2.2 |
| created_at | 2025-02-27 05:26:54.655438+00 |
| updated_at | 2025-07-13 10:31:24.692773+00 |
| description | Defines the schema and structures for batch processing, including batch choices, message roles, error handling, and token management, with support for JSON deserialization and validation. |
| homepage | |
| repository | https://github.com/klebs6/klebs-general |
| max_upload_size | |
| id | 1571333 |
| size | 206,537 |
The batch-mode-batch-schema crate provides the data structures and schemas necessary for representing and handling batch-related data in batch processing workflows. It includes structures for batch choices, error responses, token details, and other key elements that are essential for processing batches in a consistent way. The crate also offers the ability to deserialize JSON responses, ensuring the integrity of the batch data and handling any errors that may arise.
use batch_mode_batch_schema::{BatchChoice, FinishReason, BatchMessage};
use serde_json::json;
let json = r#"{
"index": 0,
"message": {
"role": "assistant",
"content": "This is the assistant's response.",
"refusal": null
},
"logprobs": null,
"finish_reason": "stop"
}"#;
let choice: BatchChoice = serde_json::from_str(json).unwrap();
println!("Batch Choice: {:?}", choice);
use batch_mode_batch_schema::MessageRole;
use serde_json::json;
let json = r#""assistant""#;
let role: MessageRole = serde_json::from_str(json).unwrap();
println!("Message Role: {:?}", role);
use batch_mode_batch_schema::{BatchErrorResponseBody, BatchErrorDetails};
let error_json = r#"{
"error": {
"message": "Invalid API key",
"type": "authentication_error",
"param": null,
"code": "invalid_api_key"
}
}"#;
let error_body: BatchErrorResponseBody = serde_json::from_str(error_json).unwrap();
println!("Error: {:?}", error_body.error());
use batch_mode_batch_schema::BatchTokenDetails;
use serde_json::json;
let token_json = r#"{
"cached_tokens": 100,
"audio_tokens": 50,
"reasoning_tokens": 25,
"accepted_prediction_tokens": 20,
"rejected_prediction_tokens": 5
}"#;
let token_details: BatchTokenDetails = serde_json::from_str(token_json).unwrap();
println!("Total tokens: {}", token_details.total_tokens());
This crate utilizes the error-tree library for structured error handling, including errors for invalid content, missing required fields, and deserialization issues. Some of the key error types are:
ContentParseError: Indicates errors while parsing batch content.BatchReconciliationError: Indicates errors in the reconciliation process.JsonParseError: Indicates issues during JSON parsing.This crate is licensed under the MIT License. See LICENSE for details.