Runtimes
AsyncRuntime
Bases: Runtime
Async version of runtime that uses asyncio to process batch of records.
Source code in adala/runtimes/base.py
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 |
|
batch_to_batch(batch, input_template, instructions_template, output_template, extra_fields=None, field_schema=None, instructions_first=True)
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 |
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
|
Returns:
Name | Type | Description |
---|---|---|
InternalDataFrame |
InternalDataFrame
|
The processed batch. |
Source code in adala/runtimes/base.py
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 |
|
record_to_record(record, input_template, instructions_template, output_template, extra_fields=None, field_schema=None, instructions_first=True)
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
|
Returns:
Type | Description |
---|---|
Dict[str, str]
|
Dict[str, str]: The processed record. |
Source code in adala/runtimes/base.py
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 |
|
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. |
Source code in adala/runtimes/base.py
11 12 13 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 |
|
batch_to_batch(batch, input_template, instructions_template, output_template, extra_fields=None, field_schema=None, instructions_first=True)
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 |
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
|
Returns:
Name | Type | Description |
---|---|---|
InternalDataFrame |
InternalDataFrame
|
The processed batch. |
Source code in adala/runtimes/base.py
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 |
|
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
23 24 25 26 27 28 29 30 31 32 |
|
record_to_batch(record, input_template, instructions_template, output_template, output_batch_size=1, extra_fields=None, field_schema=None, instructions_first=True)
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 |
output_template |
str
|
The output template. |
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
|
Returns:
Name | Type | Description |
---|---|---|
InternalDataFrame |
InternalDataFrame
|
The processed batch. |
Source code in adala/runtimes/base.py
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 |
|
record_to_record(record, input_template, instructions_template, output_template, extra_fields=None, field_schema=None, instructions_first=True)
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 |
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
|
Returns:
Type | Description |
---|---|
Dict[str, str]
|
Dict[str, str]: The processed record. |
Source code in adala/runtimes/base.py
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 |
|
AsyncOpenAIChatRuntime
Bases: AsyncRuntime
Runtime that uses OpenAI API and chat completion models to perform the skill. It uses async calls to OpenAI API.
Attributes:
Name | Type | Description |
---|---|---|
openai_model |
str
|
OpenAI model name. |
openai_api_key |
Optional[str]
|
OpenAI API key. If not provided, will be taken from OPENAI_API_KEY environment variable. |
max_tokens |
Optional[int]
|
Maximum number of tokens to generate. Defaults to 1000. |
temperature |
Optional[float]
|
Temperature for sampling, between 0 and 1. Higher values means the model will take more risks. Try 0.9 for more creative applications, and 0 (argmax sampling) for ones with a well-defined answer. Defaults to 0.0. |
concurrent_clients |
Optional[int]
|
Number of concurrent clients to OpenAI API. More clients means more parallel requests, but also more money spent and more chances to hit the rate limit. Defaults to 10. |
Source code in adala/runtimes/_openai.py
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 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
|
batch_to_batch(batch, input_template, instructions_template, output_template, extra_fields=None, field_schema=None, instructions_first=True)
async
Execute batch of requests with async calls to OpenAI API
Source code in adala/runtimes/_openai.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
|
OpenAIChatRuntime
Bases: Runtime
Runtime that uses OpenAI API and chat completion models to perform the skill.
Attributes:
Name | Type | Description |
---|---|---|
openai_model |
str
|
OpenAI model name. |
openai_api_key |
Optional[str]
|
OpenAI API key. If not provided, will be taken from OPENAI_API_KEY environment variable. |
max_tokens |
Optional[int]
|
Maximum number of tokens to generate. Defaults to 1000. |
Source code in adala/runtimes/_openai.py
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 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|
execute(messages)
Execute OpenAI request given list of messages in OpenAI API format
Source code in adala/runtimes/_openai.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
|
record_to_record(record, input_template, instructions_template, output_template, extra_fields=None, field_schema=None, instructions_first=False)
Execute OpenAI request given record and templates for input, instructions and output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record |
Dict[str, str]
|
Record to be used for input, instructions and output templates. |
required |
input_template |
str
|
Template for input message. |
required |
instructions_template |
str
|
Template for instructions message. |
required |
output_template |
str
|
Template for output message. |
required |
extra_fields |
Optional[Dict[str, str]]
|
Extra fields to be used in templates. |
None
|
field_schema |
Optional[Dict]
|
Field schema to be used for parsing templates. |
None
|
instructions_first |
bool
|
If True, instructions will be sent before input. |
False
|
Returns:
Type | Description |
---|---|
Dict[str, str]
|
Dict[str, str]: Output record. |
Source code in adala/runtimes/_openai.py
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 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|
OpenAIVisionRuntime
Bases: OpenAIChatRuntime
Runtime that uses OpenAI API and vision models to perform the skill. Only compatible with OpenAI API version 1.0.0 or higher.
Source code in adala/runtimes/_openai.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
|
record_to_record(record, input_template, instructions_template, output_template, extra_fields=None, field_schema=None, instructions_first=False)
Execute OpenAI request given record and templates for input, instructions and output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record |
Dict[str, str]
|
Record to be used for input, instructions and output templates. |
required |
input_template |
str
|
Template for input message. |
required |
instructions_template |
str
|
Template for instructions message. |
required |
output_template |
str
|
Template for output message. |
required |
extra_fields |
Optional[Dict[str, str]]
|
Extra fields to be used in templates. |
None
|
field_schema |
Optional[Dict]
|
Field jsonschema to be used for parsing templates.
Field schema must contain "format": "uri" for image fields. For example:
|
None
|
instructions_first |
bool
|
If True, instructions will be sent before input. |
False
|
Source code in adala/runtimes/_openai.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
|
async_create_completion(model, user_prompt, system_prompt=None, openai_api_key=None, instruction_first=True, semaphore=None, max_tokens=1000, temperature=0.0, session=None, default_timeout=10)
async
Async version of create_completion function with error handling and session timeout.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
str
|
OpenAI model name. |
required |
user_prompt |
str
|
User prompt. |
required |
system_prompt |
str
|
System prompt. |
None
|
openai_api_key |
str
|
OpenAI API key (if not set, will use OPENAI_API_KEY environment variable). |
None
|
instruction_first |
bool
|
Whether to put instructions first. |
True
|
semaphore |
Semaphore
|
Semaphore to limit concurrent requests. |
None
|
max_tokens |
int
|
Maximum tokens to generate. |
1000
|
temperature |
float
|
Temperature for sampling. |
0.0
|
session |
ClientSession
|
aiohttp session to use for requests. |
None
|
default_timeout |
int
|
Default timeout for the session. |
10
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: OpenAI response or error message. |
Source code in adala/runtimes/_openai.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 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 |
|