language-model-batch-workflow-derive
This crate provides a procedural macro #[derive(LanguageModelBatchWorkflow)] for structures that manage automated batch tasks involving language model requests. By annotating certain fields with attributes like #[batch_client] and #[batch_workspace], you can generate consistent, boilerplate-free implementations of core traits from the batch-mode-batch-workflow ecosystem.
Overview
When deriving LanguageModelBatchWorkflow, the macro enforces the presence of several annotated fields:
#[batch_client]– Must be anArc<OpenAIClientHandle>orArc<dyn LanguageModelClientInterface<E>>, whereEis your custom error type orOpenAIClientError.#[batch_workspace]– Must be anArc<BatchWorkspace>orArc<dyn FullBatchWorkspaceInterface<BatchWorkspaceError>>.#[expected_content_type]– Must be anExpectedContentType.#[model_type]– Must be aLanguageModelType.#[batch_error_type(...)]– Declares the user’s chosen custom error type (e.g.,MyErr) at the struct level.
Additionally, you may supply optional attributes to customize output/error processing:
#[custom_process_batch_output_fn]– ABatchWorkflowProcessOutputFileFnthat defines how to handle successful batch results.#[custom_process_batch_error_fn]– ABatchWorkflowProcessErrorFileFnthat defines how to handle batch errors.
Key Traits Implemented
-
FinishProcessingUncompletedBatches
Provides logic to finalize any partially processed batch work using the annotated workspace and client fields. -
ProcessBatchRequests
Defines how to dispatch new requests and handle output/error files, with optional custom overrides for post-processing. -
LanguageModelBatchWorkflow<Error>
Supplies theplant_seed_and_waitmethod, which internally invokes your primary batch workflow logic asynchronously. -
ComputeLanguageModelRequests(to be implemented by you)
Although not generated automatically, you provide the method that forms your language model queries (compute_language_model_requests). The macro integrates this method into the larger workflow. -
SendandSync
The derived struct is declared thread-safe to allow concurrency in batch-based tasks.
Example
use LanguageModelBatchWorkflow;
use *;
use *;
use Arc;
/// Define your own error type (must implement `From` conversions for relevant errors).
;
// Satisfy all required conversions, for example:
// ...
In this example, the macro checks that each annotated field is of a valid type, then automatically implements batch workflow traits. You only need to supply your custom logic for building language model requests.
Trybuild Tests
This crate uses trybuild to verify correctness by compiling pass/fail examples:
fail_missing_batch_client.rs
Ensures a compile error occurs if#[batch_client]is absent.fail_missing_batch_workspace.rs
Checks that#[batch_workspace]is mandatory.fail_missing_error_type.rs
Ensures the macro fails when#[batch_error_type(...)]is not provided.pass_valid_struct.rs
Demonstrates a proper struct that compiles without error.