API Reference¶
nearai ¶
EntryLocation ¶
Bases: BaseModel
EntryLocation
Source code in nearai/openapi_client/models/entry_location.py
from_dict classmethod
¶
Create an instance of EntryLocation from a dict
Source code in nearai/openapi_client/models/entry_location.py
from_json classmethod
¶
to_dict ¶
Return the dictionary representation of the model using alias.
This has the following differences from calling pydantic's self.model_dump(by_alias=True)
:
None
is only added to the output dict for nullable fields that were set at model initialization. Other fields with valueNone
are ignored.
Source code in nearai/openapi_client/models/entry_location.py
to_json ¶
Returns the JSON representation of the model using alias
parse_location ¶
parse_location(entry_location: str) -> EntryLocation
Create a EntryLocation from a string in the format namespace/name/version.
Source code in nearai/lib.py
agents ¶
agent ¶
Agent ¶
Bases: object
Source code in nearai/agents/agent.py
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 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 |
|
get_full_name ¶
load_agent staticmethod
¶
load_agent(name: str, config: ClientConfig, local: bool = False)
Loads a single agent from the registry.
Source code in nearai/agents/agent.py
load_agents staticmethod
¶
load_agents(agents: str, config: ClientConfig, local: bool = False)
set_agent_metadata ¶
Set agent details from metadata.
Source code in nearai/agents/agent.py
write_agent_files_to_temp staticmethod
¶
Write agent files to a temporary directory.
Source code in nearai/agents/agent.py
environment ¶
Environment ¶
Bases: object
Source code in nearai/agents/environment.py
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 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 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 |
|
__init__ ¶
__init__(path: str, agents: List[Agent], client: InferenceClient, hub_client: OpenAI, thread_id: str, run_id: str, create_files: bool = True, env_vars: Optional[Dict[str, Any]] = None, tool_resources: Optional[Dict[str, Any]] = None, print_system_log: bool = False, agent_runner_user: Optional[str] = None, approvals: Optional[Dict[str, Any]] = default_approvals) -> None
Source code in nearai/agents/environment.py
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 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 |
|
add_agent_log ¶
Add agent log with timestamp and log level.
Source code in nearai/agents/environment.py
add_agent_start_system_log ¶
Adds agent start system log.
Source code in nearai/agents/environment.py
add_message ¶
add_message(role: str, message: str, attachments: Optional[Iterable[Attachment]] = None, **kwargs: Any)
Deprecated. Please use add_reply
instead. Assistant adds a message to the environment.
Source code in nearai/agents/environment.py
add_system_log ¶
Add system log with timestamp and log level.
Source code in nearai/agents/environment.py
call_agent ¶
clear_temp_agent_files ¶
Remove temp agent files created to be used in runpy
.
Source code in nearai/agents/environment.py
completion ¶
completion(messages: Union[Iterable[ChatCompletionMessageParam], str], model: Union[Iterable[ChatCompletionMessageParam], str] = '', **kwargs: Any) -> str
Returns a completion for the given messages using the given model.
Source code in nearai/agents/environment.py
completion_and_run_tools ¶
completion_and_run_tools(messages: List[ChatCompletionMessageParam], model: str = '', tools: Optional[List] = None, **kwargs: Any) -> Optional[str]
Returns a completion for the given messages using the given model and runs tools.
Source code in nearai/agents/environment.py
completions ¶
completions(messages: Union[Iterable[ChatCompletionMessageParam], str], model: Union[Iterable[ChatCompletionMessageParam], str] = '', stream: bool = False, **kwargs: Any) -> Union[ModelResponse, CustomStreamWrapper]
Returns all completions for given messages using the given model.
Source code in nearai/agents/environment.py
completions_and_run_tools ¶
completions_and_run_tools(messages: List[ChatCompletionMessageParam], model: str = '', tools: Optional[List] = None, add_responses_to_messages: bool = True, agent_role_name='assistant', tool_role_name='tool', **kwargs: Any) -> ModelResponse
Returns all completions for given messages using the given model and runs tools.
Source code in nearai/agents/environment.py
create_snapshot ¶
Create an in memory snapshot.
Source code in nearai/agents/environment.py
environment_run_info ¶
Returns the environment run information.
Source code in nearai/agents/environment.py
exec_command ¶
Executes a command in the environment and logs the output.
The environment does not allow running interactive programs. It will run a program for 1 second then will interrupt it if it is still running or if it is waiting for user input. command: The command to execute, like 'ls -l' or 'python3 tests.py'
Source code in nearai/agents/environment.py
generate_folder_hash_id ¶
Returns hash based on files and their contents in path, including subfolders.
Source code in nearai/agents/environment.py
get_agent_temp_path ¶
get_inference_parameters ¶
get_inference_parameters(messages: Union[Iterable[ChatCompletionMessageParam], str], model: Union[Iterable[ChatCompletionMessageParam], str], stream: bool, **kwargs: Any) -> Tuple[InferenceParameters, Any]
Run inference parameters to run completions.
Source code in nearai/agents/environment.py
get_last_message ¶
Reads last message from the given role and returns it.
get_primary_agent_temp_dir ¶
get_system_path ¶
get_tool_registry ¶
get_tool_registry(new: bool = False) -> ToolRegistry
Returns the tool registry, a dictionary of tools that can be called by the agent.
list_files ¶
list_messages ¶
Backwards compatibility for chat_completions messages.
Source code in nearai/agents/environment.py
list_terminal_commands ¶
Returns the terminal commands from the terminal file.
Source code in nearai/agents/environment.py
load_snapshot ¶
Load Environment from Snapshot.
Source code in nearai/agents/environment.py
read_file ¶
Reads a file from the environment or thread.
Source code in nearai/agents/environment.py
run ¶
Runs agent(s) against a new or previously created environment.
Source code in nearai/agents/environment.py
set_next_actor ¶
Set the next actor / action in the dialogue.
Source code in nearai/agents/environment.py
signed_completion ¶
signed_completion(messages: Union[Iterable[ChatCompletionMessageParam], str], model: Union[Iterable[ChatCompletionMessageParam], str] = '', **kwargs: Any) -> Dict[str, str]
Returns a completion for the given messages using the given model with the agent signature.
Source code in nearai/agents/environment.py
verify_message ¶
verify_message(account_id: str, public_key: str, signature: str, message: str, nonce: str, callback_url: str) -> SignatureVerificationResult
Verifies that the user message is signed with NEAR Account.
Source code in nearai/agents/environment.py
verify_signed_message ¶
verify_signed_message(completion: str, messages: Union[Iterable[ChatCompletionMessageParam], str], public_key: Union[str, None] = None, signature: Union[str, None] = None, model: Union[Iterable[ChatCompletionMessageParam], str] = '', **kwargs: Any) -> bool
Verifies a signed message.
Source code in nearai/agents/environment.py
tool_json_helper ¶
parse_json_args ¶
Parses LLM generated JSON args, trying various repair strategies if args are not valid JSON.
Source code in nearai/agents/tool_json_helper.py
parse_json_args_based_on_signature ¶
Finds parameter names based on the signature and tries to extract the values in between from the args string.
Source code in nearai/agents/tool_json_helper.py
tool_registry ¶
ToolRegistry ¶
A registry for tools that can be called by the agent.
Tool definitions follow this structure:
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["location"],
},
},
}
Source code in nearai/agents/tool_registry.py
5 6 7 8 9 10 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 |
|
call_tool ¶
get_all_tools ¶
get_tool ¶
get_tool_definition ¶
Get the definition of a tool by name.
Source code in nearai/agents/tool_registry.py
cli ¶
AgentCli ¶
Source code in nearai/cli.py
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 |
|
_create_new_agent ¶
Create a new agent from scratch.
Source code in nearai/cli.py
_fork_agent ¶
Fork an existing agent.
Source code in nearai/cli.py
_task ¶
_task(agent: str, task: str, thread_id: Optional[str] = None, tool_resources: Optional[Dict[str, Any]] = None, file_ids: Optional[List[str]] = None, last_message_id: Optional[str] = None, local: bool = False, env_vars: Optional[Dict[str, Any]] = None) -> Optional[str]
Runs agent non-interactively with a single task.
Source code in nearai/cli.py
create ¶
create(name: Optional[str] = None, description: Optional[str] = None, fork: Optional[str] = None) -> None
Create a new agent or fork an existing one.
Usage
nearai agent create nearai agent create --name
Examples¶
nearai agent create nearai agent create --name my_agent --description "My new agent" nearai agent create --fork agentic.near/summary/0.0.3 --name new_summary_agent
Source code in nearai/cli.py
dev ¶
Run local UI for development of agents that have their own UI.
Source code in nearai/cli.py
inspect ¶
Inspect environment from given path.
interactive ¶
interactive(agent: str, thread_id: Optional[str] = None, tool_resources: Optional[Dict[str, Any]] = None, local: bool = False, env_vars: Optional[Dict[str, Any]] = None) -> None
Runs agent interactively.
Source code in nearai/cli.py
task ¶
task(agent: str, task: str, thread_id: Optional[str] = None, tool_resources: Optional[Dict[str, Any]] = None, file_ids: Optional[List[str]] = None, local: bool = False, env_vars: Optional[Dict[str, Any]] = None) -> None
CLI wrapper for the _task method.
Source code in nearai/cli.py
BenchmarkCli ¶
Source code in nearai/cli.py
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 |
|
__init__ ¶
list ¶
list(namespace: Optional[str] = None, benchmark: Optional[str] = None, solver: Optional[str] = None, args: Optional[str] = None, total: int = 32, offset: int = 0)
List all executed benchmarks.
Source code in nearai/cli.py
run ¶
run(dataset: str, solver_strategy: str, max_concurrent: int = 2, force: bool = False, subset: Optional[str] = None, check_compatibility: bool = True, record: bool = False, num_inference_retries: int = 10, **solver_args: Any) -> None
Run benchmark on a dataset with a solver strategy.
It will cache the results in the database and subsequent runs will pull the results from the cache. If force is set to True, it will run the benchmark again and update the cache.
Source code in nearai/cli.py
CLI ¶
Source code in nearai/cli.py
location ¶
submit ¶
Submit a task to be executed by a worker.
Source code in nearai/cli.py
task ¶
ConfigCli ¶
Source code in nearai/cli.py
get ¶
EvaluationCli ¶
Source code in nearai/cli.py
read_solutions ¶
Reads solutions.json from evaluation entry.
Source code in nearai/cli.py
table ¶
table(all_key_columns: bool = False, all_metrics: bool = False, num_columns: int = 6, metric_name_max_length: int = 30) -> None
Prints table of evaluations.
Source code in nearai/cli.py
HubCLI ¶
Source code in nearai/cli.py
chat ¶
Chat with model from NEAR AI hub.
query (str): User's query to model
endpoint (str): NEAR AI HUB's url
model (str): Name of a model
provider (str): Name of a provider
info (bool): Display system info
kwargs (Dict[str, Any]): All cli keyword arguments
Source code in nearai/cli.py
LoginCLI ¶
Source code in nearai/cli.py
__call__ ¶
Login with NEAR Mainnet account.
remote (bool): Remote login allows signing message with NEAR Account on a remote machine
auth_url (str): Url to the auth portal
accountId (str): AccountId in .near-credentials folder to signMessage
privateKey (str): Private Key to sign a message
kwargs (Dict[str, Any]): All cli keyword arguments
Source code in nearai/cli.py
save ¶
Save NEAR account authorization data.
accountId (str): Near Account
signature (str): Signature
publicKey (str): Public Key used to sign
callbackUrl (str): Callback Url
nonce (str): nonce
kwargs (Dict[str, Any]): All cli keyword arguments
Source code in nearai/cli.py
LogoutCLI ¶
Source code in nearai/cli.py
__call__ ¶
Clear NEAR account auth data.
Source code in nearai/cli.py
PermissionCli ¶
Source code in nearai/cli.py
RegistryCli ¶
Source code in nearai/cli.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 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 |
|
download ¶
info ¶
Show information about an item.
Source code in nearai/cli.py
list ¶
list(namespace: str = '', category: str = '', tags: str = '', total: int = 32, offset: int = 0, show_all: bool = False, show_latest_version: bool = True, star: str = '') -> None
List available items.
Source code in nearai/cli.py
metadata_template ¶
Create a metadata template.
Source code in nearai/cli.py
update ¶
Update metadata of a registry item.
Source code in nearai/cli.py
upload ¶
upload(local_path: str = '.') -> EntryLocation
upload_unregistered_common_provider_models ¶
Creates new registry items for unregistered common provider models.
Source code in nearai/cli.py
check_update ¶
Check if there is a new version of nearai CLI available.
Source code in nearai/cli.py
config ¶
Config ¶
Bases: BaseModel
Source code in nearai/config.py
get ¶
update_with ¶
update_with(extra_config: Dict[str, Any], map_key: Callable[[str], str] = lambda x: x) -> Config
Update the config with the given dictionary.
Source code in nearai/config.py
NearAiHubConfig ¶
Bases: BaseModel
NearAiHub Config.
login_with_near (Optional[bool]): Indicates whether to attempt login using Near Auth.
api_key (Optional[str]): The API key to use if Near Auth is not being utilized
base_url (Optional[str]): NEAR AI Hub url
default_provider (Optional[str]): Default provider name
default_model (Optional[str]): Default model name
custom_llm_provider (Optional[str]): provider to be used by litellm proxy
Source code in nearai/config.py
dataset ¶
get_dataset ¶
Download the dataset from the registry and download it locally if it hasn't been downloaded yet.
:param name: The name of the entry to download the dataset. The format should be namespace/name/version. :return: The path to the downloaded dataset
Source code in nearai/dataset.py
load_dataset ¶
delegation ¶
OnBehalfOf ¶
Create a context manager that allows you to delegate actions to another account.
with OnBehalfOf("scheduler.ai"):
# Upload is done on behalf of scheduler.ai
# If delegation permission is not granted, this will raise an exception
registry.upload()
Source code in nearai/delegation.py
__enter__ ¶
Set the default client to the account we are acting on behalf of.
Source code in nearai/delegation.py
__exit__ ¶
Reset the default client to the original account.
__init__ ¶
Context manager that creates a scope where all actions are done on behalf of another account.
check_on_behalf_of ¶
revoke_delegation ¶
evaluation ¶
_print_metrics_tables ¶
_print_metrics_tables(rows: List[Dict[str, str]], metric_names: List[str], num_columns: int, all_key_columns: bool, metric_name_max_length: int)
Builds table(s) and prints them.
Source code in nearai/evaluation.py
_shorten_metric_name ¶
Shortens metric name if needed.
Source code in nearai/evaluation.py
load_benchmark_entry_info ¶
Deserializes benchmark info entry from db data.
Source code in nearai/evaluation.py
print_evaluation_table ¶
print_evaluation_table(rows: List[Dict[str, str]], columns: List[str], important_columns: List[str], all_key_columns: bool, all_metrics: bool, num_columns: int, metric_name_max_length: int) -> None
Prints table of evaluations.
Source code in nearai/evaluation.py
record_evaluation_metrics ¶
record_evaluation_metrics(solver_strategy: SolverStrategy, benchmark_id: int, data_tasks: Union[Dataset, List[dict]], metrics: Dict[str, Any], prepend_evaluation_name: bool = True) -> None
Uploads evaluation metrics into registry.
Source code in nearai/evaluation.py
record_single_score_evaluation ¶
record_single_score_evaluation(solver_strategy: SolverStrategy, benchmark_id: int, data_tasks: Union[Dataset, List[dict]], score: float) -> None
Uploads single score evaluation into registry.
Source code in nearai/evaluation.py
upload_evaluation ¶
upload_evaluation(evaluation_name: str, benchmark_id: int, data_tasks: Union[Dataset, List[dict]], metrics: Dict[str, Any], model: str = '', agent: str = '', namespace: str = '', version: str = '', provider: str = '') -> None
Uploads evaluation into registry.
evaluation_name
: a unique name for (benchmark, solver) tuple, e.g. "mbpp" or "live_bench" or "mmlu-5-shot". metrics
: metrics from evaluation. model
: model that was used. agent
: agent that was evaluated, in any. namespace
: namespace of evaluated agent or evaluated model. version
: version of evaluated agent or evaluated model. provider
: provider of model used; pass local
if running locally.
Source code in nearai/evaluation.py
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 |
|
finetune ¶
FinetuneCli ¶
Source code in nearai/finetune/__init__.py
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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
start ¶
start(model: str, tokenizer: str, dataset: str, num_procs: int, format: str, upload_checkpoint: bool = True, num_nodes: int = 1, job_id: Optional[str] = None, checkpoint: Optional[str] = None, **dataset_kwargs: Any) -> None
Start a finetuning job on the current node.
model: Name of a model in the registry. Base model to finetune.
tokenizer: Name of a tokenizer in the registry. Using tokenizer.model format.
dataset: Name of a dataset in the registry.
num_procs: Number of GPUs to use for training
format: Name of the configuration file to use. For example llama3-70b, llama3-8b. Valid options are in etc/finetune.
upload_checkpoint: Whether to upload the checkpoint to the registry. Default is True.
num_nodes: Number of nodes to use for training. Default is 1.
job_id: Unique identifier for the job. Default is None.
checkpoint: Name of the model checkpoint to start from. Default is None.
dataset_kwargs: Additional keyword arguments to pass to the dataset constructor.
Source code in nearai/finetune/__init__.py
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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
parse_line ¶
Example of line to be parsed.
Step 33 | loss:1.5400923490524292 lr:9.9e-05 tokens_per_second_per_gpu:101.22285588141214
Source code in nearai/finetune/__init__.py
text_completion ¶
TextCompletionDataset ¶
Bases: Dataset
Freeform dataset for any unstructured text corpus. Quickly load any dataset from Hugging Face or local disk and tokenize it for your model.
tokenizer (BaseTokenizer): Tokenizer used to encode data. Tokenize must implement an ``encode`` and ``decode`` method.
source (str): path string of dataset, anything supported by Hugging Face's ``load_dataset``
(https://huggingface.co/docs/datasets/en/package_reference/loading_methods#datasets.load_dataset.path)
column (str): name of column in the sample that contains the text data. This is typically required
for Hugging Face datasets or tabular data. For local datasets with a single column, use the default "text",
which is what is assigned by Hugging Face datasets when loaded into memory. Default is "text".
max_seq_len (Optional[int]): Maximum number of tokens in the returned input and label token id lists.
Default is None, disabling truncation. We recommend setting this to the highest you can fit in memory
and is supported by the model. For example, llama2-7B supports up to 4096 for sequence length.
**load_dataset_kwargs (Dict[str, Any]): additional keyword arguments to pass to ``load_dataset``.
Source code in nearai/finetune/text_completion.py
truncate ¶
Truncate a list of tokens to a maximum length. If eos_id is provided, the last token will be replaced with eos_id.
tokens (List[Any]): list of tokens to truncate
max_seq_len (int): maximum length of the list
eos_id (Optional[Any]): token to replace the last token with. If None, the
last token will not be replaced. Default is None.
List[Any]: truncated list of tokens
Source code in nearai/finetune/text_completion.py
hub ¶
Hub ¶
Bases: object
Source code in nearai/hub.py
chat ¶
Processes a chat request by sending parameters to the NEAR AI Hub and printing the response.
Source code in nearai/hub.py
parse_hub_chat_params ¶
Parses and sets instance attributes from the given keyword arguments, using default values if needed.
Source code in nearai/hub.py
lib ¶
parse_location ¶
parse_location(entry_location: str) -> EntryLocation
Create a EntryLocation from a string in the format namespace/name/version.
Source code in nearai/lib.py
login ¶
AuthHandler ¶
Bases: SimpleHTTPRequestHandler
Source code in nearai/login.py
do_GET ¶
Webserver GET method.
Source code in nearai/login.py
find_open_port ¶
Finds and returns an open port number by binding to a free port on the local machine.
generate_and_save_signature ¶
Generates a signature for the given account ID and private key, then updates the auth configuration.
Source code in nearai/login.py
generate_callback_url ¶
generate_nonce ¶
login_with_file_credentials ¶
Logs in using credentials from a file for the specified account ID, generating and saving a signature.
Source code in nearai/login.py
login_with_near_auth ¶
Initiates the login process using NEAR authentication, either starting a local server to handle the callback or providing a URL for remote authentication.
Source code in nearai/login.py
print_login_status ¶
Prints the current authentication status if available in the config file.
Source code in nearai/login.py
print_url_message ¶
Prints a message instructing the user to visit the given URL to complete the login process.
update_auth_config ¶
Update authentication configuration if the provided signature is valid.
Source code in nearai/login.py
model ¶
get_model ¶
Download the model from the registry and download it locally if it hasn't been downloaded yet.
:param name: The name of the entry to download the model. The format should be namespace/name/version. :return: The path to the downloaded model
Source code in nearai/model.py
registry ¶
Registry ¶
Source code in nearai/registry.py
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 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 |
|
__init__ ¶
Create Registry object to interact with the registry programmatically.
Source code in nearai/registry.py
dict_models ¶
dict_models() -> Dict[NamespacedName, NamespacedName]
Returns a mapping canonical->name.
Source code in nearai/registry.py
download ¶
download(entry_location: Union[str, EntryLocation], force: bool = False, show_progress: bool = False, verbose: bool = True) -> Path
Download entry from the registry locally.
Source code in nearai/registry.py
download_file ¶
download_file(entry_location: EntryLocation, path: Path, local_path: Path)
Download a file from the registry.
Source code in nearai/registry.py
info ¶
info(entry_location: EntryLocation) -> Optional[EntryMetadata]
Get metadata of a entry in the registry.
Source code in nearai/registry.py
list ¶
list(namespace: str, category: str, tags: str, total: int, offset: int, show_all: bool, show_latest_version: bool, starred_by: str = '') -> List[EntryInformation]
List and filter entries in the registry.
Source code in nearai/registry.py
list_all_visible ¶
List all visible entries.
Source code in nearai/registry.py
list_files ¶
list_files(entry_location: EntryLocation) -> List[str]
List files in from an entry in the registry.
Return the relative paths to all files with respect to the root of the entry.
Source code in nearai/registry.py
update ¶
update(entry_location: EntryLocation, metadata: EntryMetadataInput) -> Dict[str, Any]
Update metadata of a entry in the registry.
Source code in nearai/registry.py
upload ¶
upload(local_path: Path, metadata: Optional[EntryMetadata] = None, show_progress: bool = False) -> EntryLocation
Upload entry to the registry.
If metadata is provided it will overwrite the metadata in the directory, otherwise it will use the metadata.json found on the root of the directory.
Source code in nearai/registry.py
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 |
|
upload_file ¶
upload_file(entry_location: EntryLocation, local_path: Path, path: Path) -> bool
Upload a file to the registry.
Source code in nearai/registry.py
get_namespace ¶
Returns namespace of an item or user namespace.
Source code in nearai/registry.py
shared ¶
auth_data ¶
AuthData ¶
Bases: BaseModel
Source code in nearai/shared/auth_data.py
namespace property
¶
Get the account ID for the auth data.
In case you are running a request on behalf of another account, this will return the account ID of the account.
generate_bearer_token ¶
Generates a JSON-encoded bearer token containing authentication data.
Source code in nearai/shared/auth_data.py
cache ¶
mem_cache_with_timeout ¶
Decorator to cache function results for a specified timeout period.
Source code in nearai/shared/cache.py
client_config ¶
ClientConfig ¶
Bases: BaseModel
Source code in nearai/shared/client_config.py
get_hub_client ¶
Get the hub client.
Source code in nearai/shared/client_config.py
inference_client ¶
InferenceClient ¶
Bases: object
Source code in nearai/shared/inference_client.py
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 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 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 |
|
add_file_to_vector_store ¶
Adds a file to vector store.
Source code in nearai/shared/inference_client.py
add_user_memory ¶
completions ¶
completions(model: str, messages: Iterable[ChatCompletionMessageParam], stream: bool = False, temperature: Optional[float] = None, max_tokens: Optional[int] = None, **kwargs: Any) -> Union[ModelResponse, CustomStreamWrapper]
Takes a model
and messages
and returns completions.
model
can be: 1. full path provider::model_full_path
. 2. model_short_name
. Default provider will be used.
Source code in nearai/shared/inference_client.py
create_thread ¶
create_vector_store ¶
create_vector_store(name: str, file_ids: List[str], expires_after: Union[ExpiresAfter, NotGiven] = NOT_GIVEN, chunking_strategy: Union[AutoFileChunkingStrategyParam, StaticFileChunkingStrategyParam, NotGiven] = NOT_GIVEN, metadata: Optional[Dict[str, str]] = None) -> VectorStore
Creates Vector Store.
:param name: Vector store name. :param file_ids: Files to be added to the vector store. :param expires_after: Expiration policy. :param chunking_strategy: Chunking strategy. :param metadata: Additional metadata. :return: Returns the created vector store or error.
Source code in nearai/shared/inference_client.py
create_vector_store_from_source ¶
create_vector_store_from_source(name: str, source: Union[GitHubSource, GitLabSource], source_auth: Optional[str] = None, chunking_strategy: Optional[ChunkingStrategy] = None, expires_after: Optional[ExpiresAfter] = None, metadata: Optional[Dict[str, str]] = None) -> VectorStore
Creates a vector store from the given source.
name (str): The name of the vector store.
source (Union[GitHubSource, GitLabSource]): The source from which to create the vector store.
source_auth (Optional[str]): The source authentication token.
chunking_strategy (Optional[ChunkingStrategy]): The chunking strategy to use.
expires_after (Optional[ExpiresAfter]): The expiration policy.
metadata (Optional[Dict[str, str]]): Additional metadata.
VectorStore: The created vector store.
Source code in nearai/shared/inference_client.py
generate_auth_for_current_agent ¶
Regenerate auth for the current agent.
Source code in nearai/shared/inference_client.py
generate_image ¶
get_agent_data ¶
Get agent data for the agent this client was initialized with.
get_agent_data_by_key ¶
Get agent data by key for the agent this client was initialized with.
get_agent_public_key ¶
Request agent public key.
Source code in nearai/shared/inference_client.py
get_vector_store ¶
Gets a vector store by id.
Source code in nearai/shared/inference_client.py
query_user_memory ¶
query_vector_store ¶
query_vector_store(vector_store_id: str, query: str, full_files: bool = False) -> Union[List[SimilaritySearch], List[SimilaritySearchFile]]
Query a vector store.
Source code in nearai/shared/inference_client.py
run_agent ¶
Starts a child agent run from a parent agent run.
Source code in nearai/shared/inference_client.py
save_agent_data ¶
Save agent data for the agent this client was initialized with.
Source code in nearai/shared/inference_client.py
schedule_run ¶
schedule_run(agent: str, input_message: str, thread_id: Optional[str], run_params: Optional[Dict[str, str]], run_at: datetime)
Query a vector store.
Source code in nearai/shared/inference_client.py
threads_create_and_run_poll ¶
threads_create_and_run_poll(assistant_id: str, model: str, messages: List[ChatCompletionMessageParam])
Create a thread and run the assistant.
Source code in nearai/shared/inference_client.py
threads_fork ¶
threads_list_messages ¶
threads_messages_create ¶
Create a message in a thread.
threads_runs_create ¶
Create a run in a thread.
upload_file ¶
upload_file(file_content: str, purpose: Literal['assistants', 'batch', 'fine-tune', 'vision'], encoding: str = 'utf-8', file_name='file.txt', file_type='text/plain') -> FileObject
Uploads a file.
Source code in nearai/shared/inference_client.py
models ¶
AutoFileChunkingStrategyParam ¶
ChunkingStrategy ¶
CreateVectorStoreRequest ¶
Bases: BaseModel
Request model for creating a new vector store.
Source code in nearai/shared/models.py
chunking_strategy class-attribute
instance-attribute
¶
chunking_strategy: Union[AutoFileChunkingStrategyParam, StaticFileChunkingStrategyParam, None] = None
The chunking strategy to use for the vector store.
expires_after class-attribute
instance-attribute
¶
expires_after: Optional[ExpiresAfter] = None
The expiration time for the vector store.
file_ids class-attribute
instance-attribute
¶
The file IDs to attach to the vector store.
metadata class-attribute
instance-attribute
¶
The metadata to attach to the vector store.
ExpiresAfter ¶
Bases: TypedDict
Source code in nearai/shared/models.py
StaticFileChunkingStrategyParam ¶
Bases: TypedDict
Source code in nearai/shared/models.py
chunk_overlap_tokens instance-attribute
¶
The number of tokens that overlap between chunks. The default value is 400
.
Note that the overlap must not exceed half of max_chunk_size_tokens
.
max_chunk_size_tokens instance-attribute
¶
The maximum number of tokens in each chunk.
The default value is 800
. The minimum value is 100
and the maximum value is 4096
.
VectorStoreFileCreate ¶
Bases: BaseModel
Request model for creating a vector store file.
Source code in nearai/shared/models.py
naming ¶
NamespacedName ¶
Source code in nearai/shared/naming.py
canonical ¶
canonical() -> NamespacedName
Returns canonical NamespacedName.
Source code in nearai/shared/naming.py
create_registry_name ¶
Formats name
for a suitable registry name.
Source code in nearai/shared/naming.py
get_canonical_name ¶
Returns a name that can be used for matching entities.
Applies such transformations: 1. All letters lowercase. 2. Convert '.' between digits to 'p'. 3. Convert '
e.g. "llama-3.1-70b-instruct" -> "llama3p1_70binstruct"
Source code in nearai/shared/naming.py
near ¶
sign ¶
SignatureVerificationResult ¶
Bases: Enum
Source code in nearai/shared/near/sign.py
convert_nonce ¶
Converts a given value to a 32-byte nonce.
Source code in nearai/shared/near/sign.py
create_inference_signature ¶
create_inference_signature(private_key: str, payload: CompletionSignaturePayload) -> tuple[str, str]
Creates a cryptographic signature for a given extended inference payload using a specified private key.
Source code in nearai/shared/near/sign.py
create_signature ¶
Creates a cryptographic signature for a given payload using a specified private key.
Source code in nearai/shared/near/sign.py
validate_completion_signature ¶
Validates a cryptographic signature for a given payload using a specified public key.
Source code in nearai/shared/near/sign.py
validate_nonce ¶
Ensures that the nonce is a valid timestamp.
Source code in nearai/shared/near/sign.py
validate_signature ¶
Validates a cryptographic signature for a given payload using a specified public key.
Source code in nearai/shared/near/sign.py
verify_access_key_owner ¶
verify_access_key_owner(public_key, account_id) -> SignatureVerificationResult
Verifies if a given public key belongs to a specified account ID using FastNEAR API.
Source code in nearai/shared/near/sign.py
verify_signed_message ¶
verify_signed_message(account_id, public_key, signature, message, nonce, recipient, callback_url) -> SignatureVerificationResult
Verifies a signed message and ensures the public key belongs to the specified account.
Source code in nearai/shared/near/sign.py
provider_models ¶
ProviderModels ¶
Source code in nearai/shared/provider_models.py
provider_models cached
property
¶
provider_models: Dict[NamespacedName, Dict[str, str]]
Returns a mapping canonical->provider->model_full_name.
available_provider_matches ¶
available_provider_matches(model: NamespacedName) -> Dict[str, str]
get_unregistered_common_provider_models ¶
get_unregistered_common_provider_models(registry_models: Dict[NamespacedName, NamespacedName]) -> List[Dict[str, str]]
Returns provider matches for unregistered provider models with default namespace.
Source code in nearai/shared/provider_models.py
match_provider_model ¶
Returns provider and model_full_path for given model
and optional provider
.
model
may take different formats. Supported ones: 1. model_full_path, e.g. "fireworks::accounts/yi-01-ai/models/yi-large" 2. model_full_path without provider, e.g. "accounts/yi-01-ai/models/yi-large" 3. model_short_name as used by provider, e.g. "llama-v3-70b-instruct" 4. namespace/model_short_name as used by provider, e.g. "yi-01-ai/yi-large" 5. model_name as used in registry, e.g. "llama-3-70b-instruct" 6. namespace/model_name as used in registry, e.g. "near.ai/llama-3-70b-instruct"
Source code in nearai/shared/provider_models.py
get_provider_model ¶
Splits the model
string based on a predefined separator and returns the components.
provider (Optional[str]): The default provider name. Can be `None` if the provider
is included in the `model` string.
model (str): The model identifier, which may include the provider name separated by
a specific delimiter (defined by `PROVIDER_MODEL_SEP`, e.g. `::`).
Source code in nearai/shared/provider_models.py
get_provider_namespaced_model ¶
get_provider_namespaced_model(provider_model: str, provider: Optional[str] = None) -> Tuple[str, NamespacedName]
Given provider_model
returns provider and namespaced model.
Source code in nearai/shared/provider_models.py
solvers ¶
DDOTSV0Solver ¶
Bases: SolverStrategy
Solver strategy for competitive programming problems live on DDOTS.
This dataset will run agents in an Agent environment previously prepared.
workspace/ .id -- Id of the problem PROBLEM.txt -- Description of the problem
The agent should call env.submit_python(code) to submit the code to the DDOTS server.
Source code in nearai/solvers/ddot_v0_solver.py
GSM8KSolverStrategy ¶
Bases: SolverStrategy
Solver strategy for the GSM8K dataset.
Source code in nearai/solvers/gsm8k_solver.py
HellaswagSolverStrategy ¶
Bases: SolverStrategy
Solver strategy for the MMLU dataset.
Source code in nearai/solvers/hellaswag_solver.py
LeanSolverStrategy ¶
Bases: SolverStrategy
Solver strategy to evaluate against Lean problems.
Source code in nearai/solvers/lean_solver.py
LiveBenchSolverStrategy ¶
Bases: SolverStrategy
Solver strategy for the live bench dataset.
Source code in nearai/solvers/livebench_solver.py
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 232 233 234 235 236 237 238 239 240 |
|
MBPPSolverStrategy ¶
Bases: SolverStrategy
Solver strategy for the MBPP dataset.
Source code in nearai/solvers/mbpp_solver.py
MMLUSolverStrategy ¶
Bases: SolverStrategy
Solver strategy for the MMLU dataset.
Source code in nearai/solvers/mmlu_solver.py
SolverStrategy ¶
Bases: ABC
Abstract class for solver strategies.
Source code in nearai/solvers/__init__.py
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 |
|
agent_name ¶
agent_version ¶
compatible_datasets abstractmethod
¶
evaluated_entry_namespace ¶
Returns namespace of a model or agent to be evaluated.
evaluation_name abstractmethod
¶
Returns a unique name for (benchmark, solver) tuple, e.g. 'mbpp' or 'live_bench' or 'mmlu-5-shot'.
get_custom_tasks ¶
Custom tasks for custom benchmark.
Source code in nearai/solvers/__init__.py
get_evaluation_metrics ¶
Given results for all datums, returns evaluation metrics.
Not used by TrueOrFalseList scoring method. Do not prepend with evaluation_name. If hierarchical, use slashes /. Expected metrics is a dict of scores, e.g.: {"average":
Source code in nearai/solvers/__init__.py
model_provider ¶
Returns model provider.
Source code in nearai/solvers/__init__.py
SolverStrategyMeta ¶
Bases: ABCMeta
Metaclass that automatically registers subclasses in the SolverStrategyRegistry.
Source code in nearai/solvers/__init__.py
ddot_v0_solver ¶
DDOTSEnvironment ¶
Bases: Environment
Source code in nearai/solvers/ddot_v0_solver.py
submit_python ¶
Returns True if the submission was accepted, False otherwise.
The second element of the tuple is the output of the checker if the submission was rejected.
Source code in nearai/solvers/ddot_v0_solver.py
DDOTSV0Solver ¶
Bases: SolverStrategy
Solver strategy for competitive programming problems live on DDOTS.
This dataset will run agents in an Agent environment previously prepared.
workspace/ .id -- Id of the problem PROBLEM.txt -- Description of the problem
The agent should call env.submit_python(code) to submit the code to the DDOTS server.
Source code in nearai/solvers/ddot_v0_solver.py
gsm8k_solver ¶
GSM8KSolverStrategy ¶
Bases: SolverStrategy
Solver strategy for the GSM8K dataset.
Source code in nearai/solvers/gsm8k_solver.py
hellaswag_solver ¶
HellaswagSolverStrategy ¶
Bases: SolverStrategy
Solver strategy for the MMLU dataset.
Source code in nearai/solvers/hellaswag_solver.py
lean_solver ¶
LeanSolverStrategy ¶
Bases: SolverStrategy
Solver strategy to evaluate against Lean problems.
Source code in nearai/solvers/lean_solver.py
load_theorem ¶
Use local copy of the repository.
livebench_solver ¶
LiveBenchSolverStrategy ¶
Bases: SolverStrategy
Solver strategy for the live bench dataset.
Source code in nearai/solvers/livebench_solver.py
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 232 233 234 235 236 237 238 239 240 |
|
mbpp_solver ¶
MBPPSolverStrategy ¶
Bases: SolverStrategy
Solver strategy for the MBPP dataset.
Source code in nearai/solvers/mbpp_solver.py
mmlu_solver ¶
MMLUSolverStrategy ¶
Bases: SolverStrategy
Solver strategy for the MMLU dataset.
Source code in nearai/solvers/mmlu_solver.py
tests ¶
test_provider_models ¶
TestMatchProviderModel ¶
Bases: TestCase
Unit tests for get_provider_namespaced_model.