BatchJobManager
The BatchJobManager
is the core class for programmatically generating large batches of requests from templates or lists of inputs. It's designed for scalability and is the recommended tool for creating thousands of similar API calls efficiently.
Manages the creation of batch job request files.
Provides methods to generate request line-by-line JSON files based on prompt templates, common request configurations, and input instances.
Source code in openbatch/manager.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
add(custom_id, request, save_file_path)
staticmethod
Creates a single batch request object and appends it to the specified file.
This is the core method for generating the JSONL file content. It determines the appropriate API strategy based on the request type and serializes the full request structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
custom_id
|
str
|
A unique identifier for this specific request in the batch. |
required |
request
|
Union[ResponsesRequest, ChatCompletionsRequest, EmbeddingsRequest]
|
The API-specific request configuration object. |
required |
save_file_path
|
Union[str, Path]
|
The path to the batch job request file (JSONL format). |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the request type is unsupported or if a required field
(like |
Source code in openbatch/manager.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
add_embedding_requests(inputs, common_request, save_file_path)
Adds multiple embedding request instances to a batch request file.
This method iterates over embedding input instances, sets the input text(s), merges instance-specific options, and adds the request to the batch file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs
|
Iterable[EmbeddingInputInstance]
|
An iterable of instances containing the text(s) to embed and instance options. |
required |
common_request
|
EmbeddingsRequest
|
The base embedding request configuration. |
required |
save_file_path
|
Union[str, Path]
|
The path to the batch job request file (JSONL format). |
required |
Source code in openbatch/manager.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
add_templated_instances(prompt, common_request, input_instances, save_file_path)
Adds multiple templated input instances to a batch request file.
This method iterates over input instances, applies variable mapping to the prompt, merges instance-specific options, and adds the resulting request to the batch file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
Union[PromptTemplate, ReusablePrompt]
|
The prompt definition, either an in-memory template or a reference to a reusable prompt. |
required |
common_request
|
Union[ResponsesRequest, ChatCompletionsRequest]
|
The base request configuration (e.g., model, temperature). Must be a TextGenerationRequest subclass (ResponsesRequest or ChatCompletionsRequest). |
required |
input_instances
|
Iterable[PromptTemplateInputInstance]
|
An iterable of instances containing prompt variable mappings and instance options. |
required |
save_file_path
|
str | Path
|
The path to the batch job request file (JSONL format). |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Source code in openbatch/manager.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|