Base
BaseLLM
Bases: ConnectionNode
Base class for all LLM nodes.
Attributes:
| Name | Type | Description |
|---|---|---|
MODEL_PREFIX |
ClassVar[str | None]
|
Optional model prefix. |
name |
str | None
|
Name of the LLM node. Defaults to "LLM". |
model |
str
|
Model to use for the LLM. |
prompt |
Prompt | None
|
Prompt to use for the LLM. |
connection |
BaseConnection
|
Connection to use for the LLM. |
group |
Literal[LLMS]
|
Group for the node. Defaults to NodeGroup.LLMS. |
temperature |
float | None
|
Temperature for the LLM. |
max_tokens |
int | None
|
Maximum number of tokens for the LLM. |
stop |
list[str]
|
List of tokens to stop at for the LLM. |
error_handling |
ErrorHandling
|
Error handling config. Defaults to ErrorHandling(timeout_seconds=600). |
top_p |
float | None
|
Value to consider tokens with top_p probability. |
seed |
int | None
|
Seed for generating the same result for repeated requests. |
presence_penalty |
float | None
|
Penalize new tokens based on their existence in the text. |
frequency_penalty |
float | None
|
Penalize new tokens based on their frequency in the text. |
tool_choice |
str | None
|
Value to control which function is called by the model. |
thinking_enabled |
bool
|
Enables advanced reasoning if set to True. |
budget_tokens |
int
|
Maximum number of tokens allocated for thinking. |
response_format |
dict[str, Any]
|
JSON schema that specifies the structure of the llm's output. |
tools |
list[Tool]
|
List of tools that llm can call. |
fallback |
FallbackConfig
|
Configuration for fallback behavior. |
Source code in dynamiq/nodes/llms/base.py
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 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 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 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 408 409 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 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 | |
is_pdf_input_supported: bool
property
Check if the LLM supports PDF input.
is_vision_supported: bool
property
Check if the LLM supports vision/image processing.
to_dict_exclude_params: dict
property
Exclude fallback configuration during serialization.
__init__(**kwargs)
Initialize the BaseLLM instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs |
Additional keyword arguments. |
{}
|
Source code in dynamiq/nodes/llms/base.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
execute(input_data, config=None, prompt=None, tools=None, response_format=None, parallel_tool_calls=None, **kwargs)
Execute the LLM node.
This method processes the input data, formats the prompt, and generates a response using the configured LLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data |
BaseLLMInputSchema
|
The input data for the LLM. |
required |
config |
RunnableConfig
|
The configuration for the execution. Defaults to None. |
None
|
prompt |
Prompt
|
The prompt to use for this execution. Defaults to None. |
None
|
tools |
list[Tool | dict]
|
List of tools that llm can call. |
None
|
response_format |
dict[str, Any]
|
JSON schema that specifies the structure of the llm's output |
None
|
parallel_tool_calls |
bool | None
|
Whether to allow the LLM to return multiple tool calls in a single response. None means provider decides. |
None
|
**kwargs |
Additional keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
A dictionary containing the generated content and tool calls. |
Source code in dynamiq/nodes/llms/base.py
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 | |
get_context_for_input_schema()
Provides context for input schema that is required for proper validation.
Source code in dynamiq/nodes/llms/base.py
299 300 301 | |
get_messages(prompt, input_data)
Format and filter message parameters based on provider requirements. Override this in provider-specific subclasses.
Source code in dynamiq/nodes/llms/base.py
356 357 358 359 360 361 362 363 364 365 366 | |
get_token_limit()
Returns token limits of a llm.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of tokens. |
Source code in dynamiq/nodes/llms/base.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
get_usage_data(model, completion)
classmethod
Get usage data for the LLM.
This method generates usage data for the LLM based on the provided messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model |
str
|
The model to use for generating the usage data. |
required |
completion |
ModelResponse
|
The completion response from the LLM. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
BaseLLMUsageData |
BaseLLMUsageData
|
A model containing the usage data for the LLM. |
Source code in dynamiq/nodes/llms/base.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 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 | |
init_components(connection_manager=None)
Initialize components including fallback LLM if configured.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection_manager |
The connection manager for initializing connections. |
None
|
Source code in dynamiq/nodes/llms/base.py
270 271 272 273 274 275 276 277 278 | |
reset_run_state()
Reset the run state of the LLM.
Source code in dynamiq/nodes/llms/base.py
295 296 297 | |
run_sync(input_data, config=None, depends_result=None, **kwargs)
Run the LLM with fallback support.
If the primary LLM fails and a fallback is configured, the primary failure is traced first, then the fallback LLM is executed separately.
The fallback receives the same transformed input that the primary received, and the primary's output_transformer is applied to the fallback's output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data |
dict
|
Input data for the LLM. |
required |
config |
RunnableConfig
|
Configuration for the run. |
None
|
depends_result |
dict
|
Results of dependent nodes. |
None
|
**kwargs |
Additional keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
RunnableResult |
RunnableResult
|
Result of the LLM execution. |
Source code in dynamiq/nodes/llms/base.py
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 | |
set_model(value)
classmethod
Set the model with the appropriate prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
str | None
|
The model value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The model value with the prefix. |
Source code in dynamiq/nodes/llms/base.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
to_dict(**kwargs)
Convert to dictionary representation.
Source code in dynamiq/nodes/llms/base.py
285 286 287 288 289 290 291 292 293 | |
update_completion_params(params)
Updates or modifies the parameters for the completion method.
This method can be overridden by subclasses to customize the parameters passed to the completion method. By default, it enables usage information in streaming mode if streaming is enabled and include_usage is set. Args: params (dict[str, Any]): The parameters to be updated.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: The updated parameters. |
Source code in dynamiq/nodes/llms/base.py
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 | |
BaseLLMUsageData
Bases: BaseModel
Model for LLM usage data.
Attributes:
| Name | Type | Description |
|---|---|---|
prompt_tokens |
int
|
Number of prompt tokens. |
prompt_tokens_cost_usd |
float | None
|
Cost of prompt tokens in USD. |
completion_tokens |
int
|
Number of completion tokens. |
completion_tokens_cost_usd |
float | None
|
Cost of completion tokens in USD. |
total_tokens |
int
|
Total number of tokens. |
total_tokens_cost_usd |
float | None
|
Total cost of tokens in USD. |
cache_read_input_tokens |
int | None
|
Number of cache read input tokens. |
cache_creation_input_tokens |
int | None
|
Number of cache creation input tokens. |
Source code in dynamiq/nodes/llms/base.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
FallbackConfig
Bases: BaseModel
Configuration for LLM fallback behavior.
Attributes:
| Name | Type | Description |
|---|---|---|
llm |
BaseLLM | None
|
The fallback LLM to use when the primary LLM fails. Required when enabled=True. |
enabled |
bool
|
Whether fallback is enabled. Defaults to False. |
triggers |
list[FallbackTrigger]
|
List of trigger conditions that will activate the fallback. Use FallbackTrigger.ANY to trigger on any error. |
Examples:
Single trigger
FallbackConfig(llm=my_llm, enabled=True, triggers=[FallbackTrigger.RATE_LIMIT])
Multiple triggers
FallbackConfig(llm=my_llm, enabled=True, triggers=[FallbackTrigger.RATE_LIMIT, FallbackTrigger.CONNECTION])
Source code in dynamiq/nodes/llms/base.py
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 | |
validate_llm_required_when_enabled()
Validate that llm is provided when fallback is enabled.
Source code in dynamiq/nodes/llms/base.py
96 97 98 99 100 101 | |