Runtimes
AsyncRuntime
Bases: Runtime
Async version of runtime that uses asyncio to process batch of records.
Source code in adala/runtimes/base.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
batch_to_batch(batch, input_template, instructions_template, response_model, extra_fields=None, field_schema=None, instructions_first=True, output_template=None)
abstractmethod
async
Processes a record.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch |
InternalDataFrame
|
The batch to process. |
required |
input_template |
str
|
The input template. |
required |
instructions_template |
str
|
The instructions template. |
required |
response_model |
Optional[Type[BaseModel]]
|
The response model to use for processing records. |
required |
extra_fields |
Optional[Dict[str, str]]
|
Extra fields to use in the templates. Defaults to None. |
None
|
field_schema |
Optional[Dict]
|
Field JSON schema to use in the templates. Defaults to all fields are strings, i.e. analogous to {"field_n": {"type": "string"}}. |
None
|
instructions_first |
bool
|
Whether to put instructions first. Defaults to True. |
True
|
output_template |
str
|
The output template. Deprecated. |
None
|
Returns:
Name | Type | Description |
---|---|---|
InternalDataFrame |
InternalDataFrame
|
The processed batch. |
Source code in adala/runtimes/base.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
record_to_record(record, input_template, instructions_template, output_template, extra_fields=None, field_schema=None, instructions_first=True, response_model=None)
abstractmethod
async
Processes a record.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record |
Dict[str, str]
|
The record to process. |
required |
input_template |
str
|
The input template. |
required |
instructions_template |
str
|
The instructions template. |
required |
output_template |
str
|
The output template. |
required |
extra_fields |
Optional[Dict[str, str]]
|
Extra fields to use in the templates. Defaults to None. |
None
|
field_schema |
Optional[Dict]
|
Field JSON schema to use in the templates. Defaults to all fields are strings, i.e. analogous to {"field_n": {"type": "string"}}. |
None
|
instructions_first |
bool
|
Whether to put instructions first. Defaults to True. |
True
|
response_model |
Optional[Type[BaseModel]]
|
The response model to use for processing records. Defaults to None.
If set, the response will be generated according to this model and |
None
|
Returns:
Type | Description |
---|---|
Dict[str, str]
|
Dict[str, str]: The processed record. |
Source code in adala/runtimes/base.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
Runtime
Bases: BaseModelInRegistry
Base class representing a generic runtime environment.
Attributes:
Name | Type | Description |
---|---|---|
verbose |
bool
|
Flag indicating if runtime outputs should be verbose. Defaults to False. |
batch_size |
Optional[int]
|
The batch size to use for processing records. Defaults to None. |
concurrency |
Optional[int]
|
The number of parallel processes to use for processing records. Defaults to 1. Note that when parallel processing is used, the memory footprint will be doubled compared to sequential processing. |
response_model |
Optional[Type[BaseModel]]
|
The response model to use for processing records. Defaults to None.
If set, the response will be generated according to this model and |
Source code in adala/runtimes/base.py
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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
batch_to_batch(batch, input_template, instructions_template, response_model, extra_fields=None, field_schema=None, instructions_first=True, output_template=None)
Processes a record.
It supports parallel processing of the batch:
- when the concurrency
is set to -1 (using all available CPUs),
- when the concurrency
is set to 1 (sequential processing),
- when the concurrency
is set to a fixed number of CPUs.
Please note that parallel processing doubles the memory footprint compared to sequential processing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch |
InternalDataFrame
|
The batch to process. |
required |
input_template |
str
|
The input template. |
required |
instructions_template |
str
|
The instructions' template. |
required |
response_model |
Type[BaseModel]
|
The response model to use for processing records. |
required |
extra_fields |
Optional[Dict[str, str]]
|
Extra fields to use in the templates. Defaults to None. |
None
|
field_schema |
Optional[Dict]
|
Field JSON schema to use in the templates. Defaults to all fields are strings, i.e. analogous to {"field_n": {"type": "string"}}. |
None
|
instructions_first |
bool
|
Whether to put instructions first. Defaults to True. |
True
|
output_template |
str
|
The output template. Deprecated. |
None
|
Returns: InternalDataFrame: The processed batch.
Source code in adala/runtimes/base.py
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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
init_runtime()
Initializes the runtime.
This method should be used to validate and potentially initialize the runtime instance.
Returns:
Name | Type | Description |
---|---|---|
Runtime |
Runtime
|
The initialized runtime instance. |
Source code in adala/runtimes/base.py
67 68 69 70 71 72 73 74 75 76 |
|
record_to_batch(record, input_template, instructions_template, response_model, output_batch_size=1, extra_fields=None, field_schema=None, instructions_first=True, output_template=None)
Processes a record and return a batch.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record |
Dict[str, str]
|
The record to process. |
required |
input_template |
str
|
The input template. |
required |
instructions_template |
str
|
The instructions template. |
required |
response_model |
Optional[Type[BaseModel]]
|
The response model to use for processing records. Defaults to None. |
required |
output_batch_size |
int
|
The batch size for the output. Defaults to 1. |
1
|
extra_fields |
Optional[Dict[str, str]]
|
Extra fields to use in the templates. Defaults to None. |
None
|
field_schema |
Optional[Dict]
|
Field JSON schema to use in the templates. Defaults to all fields are strings, i.e. analogous to {"field_n": {"type": "string"}}. |
None
|
instructions_first |
bool
|
Whether to put instructions first. Defaults to True. |
True
|
output_template |
str
|
The output template. Deprecated. |
None
|
Returns:
Name | Type | Description |
---|---|---|
InternalDataFrame |
InternalDataFrame
|
The processed batch. |
Source code in adala/runtimes/base.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
record_to_record(record, input_template, instructions_template, response_model, extra_fields=None, field_schema=None, instructions_first=True, output_template=None)
abstractmethod
Processes a record.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record |
Dict[str, str]
|
The record to process. |
required |
input_template |
str
|
The input template. |
required |
instructions_template |
str
|
The instructions template. |
required |
response_model |
Type[BaseModel]
|
The response model to use for processing records. |
required |
extra_fields |
Optional[Dict[str, str]]
|
Extra fields to use in the templates. Defaults to None. |
None
|
field_schema |
Optional[Dict]
|
Field JSON schema to use in the templates. Defaults to all fields are strings, i.e. analogous to {"field_n": {"type": "string"}}. |
None
|
instructions_first |
bool
|
Whether to put instructions first. Defaults to True. |
True
|
output_template |
str
|
The output template. Deprecated. |
None
|
Returns:
Type | Description |
---|---|
Dict[str, str]
|
Dict[str, str]: The processed record. |
Source code in adala/runtimes/base.py
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 |
|