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
agent_creator ¶
create_new_agent ¶
Create a new agent from scratch with interactive options.
Source code in nearai/agent_creator.py
display_success_and_options ¶
Display success message and interactive options for next steps.
Source code in nearai/agent_creator.py
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 |
|
fork_agent ¶
Fork an existing agent.
Source code in nearai/agent_creator.py
prompt_agent_details ¶
Prompt user for agent details and return them.
Source code in nearai/agent_creator.py
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 |
|
agents ¶
agent ¶
Agent ¶
Bases: object
Source code in nearai/agents/agent.py
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 |
|
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
)
run ¶
run(
env: Any,
task: Optional[str] = None,
log_stdout_callback=None,
log_stderr_callback=None,
) -> Tuple[Optional[str], Optional[str]]
Run the agent code. Returns error message and traceback message.
Source code in nearai/agents/agent.py
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 |
|
run_python_code ¶
run_python_code(
agent_namespace,
agent_runner_user,
agent_py_modules_import,
log_stdout_callback=None,
log_stderr_callback=None,
) -> Tuple[Optional[str], Optional[str]]
Launch python agent.
Source code in nearai/agents/agent.py
run_ts_agent ¶
run_ts_agent(
agent_filename,
env_vars,
json_params,
log_stdout_callback=None,
log_stderr_callback=None,
)
Launch typescript agent.
Source code in nearai/agents/agent.py
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
clear_module_cache ¶
Clears specified modules from the cache before executing the main code.
When executing agent code that imports utility modules from different locations, Python's module caching can sometimes use cached versions from the wrong location instead of importing from the agent's directory.
This function removes modules from sys.modules to ensure they're freshly imported when used in subsequent code executions, preventing issues with cached imports.
module_names: List of module names to clear from cache
namespace: Dictionary namespace for code execution
Source code in nearai/agents/agent.py
get_local_agent_files ¶
List of local agent files.
Files matching patterns in .gitignore (if present) are excluded.
Source code in nearai/agents/agent.py
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 |
|
environment ¶
Environment ¶
Bases: object
Source code in nearai/agents/environment.py
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 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 |
|
__init__ ¶
__init__(
agents: List[Agent],
client: InferenceClient,
hub_client: OpenAI,
thread_id: str,
run_id: str,
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,
fastnear_api_key: Optional[str] = None,
approvals=None,
) -> None
Source code in nearai/agents/environment.py
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 |
|
_load_log_from_thread ¶
Load log file from thread if it doesn't exist locally.
Source code in nearai/agents/environment.py
_save_logs_to_thread ¶
Save log file to thread.
Source code in nearai/agents/environment.py
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_chat_log ¶
Add chat history to log file when in debug mode.
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_get_tools_calls ¶
completion_and_get_tools_calls(
messages: List[ChatCompletionMessageParam],
model: str = "",
**kwargs: Any,
) -> SimpleNamespace
Returns completion message and/or tool calls from OpenAI or Llama tool formats.
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,
thread_id: Optional[str] = None,
attachments: Optional[Iterable[Attachment]] = None,
message_type: Optional[str] = None,
**kwargs: Any,
) -> Union[ModelResponse, CustomStreamWrapper]
Returns all completions for given messages using the given model.
Always returns a ModelResponse object. When stream=True, aggregates the streamed content into a ModelResponse. When stream=False, returns the ModelResponse directly.
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
environment_run_info ¶
Returns the environment run information.
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_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 ¶
list_messages(
thread_id: Optional[str] = None,
limit: Union[int, NotGiven] = 200,
order: Literal["asc", "desc"] = "asc",
)
Backwards compatibility for chat_completions messages.
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.
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
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 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 |
|
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
register_mcp_tool ¶
Register a tool callable from its definition.
Source code in nearai/agents/tool_registry.py
cli ¶
AgentCli ¶
For creating and interacting with agents.
Agent commands allow you to create and interact with agents by running them locally or via NEAR AI Cloud.
Commands
nearai agent create : Create a new agent or fork an existing one (--name, --description, --fork) nearai agent interactive : Run an agent interactively (--agent, --thread-id, --tool-resources, --local, --verbose, --env-vars) nearai agent task : Run a single task with an agent (--agent*, --task*, --thread-id, --tool-resources, --file-ids, --local, --verbose, --env-vars) nearai agent upload : Upload an agent to the registry (--local-path, --bump, --minor-bump, --major-bump) nearai agent dev : Run local UI for development of agents nearai agent inspect : Inspect environment from given path (
Examples:
Create a new agent interactively (Step-by-step prompts)¶
nearai agent create
Create a new agent with specific name and description¶
nearai agent create --name my-agent --description "My helpful assistant"
Run an agent interactively (Choose an agent from the list)¶
nearai agent interactive
Run a specific agent interactively in local mode¶
nearai agent interactive --agent path/to/agent --local
Run a single task with an agent¶
nearai agent task --agent example.near/agent-name/0.0.3 --task "Summarize this article: https://example.com/article"
Upload an agent to the registry¶
nearai agent upload ./path/to/agent
Upload an agent with automatic version bumping¶
nearai agent upload ./path/to/agent --bump
Documentation
https://docs.near.ai/agents/quickstart
Source code in nearai/cli.py
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 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 |
|
__call__ ¶
_print_stream_async async
¶
Asynchronously print the stream of messages from the run.
:param run: The stream to iterate over :return:
Source code in nearai/cli.py
_start_local_session ¶
_start_local_session(
agent: str,
thread_id: Optional[str] = None,
tool_resources: Optional[Dict[str, Any]] = None,
local_path: Optional[Path] = None,
verbose: bool = False,
env_vars: Optional[Dict[str, Any]] = None,
) -> EnvironmentRun
Starts local session, no messages yet from user.
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_path: Optional[Path] = None,
verbose: bool = False,
env_vars: Optional[Dict[str, Any]] = None,
streaming: bool = True,
) -> Optional[str]
Runs agent non-interactively with a single task.
Source code in nearai/cli.py
1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 |
|
create ¶
create(
name: Optional[str] = None,
description: Optional[str] = None,
fork: Optional[str] = None,
) -> None
Create a new AI agent from scratch or fork existing ones.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str) | Name for the new agent (optional). | None |
description | str) | Description of the new agent (optional). | None |
fork | str) | Path to an existing agent to fork (format: namespace/agent_name/version). | None |
Examples:
Create a new agent step-by-step with prompts¶
nearai agent create
Create with specific name and description¶
nearai agent create --name my_agent --description "My new agent"
Fork an existing agent and give it a new name¶
nearai agent create --fork example.near/agent-name/0.0.3 --name new_agent_name
Documentation
https://docs.near.ai/agents/quickstart
Source code in nearai/cli.py
dev ¶
Run a local development UI for agents that have their own UI.
This launches a local server for testing and developing agent functionality in a browser-based environment.
Examples:
Start the local development server¶
nearai agent dev
Source code in nearai/cli.py
inspect ¶
Inspect the environment and contents of an agent at the specified path.
This launches a Streamlit interface showing the agent's structure, code, and metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | str Path to the agent directory to inspect (required) | required |
Examples:
Inspect a local agent¶
nearai agent inspect ./path/to/agent
Inspect a downloaded registry agent¶
nearai agent inspect .near-registry/your-namespace/agent-name/0.1.0
Source code in nearai/cli.py
interactive ¶
interactive(
agent: Optional[str] = None,
thread_id: Optional[str] = None,
tool_resources: Optional[Dict[str, Any]] = None,
local: bool = False,
verbose: bool = False,
env_vars: Optional[Dict[str, Any]] = None,
stream: bool = False,
) -> None
Run an agent interactively in a conversational interface.
If no agent is specified, you'll be presented with a list of available agents to choose from. Specifying an agent will run the agent from NEAR AI Cloud. If you want to run a specific local agent, pass the path to the agent followed by the --local flag. (See examples below.)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent | str) | Path to the agent directory or agent ID (optional) | None |
thread_id | str) | Thread ID to continue an existing conversation | None |
tool_resources | dict) | Tool resources to pass to the agent (JSON format) | None |
local | bool) | Run the agent locally instead of in the cloud | False |
verbose | bool) | Show detailed debug information during execution | False |
env_vars | dict) | Environment variables to pass to the agent (JSON format) | None |
stream | bool) | Whether to stream the agent's output, only works with agents that stream completions | False |
Examples:
Select from a list of agents to run that you created or downloaded¶
nearai agent interactive
Run an agent hosted on NEAR AI Cloud¶
nearai agent interactive example.near/agent-name/latest
Run a specific agent locally¶
nearai agent interactive ./path/to/local/agent --local
Run an agent locally with verbose output¶
nearai agent interactive ./path/to/local/agent --local --verbose
Continue an existing conversation¶
nearai agent interactive example.near/agent-name/0.0.3 --thread-id abc123
Source code in nearai/cli.py
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 |
|
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,
verbose: bool = False,
env_vars: Optional[Dict[str, Any]] = None,
stream: bool = False,
) -> None
Run a single non-interactive task with an agent.
The agent will process the task and return its response. This is useful for automation or when you don't need an ongoing conversation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent | str) | Path to the agent directory or agent ID (required) | required |
task | str) | The task or question to send to the agent (required) | required |
thread_id | str) | Thread ID to continue an existing conversation | None |
tool_resources | dict) | Tool resources to pass to the agent (JSON format) | None |
file_ids | list) | File IDs to attach to the message | None |
local | bool) | Run the agent locally instead of in the cloud | False |
verbose | bool) | Show detailed debug information during execution | False |
env_vars | dict) | Environment variables to pass to the agent (JSON format) | None |
stream | bool) | Stream the agent's output, only works with agents that stream completions | False |
Examples:
Send a simple task to an agent¶
nearai agent task --agent example.near/agent-name/0.0.3 --task "Summarize this article: https://example.com/article"
Run a local agent with environment variables¶
nearai agent task --agent path/to/agent --task "Generate a report" --local --env-vars '{"API_KEY": "secret"}'
Continue a conversation in an existing thread¶
nearai agent task --agent example.near/agent-name/0.0.3 --task "Continue the analysis" --thread-id abc123
Source code in nearai/cli.py
1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 |
|
upload ¶
upload(
local_path: str = ".",
bump: bool = False,
minor_bump: bool = False,
major_bump: bool = False,
) -> Optional[EntryLocation]
Alias for 'nearai registry upload'.
Source code in nearai/cli.py
BenchmarkCli ¶
Commands for running and listing benchmarks on datasets with solver strategies.
Commands
nearai benchmark run : Run benchmark on a dataset with a solver strategy (dataset*, solver_strategy*, --max-concurrent, --force, --subset, --check-compatibility, --record, --num-inference-retries) nearai benchmark list : List all executed benchmarks (--namespace, --benchmark, --solver, --args, --total, --offset)
Examples:
Run a benchmark on a dataset with a solver strategy¶
nearai benchmark run my-dataset my-solver-strategy --max-concurrent 4 --force
List benchmark results filtered by namespace¶
nearai benchmark list --namespace my-namespace --benchmark my-benchmark --total 50
Source code in nearai/cli.py
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 |
|
__call__ ¶
__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,
) -> None
List all executed benchmarks.
This command displays a table of all executed benchmarks, with options to filter by namespace, benchmark name, solver name, and solver arguments. Results are paginated using limit and offset parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
namespace | str) | Filter results by namespace | None |
benchmark | str) | Filter results by benchmark name | None |
solver | str) | Filter results by solver name | None |
args | str) | Filter results by solver arguments (JSON string) | None |
total | int) | Maximum number of results to display | 32 |
offset | int) | Number of results to skip | 0 |
Examples:
List all benchmarks with default pagination¶
nearai benchmark list
Filter by namespace and benchmark name¶
nearai benchmark list --namespace my-namespace --benchmark-name my-benchmark
Filter by solver with custom pagination¶
nearai benchmark list --solver-name my-solver --limit 20 --offset 40
Filter by solver arguments¶
nearai benchmark list --solver-args '{"arg1": "value1"}'
Documentation
https://docs.near.ai/models/benchmarks_and_evaluations/
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.
This command executes a benchmark on a specified dataset using a given solver strategy. Results are cached in the database for subsequent runs unless --force is used.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset | str) | Name of the dataset to benchmark against | required |
solver_strategy | str) | Name of the solver strategy to use | required |
max_concurrent | int) | Maximum number of concurrent runs (-1 for CPU count) | 2 |
force | bool) | Force re-running the benchmark and update cache | False |
subset | str) | Optional subset of the dataset to use | None |
check_compatibility | bool) | Whether to check solver-dataset compatibility | True |
record | bool) | Whether to record detailed benchmark results | False |
num_inference_retries | int) | Number of retries for inference operations | 10 |
**solver_args | (dict) Additional arguments passed to the solver strategy | {} |
Examples:
Run a benchmark with default settings¶
nearai benchmark run my-dataset my-solver-strategy
Run with custom concurrency and force update¶
nearai benchmark run my-dataset my-solver-strategy --max-concurrent 4 --force
Run on a subset with custom solver arguments¶
nearai benchmark run my-dataset my-solver-strategy --subset train --arg1 value1 --arg2 value2
Documentation
https://docs.near.ai/models/benchmarks_and_evaluations/
Source code in nearai/cli.py
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 |
|
CLI ¶
List of commands for NEAR AI CLI to be used in the help menu.
Getting Started
nearai CLI MAIN MENU HELP nearai login Authenticate with your NEAR account nearai logout Clear your NEAR account authentication data nearai version Display the current version of the CLI nearai location Show the installation location of the CLI
Agent Development
nearai agent AGENT HELP MENU nearai agent create Create a new agent or fork an existing one nearai agent upload Upload an agent to the NEAR AI agent registry nearai agent interactive Run an agent interactively nearai agent task Run a single task with an agent nearai agent dev Run local UI for development of agents nearai agent inspect Inspect environment from given path
Registry Management
nearai registry REGISTRY HELP MENU nearai registry upload Upload an item to the registry nearai registry download Download an item from the registry nearai registry info Show information about a registry item nearai registry list List available items in the registry nearai registry update Update the remote version in an agent's metadata.json file nearai registry metadata-template Create a metadata template nearai permission PERMISSION HELP MENU (manage access control)
Model Operations
nearai benchmark run Run benchmark on a dataset with a solver strategy nearai benchmark list List all executed benchmarks nearai evaluation table Print table of evaluations nearai finetune Commands for fine-tuning modelsnear nearai tensorboard Commands for TensorBoard integration nearai vllm run Run VLLM server with OpenAI-compatible API nearai hub chat Chat with model from NEAR AI hub
Configuration
nearai config CONFIG HELP MENU nearai config set Set a configuration value nearai config get Get a configuration value nearai config show Show all configuration values
Source code in nearai/cli.py
2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 |
|
help ¶
location ¶
submit ¶
Submit a task to be executed by a worker.
Source code in nearai/cli.py
task ¶
ConfigCli ¶
Configuration commands help you manage your NEAR AI CLI settings.
You can view, set, and modify various configuration values that control how the CLI behaves.
Commands
nearai config set : Add or update a configuration value (key*, value*, --local) nearai config get : Retrieve a configuration value (key*) nearai config show : Display all configuration values
Examples:
View all configuration values¶
nearai config show
Get a specific configuration value¶
nearai config get api_url
Set a configuration value (globally)¶
nearai config set model claude-3-opus-20240229
Set a configuration value (locally for current project)¶
nearai config set model claude-3-opus-20240229 --local
Change the API URL¶
nearai config set api_url https://custom-api.example.com
Source code in nearai/cli.py
EvaluationCli ¶
Commands for evaluating and analyzing model performance on benchmark datasets.
Commands
nearai evaluation table : Print table of evaluations (--all-key-columns, --all-metrics, --num-columns, --metric-name-max-length) nearai evaluation read_solutions : Read solutions.json from evaluation entry (entry*, --status, --verbose)
Examples:
Display evaluation table with default settings¶
nearai evaluation table
Display evaluation table with all metrics and columns¶
nearai evaluation table --all-key-columns --all-metrics --num-columns 10
Read solutions from an evaluation entry¶
nearai evaluation read_solutions example.near/benchmark-result/0.1.0
Read only successful solutions with verbose output¶
nearai evaluation read_solutions example.near/benchmark-result/0.1.0 --status true --verbose
Documentation: https://docs.near.ai/models/benchmarks_and_evaluations/
Source code in nearai/cli.py
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 |
|
__call__ ¶
read_solutions ¶
Reads and displays the solutions.json file from a specified evaluation entry.
It can filter solutions by status and show either concise or verbose output for each solution.
entry (str) : Evaluation entry to read solutions from (format: namespace/name/version) status (Optional[bool]) : Filter solutions by status (true/false) verbose (bool) : Show verbose information including detailed logs
Examples:
# Read all solutions from an evaluation entry
nearai evaluation read_solutions example.near/benchmark-result/0.1.0
# Read only successful solutions
nearai evaluation read_solutions example.near/benchmark-result/0.1.0 --status true
# Read solutions with verbose output
nearai evaluation read_solutions example.near/benchmark-result/0.1.0 --verbose
Documentation
https://docs.near.ai/models/benchmarks_and_evaluations/
Source code in nearai/cli.py
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 |
|
table ¶
table(
all_key_columns: bool = False,
all_metrics: bool = False,
num_columns: int = 6,
metric_name_max_length: int = 30,
) -> None
Displays a table of all evaluation results, with options to customize the display of columns and metrics.
The table can be configured to show all key columns and metrics, or a limited subset for better readability.
all_key_columns (bool) : Show all key columns in the table instead of just the important ones. Default is False. all_metrics (bool) : Show all available metrics instead of just the default subset. Default is False. num_columns (int) : Maximum number of columns to display in the table. metric_name_max_length (int) : Maximum length for metric names in the display.
Examples:
# Display evaluation table with default settings
nearai evaluation table
# Show all available columns and metrics
nearai evaluation table --all-key-columns --all-metrics
# Customize table display
nearai evaluation table --num-columns 8 --metric-name-max-length 40
Documentation
https://docs.near.ai/models/benchmarks_and_evaluations/
Source code in nearai/cli.py
HubCLI ¶
Interact with models hosted on the NEAR AI hub.
Commands
nearai hub chat : Chat with model from NEAR AI hub (--query, --model, --provider, --endpoint, --info)
Examples:
Chat with the default model¶
nearai hub chat --query "Explain quantum computing in simple terms"
Chat with a specific model from a provider¶
nearai hub chat --query "Write a limerick about AI" --model claude-3-opus-20240229 --provider fireworks
Display system information about the request¶
nearai hub chat --query "Tell me a joke" --info
Source code in nearai/cli.py
1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 |
|
__call__ ¶
chat ¶
Chat with a model from the NEAR AI hub.
This command allows you to interact with language models hosted on the NEAR AI hub. You can specify which model to use, which provider to use, and customize the chat experience with various parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs | (dict) Keyword arguments that can include: query (str): User's query to send to the model model (str): Name of the model to use provider (str): Name of the provider (e.g., "fireworks", "hyperbolic") endpoint (str): NEAR AI Hub's URL to connect to info (bool): Display system information about the request Additional parameters passed to the model | {} |
Examples:
Chat with the default model¶
nearai hub chat --query "Explain quantum computing in simple terms"
Chat with a specific model from a provider¶
nearai hub chat --query "Write a limerick about AI" --model claude-3-opus-20240229 --provider hyperbolic
Display system information about the request¶
nearai hub chat --query "Tell me a joke" --info
Chat with a model using a custom endpoint¶
nearai hub chat --query "Summarize this text" --endpoint https://custom-hub.example.com
Source code in nearai/cli.py
LoginCLI ¶
Commands for authenticating with your NEAR account for accessing NEAR AI services.
Commands
nearai login : Login with NEAR Mainnet account (--remote, --auth_url, --accountId, --privateKey) nearai login status : Display login status and auth details nearai login save : Save NEAR account auth data (--accountId, --signature, --publicKey, --callbackUrl, --nonce)
Examples:
Login using web-based flow¶
nearai login
Login using credentials from .near-credentials¶
nearai login --accountId your-account.near
Login with direct key (less secure, use with caution)¶
nearai login --accountId your-account.near --privateKey ed25519:YOUR_PRIVATE_KEY
Check current login status¶
nearai login status
Source code in nearai/cli.py
1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 |
|
__call__ ¶
Login with NEAR Mainnet account.
Source code in nearai/cli.py
save ¶
Save NEAR account authorization data.
kwargs (dict) :
Keyword arguments that can include:
accountId (str) :
Near Account ID
signature (str) :
Signature
publicKey (str) :
Public Key used to sign the message
callbackUrl (str) :
Callback Url
nonce (str) :
Nonce
Source code in nearai/cli.py
LogoutCLI ¶
Clear your NEAR account authentication data from the local configuration.
Commands
nearai logout : Logout and remove authentication data
Examples:
Remove authentication data¶
nearai logout
Source code in nearai/cli.py
__call__ ¶
Clear NEAR account auth data.
Source code in nearai/cli.py
PermissionCli ¶
Commands for managing permissions and access control for NEAR AI resources.
Commands
nearai permission grant : Grant permission to an account (account_id*, permission*) nearai permission revoke : Revoke permission from an account (account_id*, --permission)
Examples:
Grant model access permission to an account¶
nearai permission grant alice.near model_access
Grant multiple permissions (run multiple commands)¶
nearai permission grant bob.near agent_creation nearai permission grant bob.near model_access
Revoke a specific permission¶
nearai permission revoke charlie.near model_access
Revoke all permissions from an account¶
nearai permission revoke dave.near
Source code in nearai/cli.py
2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 |
|
__call__ ¶
grant ¶
Grant a specific permission to a NEAR account.
This command allows you to grant a specific permission to a NEAR account, enabling them to access certain NEAR AI resources or perform specific actions.
account_id : (str) The NEAR account ID to grant the permission to permission : (str) The permission to grant (e.g., 'model_access', 'agent_creation')
Examples:
# Grant model access permission to an account
nearai permission grant alice.near model_access
# Grant agent creation permission
nearai permission grant bob.near agent_creation
# Grant evaluation access permission
nearai permission grant charlie.near evaluation_access
Source code in nearai/cli.py
revoke ¶
Revoke permissions from a NEAR account.
If no permission is specified, all permissions will be revoked from the account.
account_id : (str)
The NEAR account ID to revoke the permission from
permission : (str)
The permission to revoke (optional, if empty all permissions are revoked)
Examples:
# Revoke a specific permission
nearai permission revoke alice.near model_access
# Revoke all permissions from an account
nearai permission revoke bob.near
# Revoke agent creation permission
nearai permission revoke charlie.near agent_creation
Source code in nearai/cli.py
RegistryCli ¶
Manage items in the NEAR AI Registry including agents, models, datasets, and evaluations.
These commands allow you to upload, download, update, and list available items in the NEAR AI Registry.
Commands
nearai registry upload : Upload an item to the registry (
Examples:
Upload an agent to the registry¶
nearai registry upload ./path/to/agent
Download an agent from the registry¶
nearai registry download example.near/agent-name/0.0.3
Show information about a registry item¶
nearai registry info example.near/agent-name/0.0.3
List items by category¶
nearai registry list --category evaluation
List items with specific tags¶
nearai registry list --tags "vector-store"
Documentation
https://docs.near.ai/agents/registry
Source code in nearai/cli.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 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 |
|
__call__ ¶
download ¶
Download an item from the NEAR AI registry to your local machine.
This allows you to use or inspect agents, models, datasets, etc. that have been published by others.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entry_location | str) | Entry location of the item to download (format: namespace/name/version) | required |
force | bool) | Force download even if the item already exists locally | False |
Examples:
Download a specific registry item¶
nearai registry download example.near/agent-name/0.0.3
Force download an item that already exists locally¶
nearai registry download example.near/model-name/1.0.0 --force
Source code in nearai/cli.py
info ¶
Display detailed information about a registry item.
Includes metadata and available provider matches for models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entry | str) | Entry location of the item to display information for (format: namespace/name/version) | required |
Examples:
Show information about a specific registry item¶
nearai registry info example.near/agent-name/0.0.3
Show information about a model¶
nearai registry info example.near/model-name/1.0.0
Documentation
https://docs.near.ai/agents/registry
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 in the NEAR AI registry.
You can filter the results by namespace, category, tags, and other criteria to find specific items.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
namespace | str) | Filter items by namespace/user account (example.near) | '' |
category | str) | Filter items by category ('agent', 'model', 'evaluation') | '' |
tags | str) | Filter items by tags (comma-separated) | '' |
total | int) | Maximum number of items to show | 32 |
offset | int) | Offset for pagination | 0 |
show_all | bool) | Show all versions of items | False |
show_latest_version | bool) | Show only the latest version of each item | True |
star | str) | Show items starred by a specific user | '' |
Examples:
List all items in the registry¶
nearai registry list
List agents in the registry¶
nearai registry list --category agent
List items with specific tags¶
nearai registry list --tags "summarization,text"
List items from a specific namespace¶
nearai registry list --namespace example.near
Show all versions of items¶
nearai registry list --show-all
Source code in nearai/cli.py
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 |
|
metadata_template ¶
Create a metadata template file for a registry item.
This generates a properly formatted metadata.json file with default values that can be customized for your agent or model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
local_path | str Path to the directory where the metadata template will be created | '.' | |
category | str Category of the item (e.g., 'agent', 'model', 'dataset', 'evaluation') | '' | |
description | str Description of the item | '' |
Examples:
Create a metadata template in the current directory¶
nearai registry metadata-template
Create a metadata template for an agent with description¶
nearai registry metadata-template --category agent --description "My helpful assistant"
Create a metadata template in a specific directory¶
nearai registry metadata-template path/to/directory --category model
Source code in nearai/cli.py
update ¶
Update the remote metadata of an item in the NEAR AI Registry.
Looks for a metadata.json file in the given directory and updates the remote metadata with the new values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
local_path | str) | Path to the directory containing the item to update | '.' |
Examples:
Update metadata for the item in the current directory¶
nearai registry update
Update metadata for a specific item¶
nearai registry update path/to/item
Source code in nearai/cli.py
upload ¶
upload(
local_path: str = ".",
bump: bool = False,
minor_bump: bool = False,
major_bump: bool = False,
) -> Optional[EntryLocation]
Upload an item to the NEAR AI registry for public use.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
local_path | str) | Path to the agent directory | '.' |
bump | bool) | Automatically increment patch version if it already exists | False |
minor_bump | bool) | Bump with minor version increment (0.1.0 → 0.2.0) | False |
major_bump | bool) | Bump with major version increment (1.5.2 → 2.0.0) | False |
Examples:
Upload an item in the current directory¶
nearai registry upload
Upload a specific agent directory¶
nearai registry upload --local-path ./path/to/item
Upload with automatic version bumping¶
nearai registry upload --bump
Upload with minor version bump¶
nearai registry upload ./path/to/item --minor-bump
Source code in nearai/cli.py
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 |
|
upload_unregistered_common_provider_models ¶
Create new registry items for unregistered common provider models.
This command helps keep the registry up-to-date with the latest models from various providers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dry_run | bool) | Perform a dry run without actually uploading | True |
Examples:
Perform a dry run to see what would be uploaded¶
nearai registry upload-unregistered-common-provider-models
Actually upload the unregistered models¶
nearai registry upload-unregistered-common-provider-models --dry-run=False
Source code in nearai/cli.py
VllmCli ¶
Commands for running VLLM server with OpenAI-compatible API for local inference.
Commands
nearai vllm run : Run VLLM server with OpenAI-compatible API (--model, --host, --port, --tensor-parallel-size, --gpu-memory-utilization)
Examples:
Run VLLM server with default settings¶
nearai vllm run --model mistralai/Mistral-7B-Instruct-v0.1
Run VLLM server with custom host and port¶
nearai vllm run --model meta-llama/Llama-2-7b-chat-hf --host 0.0.0.0 --port 8080
Run with multiple GPUs and specific memory utilization¶
nearai vllm run --model meta-llama/Llama-2-13b-chat-hf --tensor-parallel-size 2 --gpu-memory-utilization 0.8
Source code in nearai/cli.py
1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 |
|
__call__ ¶
run ¶
Run a VLLM server with an OpenAI-compatible API for local inference.
This command starts a VLLM server that provides an OpenAI-compatible API for running language models locally. The server supports various configuration options for optimizing performance and resource utilization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs | (dict) Keyword arguments that can include: model (str): Path to the model or model name from Hugging Face host (str): Host to bind the server to port (int): Port to bind the server to tensor_parallel_size (int): Number of GPUs to use for tensor parallelism gpu_memory_utilization (float): Fraction of GPU memory to use | {} |
Examples:
Run VLLM server with default settings¶
nearai vllm run --model mistralai/Mistral-7B-Instruct-v0.1
Run VLLM server with custom host and port¶
nearai vllm run --model meta-llama/Llama-2-7b-chat-hf --host 0.0.0.0 --port 8080
Run with multiple GPUs and specific memory utilization¶
nearai vllm run --model meta-llama/Llama-2-13b-chat-hf --tensor-parallel-size 2 --gpu-memory-utilization 0.8
Run with additional VLLM configuration¶
nearai vllm run --model mistralai/Mistral-7B-Instruct-v0.1 --max-model-len 4096 --dtype float16
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
main ¶
Main entry point for the NEAR AI CLI.
Source code in nearai/cli.py
cli_help ¶
_display_commands_section ¶
Display the commands section in a table.
console: Rich console for display
sections: Parsed sections dictionary
Source code in nearai/cli_help.py
_display_description_section ¶
Display the description section in a panel.
console: Rich console for display
sections: Parsed sections dictionary
Source code in nearai/cli_help.py
_display_documentation_section ¶
Display documentation section.
console: Rich console for display
sections: Parsed sections dictionary
Source code in nearai/cli_help.py
_display_examples_section ¶
Display examples section in a panel.
console: Rich console for display
sections: Parsed sections dictionary
Source code in nearai/cli_help.py
_display_param_section ¶
_display_param_section(
console: Console,
sections: Dict[str, List[str]],
section_name: str,
section_title: str,
param_pattern: str,
obj: Any = None,
method_name: str = "__class__",
) -> None
Display a parameter section (Args or Options) in a table.
console: Rich console for display
sections: Parsed sections dictionary
section_name: Name of the section in the sections dict
section_title: Title to display for the section
param_pattern: Regex pattern to match parameter definitions
obj: The object containing the method to inspect
method_name: The name of the method to inspect, or "__class__" for class docstring
Source code in nearai/cli_help.py
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 |
|
_extract_basic_metadata ¶
_extract_basic_metadata(
obj: Any, method_name: str, console: Console
) -> Tuple[bool, Optional[str], str]
Extract basic metadata from the object or method.
obj: The object containing the docstring
method_name: Name of the method or "__class__" for class docstring
console: Console for error printing
Tuple of (is_class, docstring, display_name)
Source code in nearai/cli_help.py
_extract_description_section ¶
Extract the description section from docstring lines.
The description is the first part of the docstring until the first section header or double blank line.
lines: Lines of the docstring
List of description lines
Source code in nearai/cli_help.py
_parse_command_options ¶
Parse options for a command from the following lines.
lines: All command lines
current_index: Current position in the lines
Tuple of (options_string, next_index)
Source code in nearai/cli_help.py
_parse_docstring_sections ¶
Parse a docstring into sections.
docstring: The docstring to parse
Dictionary mapping section names to content lines
Source code in nearai/cli_help.py
_parse_param_description ¶
_parse_param_description(
section_lines: List[str],
current_index: int,
param_pattern: str,
) -> Tuple[str, int]
Parse the description lines for a parameter.
section_lines: Lines in the current section
current_index: Current position in the lines
param_pattern: Pattern to identify parameter definitions
Tuple of (description_text, next_index)
Source code in nearai/cli_help.py
format_help ¶
Format a class or method's docstring as a help message and display it with rich formatting.
obj : Any
The object containing the docstring (class or method)
method_name : str
The name of the method to format, or "__class__" to format the class's docstring
Source code in nearai/cli_help.py
generate_main_cli_help ¶
generate_main_cli_help(cli: CLI) -> None
Format the main CLI menu help display.
cli: The CLI class instance
Source code in nearai/cli_help.py
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 |
|
get_docstring_info ¶
get_docstring_info(
obj, method_name: str = "__class__"
) -> Tuple[
Optional[str],
Optional[str],
bool,
Optional[Dict[str, List[str]]],
]
Get the docstring, command title, and parsed sections for a class or method.
obj : Any
The object containing the docstring (class or method)
method_name : str
The name of the method to format, or "__class__" to format the class's docstring
Tuple of (docstring, command_title, is_class, sections)
Source code in nearai/cli_help.py
handle_help_request ¶
Common handler for CLI help requests.
args (Optional[List[str]]) :
Command line arguments (uses sys.argv if None)
bool : True if help was displayed, False otherwise
Source code in nearai/cli_help.py
cli_helpers ¶
assert_user_auth ¶
Ensure the user is authenticated.
Raises¶
SystemExit: If the user is not authenticated
Source code in nearai/cli_helpers.py
display_agents_in_columns ¶
Display agents in a rich table format.
agents: List of Path objects pointing to agent locations (pre-sorted)
Source code in nearai/cli_helpers.py
display_version_check ¶
Display formatted message about version existence check.
namespace: The namespace
name: The agent name
version: The version being checked
exists: Whether the version exists
Source code in nearai/cli_helpers.py
has_pending_input ¶
Check if there's input waiting to be read without blocking.
Source code in nearai/cli_helpers.py
load_and_validate_metadata ¶
load_and_validate_metadata(
metadata_path: Path,
) -> Tuple[Optional[Dict[str, Any]], Optional[str]]
Load and validate metadata file, including version format.
metadata_path: Path to metadata.json file
Tuple of (metadata_dict, error_message)
Source code in nearai/cli_helpers.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
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 |
|
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
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 |
|
__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. Files matching patterns in .gitignore (if present) will be excluded from upload.
Source code in nearai/registry.py
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 |
|
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
check_version_exists ¶
Check if a version already exists in the registry.
namespace: The namespace
name: The agent name
version: The version to check
Tuple of (exists, error)
If exists is True, the version exists
If error is not None, an error occurred during checking
Source code in nearai/registry.py
get_namespace ¶
Returns namespace of an item or user namespace.
Source code in nearai/registry.py
get_registry_folder ¶
increment_version_by_type ¶
Increment version according to PEP 440.
version: Current version string
increment_type: Type of increment ('major', 'minor', or 'patch')
New version string
ValueError: If increment_type is invalid or version is invalid
Source code in nearai/registry.py
resolve_local_path ¶
Determines if the local_path
is local_path
or registry_folder/local_path
.
Raises FileNotFoundError if folder or parent folder is not present.
Source code in nearai/registry.py
validate_version ¶
Validate version string according to PEP 440.
version: Version string to validate
Tuple of (is_valid, error_message)
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
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 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 |
|
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_subthread ¶
create_subthread(
thread_id: str,
messages_to_copy: Optional[List[str]] = None,
new_messages: Optional[
List[ChatCompletionMessageParam]
] = None,
)
Create a subthread.
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,
StaticFileChunkingStrategyObjectParam,
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
find_agents ¶
find_agents(
owner_id: Optional[str] = None,
with_capabilities: Optional[bool] = False,
latest_versions_only: Optional[bool] = True,
limit: Optional[int] = None,
offset: Optional[int] = None,
)
Filter agents.
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_thread ¶
get_vector_store ¶
Gets a vector store by id.
Source code in nearai/shared/inference_client.py
get_vector_store_files ¶
Adds a file to vector store.
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
remove_file ¶
run_agent ¶
run_agent(
run_on_thread_id: str,
assistant_id: str,
parent_run_id: str = "",
run_mode: RunMode = SIMPLE,
)
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
set_provider_models ¶
set_provider_models(
provider_models: Optional[ProviderModels],
)
Set provider models. Used by external caching.
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: Optional[str] = "utf-8",
file_name: Optional[str] = "file.txt",
file_type: Optional[str] = "text/plain",
) -> Optional[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. Strips '.near' extensions. 3. Convert '.' between digits to 'p'. 4. 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 ¶
validate_completion_signature(
public_key: str,
signature: str,
payload: CompletionSignaturePayload,
)
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" 7. provider base url/model-name, e.g. "https://api.openai.com/v1::gpt-4o"
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
secure_openai_clients ¶
SecureAsyncOpenAI ¶
Secure Async OpenAI client where api key is only accessible in constructor.
Source code in nearai/shared/secure_openai_clients.py
__init__ ¶
Initialize with auth token that's only accessible in constructor.
Source code in nearai/shared/secure_openai_clients.py
SecureOpenAI ¶
Secure OpenAI client where api key is only accessible in constructor.
Source code in nearai/shared/secure_openai_clients.py
__init__ ¶
Initialize with auth token that's only accessible in constructor.
Source code in nearai/shared/secure_openai_clients.py
solvers ¶
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
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 |
|
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 212 213 214 215 216 217 218 219 |
|
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
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
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 |
|
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.
Source code in nearai/tests/test_provider_models.py
test_registry_cli ¶
TestRegistryCliUpload ¶
Tests for the RegistryCli.upload method.
Source code in nearai/tests/test_registry_cli.py
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 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 |
|
test_auto_bump_version ¶
Test auto-increment feature when version already exists.
Source code in nearai/tests/test_registry_cli.py
test_auto_increment_version ¶
Test auto-increment feature when version already exists.
Source code in nearai/tests/test_registry_cli.py
test_invalid_json_metadata ¶
Test upload failure when metadata.json is not valid JSON.
Source code in nearai/tests/test_registry_cli.py
test_major_bump_version ¶
Test major bump feature when version already exists.
Source code in nearai/tests/test_registry_cli.py
test_metadata_file_not_found ¶
Test upload failure when metadata.json is missing.
Source code in nearai/tests/test_registry_cli.py
test_minor_bump_version ¶
Test minor bump feature when version already exists.
Source code in nearai/tests/test_registry_cli.py
test_missing_required_fields ¶
Test upload failure when required fields are missing in metadata.json.
Source code in nearai/tests/test_registry_cli.py
test_not_logged_in ¶
Test upload failure when user is not logged in.
Source code in nearai/tests/test_registry_cli.py
test_other_registry_error ¶
Test upload failure when an unexpected error occurs during registry info check.
Source code in nearai/tests/test_registry_cli.py
test_pep440_version_validation ¶
Test that version validation follows PEP 440 standards.
Source code in nearai/tests/test_registry_cli.py
test_successful_upload ¶
Test successful upload when version doesn't exist.
Source code in nearai/tests/test_registry_cli.py
test_version_already_exists ¶
Test upload failure when version already exists.
Source code in nearai/tests/test_registry_cli.py
mock_config ¶
Mock the CONFIG with auth data.
mock_registry ¶
temp_agent_dir ¶
Create a temporary agent directory with metadata.json.