File size: 59,311 Bytes
64459ea | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 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 | {
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "3bfa7639",
"metadata": {},
"outputs": [],
"source": [
"from dotenv import load_dotenv\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "7f0247e2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"load_dotenv(override = True)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "971f57ca",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"GROQ_API_KEY is set\n"
]
}
],
"source": [
"import os\n",
"groq_api_key = os.getenv(\"GROQ_API_KEY\")\n",
"if groq_api_key:\n",
" print(\"GROQ_API_KEY is set\")\n",
"else:\n",
" print(\"GROQ_API_KEY is not set\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "5bf3ecf7",
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (1639672286.py, line 1)",
"output_type": "error",
"traceback": [
" \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[4]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[31m \u001b[39m\u001b[31mfrom groq Import Groq\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m invalid syntax\n"
]
}
],
"source": [
"from groq Import Groq\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "18dd1ce6",
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'groq'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[5]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mgroq\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Groq\n",
"\u001b[31mModuleNotFoundError\u001b[39m: No module named 'groq'"
]
}
],
"source": [
"from groq import Groq\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c5787a4b",
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'groq'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[6]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mgroq\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Groq\n",
"\u001b[31mModuleNotFoundError\u001b[39m: No module named 'groq'"
]
}
],
"source": [
"from groq import Groq\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3fcd0ab7",
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'groq'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[7]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mgroq\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Groq\n\u001b[32m 3\u001b[39m client = Groq()\n\u001b[32m 4\u001b[39m completion = client.chat.completions.create(\n\u001b[32m 5\u001b[39m model=\u001b[33m\"\u001b[39m\u001b[33mopenai/gpt-oss-120b\u001b[39m\u001b[33m\"\u001b[39m,\n\u001b[32m 6\u001b[39m messages=[\n\u001b[32m (...)\u001b[39m\u001b[32m 17\u001b[39m stop=\u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[32m 18\u001b[39m )\n",
"\u001b[31mModuleNotFoundError\u001b[39m: No module named 'groq'"
]
}
],
"source": [
"from groq import Groq\n",
"\n",
"client = Groq()\n",
"completion = client.chat.completions.create(\n",
" model=\"openai/gpt-oss-120b\",\n",
" messages=[\n",
" {\n",
" \"role\": \"user\",\n",
" \"content\": \"\"\n",
" }\n",
" ],\n",
" temperature=1,\n",
" max_completion_tokens=8192,\n",
" top_p=1,\n",
" reasoning_effort=\"medium\",\n",
" stream=True,\n",
" stop=None\n",
")\n",
"\n",
"for chunk in completion:\n",
" print(chunk.choices[0].delta.content or \"\", end=\"\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "29acbb6d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"c:\\Users\\govindh vaila\\projects\\agents\\.venv\\Scripts\\python.exe\n"
]
}
],
"source": [
"import sys\n",
"print(sys.executable)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e57a2404",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"'c:\\Users\\govindh' is not recognized as an internal or external command,\n",
"operable program or batch file.\n"
]
}
],
"source": [
"import sys\n",
"!{sys.executable} -m pip install groq"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "35374ec1",
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'groq'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[10]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mgroq\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Groq\n",
"\u001b[31mModuleNotFoundError\u001b[39m: No module named 'groq'"
]
}
],
"source": [
"from groq import Groq\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9a722979",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Note: you may need to restart the kernel to use updated packages.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\govindh vaila\\projects\\agents\\.venv\\Scripts\\python.exe: No module named pip\n"
]
}
],
"source": [
"%pip install groq\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "04f22594",
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'groq'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mgroq\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Groq\n",
"\u001b[31mModuleNotFoundError\u001b[39m: No module named 'groq'"
]
}
],
"source": [
"from groq import Groq\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "eea60e94",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"c:\\Users\\govindh vaila\\projects\\agents\\.venv\\Scripts\\python.exe\n"
]
}
],
"source": [
"import sys\n",
"print(sys.executable)\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "4a341d20",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"c:\\Users\\govindh vaila\\projects\\agents\\.venv\\Scripts\\python.exe\n"
]
}
],
"source": [
"import sys\n",
"print(sys.executable)\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "c543e1f1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"works\n"
]
}
],
"source": [
"from groq import Groq\n",
"print(\"works\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "4c33500f",
"metadata": {},
"outputs": [],
"source": [
"groq=Groq()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "5f9ef82e",
"metadata": {},
"outputs": [
{
"ename": "BadRequestError",
"evalue": "Error code: 400 - {'error': {'message': 'The model `whisper-large-v3` does not support chat completions', 'type': 'invalid_request_error'}}",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mBadRequestError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[9]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m 1\u001b[39m messages=[{\u001b[33m'\u001b[39m\u001b[33mrole\u001b[39m\u001b[33m'\u001b[39m:\u001b[33m'\u001b[39m\u001b[33muser\u001b[39m\u001b[33m'\u001b[39m,\u001b[33m'\u001b[39m\u001b[33mcontent\u001b[39m\u001b[33m'\u001b[39m: \u001b[33m'\u001b[39m\u001b[33mwhat is the capital of india?\u001b[39m\u001b[33m'\u001b[39m}]\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m response=\u001b[43mgroq\u001b[49m\u001b[43m.\u001b[49m\u001b[43mchat\u001b[49m\u001b[43m.\u001b[49m\u001b[43mcompletions\u001b[49m\u001b[43m.\u001b[49m\u001b[43mcreate\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 3\u001b[39m \u001b[43m \u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m=\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mwhisper-large-v3\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m 4\u001b[39m \u001b[43m \u001b[49m\u001b[43mmessages\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmessages\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 5\u001b[39m \u001b[43m \u001b[49m\u001b[43mmax_tokens\u001b[49m\u001b[43m=\u001b[49m\u001b[32;43m8192\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m 6\u001b[39m \u001b[43m \u001b[49m\u001b[43mtemperature\u001b[49m\u001b[43m=\u001b[49m\u001b[32;43m0.5\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m 7\u001b[39m \u001b[43m)\u001b[49m\n\u001b[32m 8\u001b[39m \u001b[38;5;28mprint\u001b[39m(response.choices[\u001b[32m0\u001b[39m].message.content)\n",
"\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\govindh vaila\\projects\\agents\\.venv\\Lib\\site-packages\\groq\\resources\\chat\\completions.py:461\u001b[39m, in \u001b[36mCompletions.create\u001b[39m\u001b[34m(self, messages, model, citation_options, compound_custom, disable_tool_validation, documents, exclude_domains, frequency_penalty, function_call, functions, include_domains, include_reasoning, logit_bias, logprobs, max_completion_tokens, max_tokens, metadata, n, parallel_tool_calls, presence_penalty, reasoning_effort, reasoning_format, response_format, search_settings, seed, service_tier, stop, store, stream, temperature, tool_choice, tools, top_logprobs, top_p, user, extra_headers, extra_query, extra_body, timeout)\u001b[39m\n\u001b[32m 241\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mcreate\u001b[39m(\n\u001b[32m 242\u001b[39m \u001b[38;5;28mself\u001b[39m,\n\u001b[32m 243\u001b[39m *,\n\u001b[32m (...)\u001b[39m\u001b[32m 300\u001b[39m timeout: \u001b[38;5;28mfloat\u001b[39m | httpx.Timeout | \u001b[38;5;28;01mNone\u001b[39;00m | NotGiven = not_given,\n\u001b[32m 301\u001b[39m ) -> ChatCompletion | Stream[ChatCompletionChunk]:\n\u001b[32m 302\u001b[39m \u001b[38;5;250m \u001b[39m\u001b[33;03m\"\"\"\u001b[39;00m\n\u001b[32m 303\u001b[39m \u001b[33;03m Creates a model response for the given chat conversation.\u001b[39;00m\n\u001b[32m 304\u001b[39m \n\u001b[32m (...)\u001b[39m\u001b[32m 459\u001b[39m \u001b[33;03m timeout: Override the client-level default timeout for this request, in seconds\u001b[39;00m\n\u001b[32m 460\u001b[39m \u001b[33;03m \"\"\"\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m461\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_post\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 462\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m/openai/v1/chat/completions\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m 463\u001b[39m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmaybe_transform\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 464\u001b[39m \u001b[43m \u001b[49m\u001b[43m{\u001b[49m\n\u001b[32m 465\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mmessages\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmessages\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 466\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mmodel\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 467\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mcitation_options\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mcitation_options\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 468\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mcompound_custom\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mcompound_custom\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 469\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mdisable_tool_validation\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mdisable_tool_validation\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 470\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mdocuments\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mdocuments\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 471\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mexclude_domains\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mexclude_domains\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 472\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mfrequency_penalty\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mfrequency_penalty\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 473\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mfunction_call\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mfunction_call\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 474\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mfunctions\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mfunctions\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 475\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43minclude_domains\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43minclude_domains\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 476\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43minclude_reasoning\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43minclude_reasoning\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 477\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mlogit_bias\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mlogit_bias\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 478\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mlogprobs\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mlogprobs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 479\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mmax_completion_tokens\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmax_completion_tokens\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 480\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mmax_tokens\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmax_tokens\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 481\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mmetadata\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmetadata\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 482\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mn\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mn\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 483\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mparallel_tool_calls\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mparallel_tool_calls\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 484\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mpresence_penalty\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mpresence_penalty\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 485\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mreasoning_effort\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mreasoning_effort\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 486\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mreasoning_format\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mreasoning_format\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 487\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mresponse_format\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mresponse_format\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 488\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43msearch_settings\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43msearch_settings\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 489\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mseed\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mseed\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 490\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mservice_tier\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mservice_tier\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 491\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mstop\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 492\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mstore\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mstore\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 493\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mstream\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 494\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtemperature\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtemperature\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 495\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtool_choice\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtool_choice\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 496\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtools\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtools\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 497\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtop_logprobs\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtop_logprobs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 498\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtop_p\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtop_p\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 499\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43muser\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43muser\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 500\u001b[39m \u001b[43m \u001b[49m\u001b[43m}\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 501\u001b[39m \u001b[43m \u001b[49m\u001b[43mcompletion_create_params\u001b[49m\u001b[43m.\u001b[49m\u001b[43mCompletionCreateParams\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 502\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 503\u001b[39m \u001b[43m \u001b[49m\u001b[43moptions\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmake_request_options\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 504\u001b[39m \u001b[43m \u001b[49m\u001b[43mextra_headers\u001b[49m\u001b[43m=\u001b[49m\u001b[43mextra_headers\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mextra_query\u001b[49m\u001b[43m=\u001b[49m\u001b[43mextra_query\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mextra_body\u001b[49m\u001b[43m=\u001b[49m\u001b[43mextra_body\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[43m=\u001b[49m\u001b[43mtimeout\u001b[49m\n\u001b[32m 505\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 506\u001b[39m \u001b[43m \u001b[49m\u001b[43mcast_to\u001b[49m\u001b[43m=\u001b[49m\u001b[43mChatCompletion\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 507\u001b[39m \u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[43m=\u001b[49m\u001b[43mstream\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[32m 508\u001b[39m \u001b[43m \u001b[49m\u001b[43mstream_cls\u001b[49m\u001b[43m=\u001b[49m\u001b[43mStream\u001b[49m\u001b[43m[\u001b[49m\u001b[43mChatCompletionChunk\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 509\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\govindh vaila\\projects\\agents\\.venv\\Lib\\site-packages\\groq\\_base_client.py:1284\u001b[39m, in \u001b[36mSyncAPIClient.post\u001b[39m\u001b[34m(self, path, cast_to, body, content, options, files, stream, stream_cls)\u001b[39m\n\u001b[32m 1275\u001b[39m warnings.warn(\n\u001b[32m 1276\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mPassing raw bytes as `body` is deprecated and will be removed in a future version. \u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 1277\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mPlease pass raw bytes via the `content` parameter instead.\u001b[39m\u001b[33m\"\u001b[39m,\n\u001b[32m 1278\u001b[39m \u001b[38;5;167;01mDeprecationWarning\u001b[39;00m,\n\u001b[32m 1279\u001b[39m stacklevel=\u001b[32m2\u001b[39m,\n\u001b[32m 1280\u001b[39m )\n\u001b[32m 1281\u001b[39m opts = FinalRequestOptions.construct(\n\u001b[32m 1282\u001b[39m method=\u001b[33m\"\u001b[39m\u001b[33mpost\u001b[39m\u001b[33m\"\u001b[39m, url=path, json_data=body, content=content, files=to_httpx_files(files), **options\n\u001b[32m 1283\u001b[39m )\n\u001b[32m-> \u001b[39m\u001b[32m1284\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m cast(ResponseT, \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcast_to\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mopts\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[43m=\u001b[49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstream_cls\u001b[49m\u001b[43m=\u001b[49m\u001b[43mstream_cls\u001b[49m\u001b[43m)\u001b[49m)\n",
"\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\govindh vaila\\projects\\agents\\.venv\\Lib\\site-packages\\groq\\_base_client.py:1071\u001b[39m, in \u001b[36mSyncAPIClient.request\u001b[39m\u001b[34m(self, cast_to, options, stream, stream_cls)\u001b[39m\n\u001b[32m 1068\u001b[39m err.response.read()\n\u001b[32m 1070\u001b[39m log.debug(\u001b[33m\"\u001b[39m\u001b[33mRe-raising status error\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m-> \u001b[39m\u001b[32m1071\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;28mself\u001b[39m._make_status_error_from_response(err.response) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[32m 1073\u001b[39m \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[32m 1075\u001b[39m \u001b[38;5;28;01massert\u001b[39;00m response \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m, \u001b[33m\"\u001b[39m\u001b[33mcould not resolve response (should never happen)\u001b[39m\u001b[33m\"\u001b[39m\n",
"\u001b[31mBadRequestError\u001b[39m: Error code: 400 - {'error': {'message': 'The model `whisper-large-v3` does not support chat completions', 'type': 'invalid_request_error'}}"
]
}
],
"source": [
"messages=[{'role':'user','content': 'what is the capital of india?'}]\n",
"response=groq.chat.completions.create(\n",
" model=\"whisper-large-v3\",\n",
" messages=messages,\n",
" max_tokens=8192,\n",
" temperature=0.5,\n",
")\n",
"print(response.choices[0].message.content)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "41655e37",
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'groq' is not defined",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mNameError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[11]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m 1\u001b[39m messages=[{\u001b[33m'\u001b[39m\u001b[33mrole\u001b[39m\u001b[33m'\u001b[39m:\u001b[33m'\u001b[39m\u001b[33muser\u001b[39m\u001b[33m'\u001b[39m,\u001b[33m'\u001b[39m\u001b[33mcontent\u001b[39m\u001b[33m'\u001b[39m: \u001b[33m'\u001b[39m\u001b[33mwhat is the capital of india?\u001b[39m\u001b[33m'\u001b[39m}]\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m response=\u001b[43mgroq\u001b[49m.chat.completions.create(\n\u001b[32m 3\u001b[39m model=\u001b[33m\"\u001b[39m\u001b[33mgroq/compound-mini\u001b[39m\u001b[33m\"\u001b[39m,\n\u001b[32m 4\u001b[39m messages=messages,\n\u001b[32m 5\u001b[39m max_tokens=\u001b[32m8192\u001b[39m,\n\u001b[32m 6\u001b[39m temperature=\u001b[32m0.5\u001b[39m,\n\u001b[32m 7\u001b[39m )\n\u001b[32m 8\u001b[39m \u001b[38;5;28mprint\u001b[39m(response.choices[\u001b[32m0\u001b[39m].message.content)\n",
"\u001b[31mNameError\u001b[39m: name 'groq' is not defined"
]
}
],
"source": [
"messages=[{'role':'user','content': 'what is the capital of india?'}]\n",
"response=groq.chat.completions.create(\n",
" model=\"groq/compound-mini\",\n",
" messages=messages,\n",
" max_tokens=8192,\n",
" temperature=0.5,\n",
")\n",
"print(response.choices[0].message.content)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "4de006df",
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'os' is not defined",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mNameError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m google_api_key= \u001b[43mos\u001b[49m.getenv(\u001b[33m'\u001b[39m\u001b[33mGEMINI_API_KEY\u001b[39m\u001b[33m'\u001b[39m)\n",
"\u001b[31mNameError\u001b[39m: name 'os' is not defined"
]
}
],
"source": [
"google_api_key= os.getenv('GEMINI_API_KEY')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "5e51ff8a",
"metadata": {},
"outputs": [],
"source": [
"import os"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "531274e3",
"metadata": {},
"outputs": [],
"source": [
"google_api_key= os.getenv('GEMINI_API_KEY')\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "f3775084",
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'os' is not defined",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mNameError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m deepseek_api_key=\u001b[43mos\u001b[49m.getenv(\u001b[33m'\u001b[39m\u001b[33mDEEPSEEK_API_KEY\u001b[39m\u001b[33m'\u001b[39m)\n",
"\u001b[31mNameError\u001b[39m: name 'os' is not defined"
]
}
],
"source": [
"deepseek_api_key=os.getenv('DEEPSEEK_API_KEY')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "8772de63",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"deepseek_apikey=os.getenv('DEEPSEEK_API_KEY')\n",
"google_api_key= os.getenv('GEMINI_API_KEY')"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "7573416e",
"metadata": {},
"outputs": [],
"source": [
"from dotenv import load_dotenv"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "9e760898",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"load_dotenv(override= True)\n"
]
},
{
"cell_type": "markdown",
"id": "61b65f25",
"metadata": {},
"source": [
"import os\n",
"from groq import Groq\n",
"\n",
"deepseek_api_key = os.getenv(\"GROQ_API_KEY\")\n",
"client= Groq()\n",
"\n",
"endpoint=client.chat.completions.create(\n",
" model='groq/compound-mini',\n",
" temperature=0.5,\n",
" messages=[{\n",
" 'role':'user',\n",
" 'content' :'what are the natural resources ?'}\n",
" ]\n",
")\n",
"print(endpoint.choices[0].message.content)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "9c3fa94d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"**Natural resources** are materials or substances that exist in nature and can be used by humans with little or no processing. They include everything we rely on for food, water, energy, shelter, clothing, manufacturing, and many other aspects of daily life.\n",
"\n",
"### Main categories\n",
"\n",
"| Category | Renewable (can replenish) | Non‑renewable (finite) |\n",
"|----------|---------------------------|------------------------|\n",
"| **Biotic** (from living things) | • Forests / timber<br>• Fish, wildlife<br>• Crops & livestock | • Fossil fuels (coal, oil, natural gas)<br>• Coal, petroleum, natural gas |\n",
"| **Abiotic** (non‑living) | • Sunlight<br>• Wind<br>• Water (freshwater, rivers, rain) | • Minerals & metals (iron, copper, gold, uranium, bauxite, etc.)<br>• Coal, oil, natural gas |\n",
"| **Atmospheric** | • Air (oxygen, nitrogen) | – |\n",
"\n",
"### Common examples\n",
"\n",
"| Renewable resources | Non‑renewable resources |\n",
"|---------------------|--------------------------|\n",
"| **Air / Oxygen** – essential for respiration | **Coal** – used for electricity and steel |\n",
"| **Water** – drinking, irrigation, industry | **Oil / Petroleum** – fuels, plastics, chemicals |\n",
"| **Sunlight** – solar energy, photosynthesis | **Natural gas** – heating, electricity, chemicals |\n",
"| **Timber / Forests** – wood, paper, habitat | **Uranium** – nuclear power |\n",
"| **Marine life** – fish, seaweed | **Metal ores** – iron, copper, gold, bauxite, etc. |\n",
"| **Soil** – agriculture, construction | **Diamonds** – industrial and gemstone uses |\n",
"| **Wind** – wind power | – |\n",
"\n",
"### Why they matter\n",
"- **Survival:** Air, water, food (plants & animals) are essential for life. \n",
"- **Economy:** Minerals, fossil fuels, and timber drive industry, transportation, and trade. \n",
"- **Energy:** Sunlight, wind, water, and fossil fuels generate electricity and heat. \n",
"- **Culture & Science:** Many resources have cultural significance and are used in research.\n",
"\n",
"In short, natural resources are the **raw, naturally occurring materials**—both living (biotic) and non‑living (abiotic)—that humans extract, manage, and use to meet basic needs, produce goods, and power societies.\n"
]
}
],
"source": [
"import os\n",
"from groq import Groq\n",
"\n",
"deepseek_api_key = os.getenv(\"GROQ_API_KEY\")\n",
"client= Groq()\n",
"\n",
"endpoint=client.chat.completions.create(\n",
" model='groq/compound-mini',\n",
" temperature=0.5,\n",
" messages=[{\n",
" 'role':'user',\n",
" 'content' :'what are the natural resources ?'}\n",
" ]\n",
")\n",
"print(endpoint.choices[0].message.content)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "6b3d7619",
"metadata": {},
"outputs": [],
"source": [
"import os\n"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "290b9c7f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"## Real‑Time Clinical Coding Assistant – An Agentic‑AI Solution \n",
"*(Target: In‑workflow coding suggestions while a provider writes a note)* \n",
"\n",
"--- \n",
"\n",
"### 1️⃣ Vision Statement \n",
"\n",
"> **“Turn every discharge note into a claim‑ready, audit‑proof document the moment the clinician clicks ‘Finish’.”** \n",
"\n",
"The system acts as an **AI‑driven “coding co‑pilot”** that **plans**, **orchestrates**, and **executes** a multi‑step workflow, then **hands the final decision back to the clinician**. The result is ‑ minutes saved per chart, ‑ higher coding accuracy, ‑ fewer claim denials, ‑ and a measurable reduction in clinician burnout.\n",
"\n",
"--- \n",
"\n",
"## 2️⃣ High‑Level Architecture \n",
"\n",
"```\n",
"+-------------------+ +-------------------+ +-------------------+\n",
"| EHR / EMR (FHIR) | <----> | Secure API GW | <----> | Agentic AI Service|\n",
"+-------------------+ +-------------------+ +-------------------+\n",
" | | |\n",
" | | |\n",
" +--------------------------+ | +--------------------------+\n",
" | | |\n",
" v v v\n",
"+---------------+ +----------------+ +----------------+ +-------------------+\n",
"| Orchestrator | | Extraction | | Code‑Mapper | | Compliance Guard |\n",
"| (Planner) | | Engine (LLM+ | | Engine (Rules/ | | (HIPAA, CPT, |\n",
"| | | NER) | | Knowledge) | | payer rules) |\n",
"+---------------+ +----------------+ +----------------+ +-------------------+\n",
" | | | |\n",
" v v v v\n",
"+----------------+ +----------------+ +----------------+ +-------------------+\n",
"| UI Overlay / | | Structured Data| | Suggestion | | Audit & Learning |\n",
"| Clinician Hub | | Puller (Labs, | | Engine (ranked| | Engine (feedback |\n",
"| (EHR‑embedded) | | Meds, Imaging) | | by confidence)| | loop, drift) |\n",
"+----------------+ +----------------+ +----------------+ +-------------------+\n",
"```\n",
"\n",
"*All components run inside a **FIPS‑140‑2‑validated** VPC, communicate over **mutual TLS**, and are logged for **HIPAA audit trails**.*\n",
"\n",
"--- \n",
"\n",
"## 3️⃣ Core Agentic‑AI Modules \n",
"\n",
"| Module | Function | Key Technologies |\n",
"|--------|----------|-------------------|\n",
"| **Orchestrator (Planner)** | Receives “note‑completed” event, creates a **task graph** (extract → map → validate → present). Dynamically decides which external services to call based on note type, payer, and confidence thresholds. | LangChain / CrewAI style planner, OpenAI GPT‑4o / Anthropic Claude‑3.5, custom graph engine (NetworkX). |\n",
"| **Extraction Engine** | Performs **clinical concept extraction** (diagnoses, procedures, devices, labs) from free‑text and from structured EHR resources. Returns spans with provenance (sentence #, timestamp). | LLM‑augmented NER (MedSpaCy + BioClinicalBERT), few‑shot prompting, fallback regex for lab codes. |\n",
"| **Code‑Mapper Engine** | **Deterministic mapping** of extracted concepts to ICD‑10‑CM, CPT, HCPCS, DRG, and payer‑specific modifiers. Applies hierarchy, exclusion rules, and bundling logic. | Knowledge graph (Neo4j) of code sets, rule engine (Drools), OpenAI function calling for ambiguous cases. |\n",
"| **Compliance Guard** | Enforces **HIPAA, payer contracts, state‑level coding policies**; masks PHI before any LLM call; validates that suggested codes meet payer‑specific bundling and sequencing rules. | Policy engine (OPA – Open Policy Agent), token‑level redaction, audit logs. |\n",
"| **Suggestion UI Overlay** | Embedded in the EHR (via SMART on FHIR or native widget). Shows **rank‑ordered suggestions**, confidence scores, and **source snippets** (e.g., “SpO₂ = 88 % → CPT 99291”). Allows **Approve / Edit / Reject** in a single click. | React + TypeScript, FHIR UI components, real‑time WebSocket updates. |\n",
"| **Audit & Learning Engine** | Captures clinician actions (accept/reject/edit), stores them in a **secure data lake**, runs nightly **model‑drift** detection, and triggers **re‑training** or **rule‑update** cycles. | Snowflake / Azure Synapse, MLflow, SageMaker Pipelines, drift detection (Alibi‑Detect). |\n",
"| **Secure API Gateway** | Central point for **authentication (OAuth 2.0 + SMART on FHIR), rate‑limiting, logging, and encryption**. | Kong / Apigee, AWS PrivateLink, AWS KMS for key management. |\n",
"\n",
"--- \n",
"\n",
"## 4️⃣ Data Flow – Step‑by‑Step (Real‑Time Use Case)\n",
"\n",
"1. **Trigger** – Clinician clicks **“Finish Note”** in the EHR → EHR emits a **FHIR `DocumentReference`** event to the API gateway. \n",
"2. **Orchestrator** builds a **plan**: \n",
" - `extract_concepts(note_id)` → `map_codes(concepts)` → `apply_payer_rules(codes)` → `present_suggestions`. \n",
"3. **Extraction Engine** pulls the note text, runs LLM‑augmented NER, returns a JSON list of entities with **source FHIR references** (e.g., LabResult `Observation/1234`). \n",
"4. **Code‑Mapper** queries the **code graph** (Neo4j) and applies **payer‑specific rule sets** (e.g., “If CPT 99291 is used, add modifier -25”). \n",
"5. **Compliance Guard** validates the mapping, redacts any residual PHI, and logs the decision. \n",
"6. **UI Overlay** receives the ranked suggestions via a secure WebSocket, renders them inline next to the note. Clinician **approves** or **edits**. \n",
"7. **Audit Engine** records the action (`approved`, `edited → new code`, `rejected`). If edited, the delta is stored for **continuous learning**. \n",
"8. **Claim Payload** – Approved codes are pushed back to the EHR’s billing module (FHIR `Claim` resource) and to the payer interface. \n",
"\n",
"--- \n",
"\n",
"## 5️⃣ Security & Compliance Blueprint \n",
"\n",
"| Requirement | Implementation |\n",
"|-------------|----------------|\n",
"| **HIPAA‑Breach‑Proof** | All PHI stays **inside the VPC**; any LLM call that needs raw text is performed on **on‑premise LLM** (e.g., Llama 3‑8B‑Chat with encrypted inference) or via **OpenAI’s HIPAA‑covered** endpoint. |\n",
"| **Data Encryption** | Rest‑at‑AES‑256, in‑flight‑TLS 1.3 + mTLS for service‑to‑service calls. |\n",
"| **Access Control** | Role‑based access (RBAC) enforced by OIDC; only “Clinical Documentation” role can invoke the agent. |\n",
"| **Audit Trail** | Immutable CloudTrail / Azure Monitor logs; each suggestion includes `user_id`, `timestamp`, `source_fhir_id`, `confidence`, and final decision. |\n",
"| **Payer‑Specific Rules** | Stored in a **policy store** (OPA) that can be version‑controlled and signed (e.g., using Git‑signed commits). |\n",
"| **Incident Response** | Automated alert on any anomalous API usage (spike in calls, out‑of‑policy code suggestions). |\n",
"\n",
"--- \n",
"\n",
"## 6️⃣ Human‑in‑the‑Loop (HITL) Design \n",
"\n",
"1. **Confidence Threshold UI** – Only codes **≥ 85 %** confidence are shown as “auto‑accept”; lower‑confidence suggestions are highlighted with a **“review required”** badge. \n",
"2. **Rationale Pop‑over** – Click a suggestion → see the exact sentence(s) that triggered it, plus any lab/imaging evidence. \n",
"3. **One‑Click Approval** – A single “✓” inserts the code into the claim; a “✎” opens a quick edit modal. \n",
"4. **Escalation Path** – If a clinician rejects > 3 suggestions in a row, the system surfaces a **“Contact Coding Specialist”** button. \n",
"5. **Feedback Capture** – Every edit is sent back to the **Learning Engine** with a **label** (“false positive”, “missing code”) for supervised fine‑tuning. \n",
"\n",
"--- \n",
"\n",
"## 7️⃣ Continuous Learning & Drift Management \n",
"\n",
"| Activity | Frequency | Tooling |\n",
"|----------|-----------|---------|\n",
"| **Rule‑Set Sync** (CPT/ICD updates) | Weekly pull from CMS & AMA feeds | Python ETL → Neo4j update |\n",
"| **Model Retraining** (NER & LLM prompting) | Monthly (or when drift > 5 %) | SageMaker Pipelines, MLflow tracking |\n",
"| **Drift Detection** (confidence distribution shift) | Daily batch job | Alibi‑Detect, statistical KS test |\n",
"| **Human Review Audits** | Quarterly random sample of 5 % of claims | Internal audit dashboard, export to Excel/PowerBI |\n",
"\n",
"--- \n",
"\n",
"## 8️⃣ Pilot Blueprint \n",
"\n",
"| Phase | Goal | Duration | Key Deliverables |\n",
"|-------|------|----------|------------------|\n",
"| **1️⃣ Discovery & Data Mapping** | Identify a single service line (e.g., **Cardiology discharge**). Map all relevant FHIR resources (Note, Observation, Procedure). | 4 weeks | Data dictionary, API contracts, compliance sign‑off. |\n",
"| **2️⃣ MVP Build** | Implement end‑to‑end flow for **ICD‑10‑CM + CPT** only, with static rule set. | 8 weeks | Working UI overlay in a sandbox EHR, logging pipeline, basic audit dashboard. |\n",
"| **3️⃣ Validation & Safety** | Run **dual‑run**: AI suggestions **parallel** to existing manual coding for 2 weeks. Measure **agreement** and **false‑positive rate**. | 2 weeks | Accuracy report (target ≥ 90 % match), revised confidence thresholds. |\n",
"| **4️⃣ Live Pilot** | Deploy to **10 clinicians** in the chosen department. Capture **time‑saved**, **denial reduction**, **user satisfaction**. | 6 weeks | KPI dashboard (time per note, claim denial %), NPS score. |\n",
"| **5️⃣ Scale‑Readiness** | Incorporate **payer‑specific modifiers**, extend to **DRG** for inpatient stays, add **auto‑billing** push. | 8 weeks | Full rule engine, multi‑payer support, documentation for IT ops. |\n",
"\n",
"**Success Metrics (to be reported after 6‑week live pilot)** \n",
"\n",
"| KPI | Baseline | Target | Measurement |\n",
"|-----|----------|--------|--------------|\n",
"| Avg. chart‑completion → coded claim time | 22 min | ≤ 14 min (≈ 35 % reduction) | Timestamp diff in EHR logs |\n",
"| Coding accuracy (vs. audit) | 84 % | ≥ 93 % | Random chart audit (n = 200) |\n",
"| Claim denial rate (target service line) | 12 % | ≤ 6 % | Billing system denial reports |\n",
"| Clinician “coding fatigue” score (survey) | 4.2/5 (high) | ≤ 2.8/5 | 5‑point Likert post‑pilot |\n",
"| ROI (per‑provider) | $0 | ≥ $12k/yr (based on time saved & extra capture) | Salary cost + additional revenue |\n",
"\n",
"--- \n",
"\n",
"## 9️⃣ Operational & Governance Model \n",
"\n",
"| Role | Responsibility |\n",
"|------|----------------|\n",
"| **Product Owner (Clinical Ops)** | Prioritise coding rules, define KPIs, manage clinician feedback. |\n",
"| **AI Engineering Lead** | Maintain Orchestrator, LLM prompts, model versioning, drift pipeline. |\n",
"| **Compliance Officer** | Review policy updates, audit logs, ensure HIPAA & payer contracts are met. |\n",
"| **EHR Integration Team** | Manage SMART‑on‑FHIR app registration, UI embedding, API versioning. |\n",
"| **Clinical Coding Specialist** | Curate rule base, adjudicate edge‑case disagreements, supervise learning data. |\n",
"| **Data Security Engineer** | VPC hardening, key management, incident‑response playbooks. |\n",
"\n",
"--- \n",
"\n",
"## 10️⃣ Technology Stack Summary \n",
"\n",
"| Layer | Preferred Tech (AWS‑centric) |\n",
"|-------|------------------------------|\n",
"| **Compute** | Amazon ECS (Fargate) for stateless services, EC2 GPU instances for on‑prem LLM inference (if needed). |\n",
"| **LLM** | OpenAI GPT‑4o (HIPAA‑covered) **or** on‑prem Llama 3‑8B‑Chat with NVIDIA T4 GPUs (encrypted at rest). |\n",
"| **Knowledge Graph** | Neo4j Aura (managed) storing ICD‑10, CPT hierarchies, payer rule edges. |\n",
"| **Rule Engine** | Drools (Java) + OPA policies (JSON‑OPA). |\n",
"| **Data Lake** | Amazon S3 (object lock, SSE‑KMS). |\n",
"| **Orchestration** | AWS Step Functions +\n"
]
}
],
"source": [
"from dotenv import load_dotenv\n",
"import os\n",
"\n",
"load_dotenv()\n",
"\n",
"groq_api=os.getenv(\"GROQ_API_KEY\")\n",
"\n",
"from groq import Groq\n",
"\n",
"\n",
"client=Groq()\n",
"response=client.chat.completions.create(\n",
" model='groq/compound-mini',\n",
" temperature=1.4,\n",
" messages=[{\n",
" 'role':'user',\n",
" 'content':'pick a business area that might be worth exploring for an Agentic AI opportunity'\n",
" }]\n",
")\n",
"bussiness_idea=response.choices[0].message.content\n",
"response=client.chat.completions.create(\n",
" model='groq/compound-mini',\n",
" temperature=0.8,\n",
" messages=[{\n",
" 'role':'user',\n",
" 'content':f\"\"\"\n",
" bussiness_idea={bussiness_idea}\n",
" present a pain-point in that industry - something challenging that might be ripe for an Agentic solution\"\"\"\n",
" }]\n",
")\n",
"pinpoint=response.choices[0].message.content\n",
"response=client.chat.completions.create(\n",
" model='openai/gpt-oss-120b',\n",
" temperature=0.8,\n",
" messages=[{\n",
" 'role':'user',\n",
" 'content':f\"\"\"\n",
" bussiness_idea={bussiness_idea}\n",
" pinpoint={pinpoint}\n",
" propose the Agentic AI solution\"\"\"\n",
" }]\n",
") \n",
"solution=response.choices[0].message.content\n",
"print(solution)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "cd0c55e6",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"google_api=os.getenv(\"GOOGLE_API_KEY\")\n",
"if google_api:\n",
" print(\"hello , all set\")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "d3d722e8",
"metadata": {},
"outputs": [
{
"ename": "GroqError",
"evalue": "The api_key client option must be set either by passing api_key to the client or by setting the GROQ_API_KEY environment variable",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mGroqError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[9]\u001b[39m\u001b[32m, line 7\u001b[39m\n\u001b[32m 4\u001b[39m load_dotenv(override=\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[32m 5\u001b[39m groq_apo=os.getenv(\u001b[33m\"\u001b[39m\u001b[33mGROQ_API_KEY\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m----> \u001b[39m\u001b[32m7\u001b[39m client = \u001b[43mGroq\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 8\u001b[39m response=client.chat.completions.create(\n\u001b[32m 9\u001b[39m model=\u001b[33m'\u001b[39m\u001b[33mllama-3.3-70b-versatile\u001b[39m\u001b[33m'\u001b[39m,\n\u001b[32m 10\u001b[39m messages=[{\n\u001b[32m (...)\u001b[39m\u001b[32m 13\u001b[39m }]\n\u001b[32m 14\u001b[39m )\n\u001b[32m 15\u001b[39m \u001b[38;5;28mprint\u001b[39m(response.choices[\u001b[32m0\u001b[39m].message.content)\n",
"\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\govindh vaila\\projects\\agents\\.venv\\Lib\\site-packages\\groq\\_client.py:83\u001b[39m, in \u001b[36mGroq.__init__\u001b[39m\u001b[34m(self, api_key, base_url, timeout, max_retries, default_headers, default_query, http_client, _strict_response_validation)\u001b[39m\n\u001b[32m 81\u001b[39m api_key = os.environ.get(\u001b[33m\"\u001b[39m\u001b[33mGROQ_API_KEY\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m 82\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m api_key \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[32m---> \u001b[39m\u001b[32m83\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m GroqError(\n\u001b[32m 84\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mThe api_key client option must be set either by passing api_key to the client or by setting the GROQ_API_KEY environment variable\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 85\u001b[39m )\n\u001b[32m 86\u001b[39m \u001b[38;5;28mself\u001b[39m.api_key = api_key\n\u001b[32m 88\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m base_url \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n",
"\u001b[31mGroqError\u001b[39m: The api_key client option must be set either by passing api_key to the client or by setting the GROQ_API_KEY environment variable"
]
}
],
"source": [
"from dotenv import load_dotenv\n",
"from groq import Groq\n",
"import os\n",
"load_dotenv(override=True)\n",
"groq_apo=os.getenv(\"GROQ_API_KEY\")\n",
"\n",
"client = Groq()\n",
"response=client.chat.completions.create(\n",
" model='llama-3.3-70b-versatile',\n",
" messages=[{\n",
" 'role':'user',\n",
" 'content':'explain about yourself'\n",
" }]\n",
")\n",
"print(response.choices[0].message.content)"
]
},
{
"cell_type": "markdown",
"id": "ad9dd9c2",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": 1,
"id": "7703702a",
"metadata": {},
"outputs": [],
"source": [
"from dotenv import load_dotenv\n",
"from groq import Groq\n",
"import json\n",
"import os\n",
"import requests\n",
"from pypdf import PdfReader\n",
"import gradio as gr"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "220a7fe3",
"metadata": {},
"outputs": [],
"source": [
"load_dotenv(override=True)\n",
"groq_api_key=os.getenv('GROQ_API_KEY')\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5e5c9b5d",
"metadata": {},
"outputs": [
{
"ename": "GroqError",
"evalue": "The api_key client option must be set either by passing api_key to the client or by setting the GROQ_API_KEY environment variable",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mGroqError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[10]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m client=\u001b[43mGroq\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\govindh vaila\\projects\\agents\\.venv\\Lib\\site-packages\\groq\\_client.py:83\u001b[39m, in \u001b[36mGroq.__init__\u001b[39m\u001b[34m(self, api_key, base_url, timeout, max_retries, default_headers, default_query, http_client, _strict_response_validation)\u001b[39m\n\u001b[32m 81\u001b[39m api_key = os.environ.get(\u001b[33m\"\u001b[39m\u001b[33mGROQ_API_KEY\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m 82\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m api_key \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[32m---> \u001b[39m\u001b[32m83\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m GroqError(\n\u001b[32m 84\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mThe api_key client option must be set either by passing api_key to the client or by setting the GROQ_API_KEY environment variable\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 85\u001b[39m )\n\u001b[32m 86\u001b[39m \u001b[38;5;28mself\u001b[39m.api_key = api_key\n\u001b[32m 88\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m base_url \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n",
"\u001b[31mGroqError\u001b[39m: The api_key client option must be set either by passing api_key to the client or by setting the GROQ_API_KEY environment variable"
]
}
],
"source": [
"if groq_api_key:\n",
" print(\"all set\")\n",
"else:\n",
" print(\"no\") \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4f36a35b",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|