|
32 | 32 | "import matplotlib\n",
|
33 | 33 | "import matplotlib.pyplot as plt \n",
|
34 | 34 | "\n",
|
35 |
| - "import openai\n", |
36 |
| - "import tiktoken\n", |
| 35 | + "from openai import OpenAI\n", |
37 | 36 | "\n",
|
| 37 | + "import tiktoken\n", |
38 | 38 | "import nltk\n",
|
39 | 39 | "from nltk.corpus import reuters\n",
|
40 | 40 | "from nltk import bigrams, trigrams\n",
|
|
72 | 72 | "output_type": "stream",
|
73 | 73 | "text": [
|
74 | 74 | "Python implementation: CPython\n",
|
75 |
| - "Python version : 3.10.9\n", |
76 |
| - "IPython version : 8.10.0\n", |
| 75 | + "Python version : 3.11.7\n", |
| 76 | + "IPython version : 8.12.3\n", |
77 | 77 | "\n",
|
78 | 78 | "Compiler : Clang 14.0.6 \n",
|
79 | 79 | "OS : Darwin\n",
|
80 |
| - "Release : 23.1.0\n", |
81 |
| - "Machine : x86_64\n", |
82 |
| - "Processor : i386\n", |
| 80 | + "Release : 23.4.0\n", |
| 81 | + "Machine : arm64\n", |
| 82 | + "Processor : arm\n", |
83 | 83 | "CPU cores : 16\n",
|
84 | 84 | "Architecture: 64bit\n",
|
85 | 85 | "\n",
|
86 |
| - "Git hash: dd79ad5dfd349dc3b1ae00a307ee636a9ab6b2ef\n", |
| 86 | + "Git hash: 529fe8a3ea9769b549bab95c993473f8266299a8\n", |
87 | 87 | "\n",
|
88 |
| - "tqdm : 4.66.1\n", |
89 |
| - "watermark : 2.4.2\n", |
90 |
| - "numpy : 1.23.5\n", |
91 |
| - "openai : 0.28.1\n", |
92 |
| - "pandas : 1.5.3\n", |
93 |
| - "matplotlib: 3.7.2\n", |
94 |
| - "nltk : 3.7\n", |
95 |
| - "tiktoken : 0.5.1\n", |
| 88 | + "matplotlib: 3.8.0\n", |
| 89 | + "numpy : 1.26.4\n", |
| 90 | + "tqdm : 4.66.2\n", |
| 91 | + "watermark : 2.4.3\n", |
| 92 | + "pandas : 2.1.4\n", |
| 93 | + "nltk : 3.8.1\n", |
| 94 | + "tiktoken : 0.6.0\n", |
96 | 95 | "\n"
|
97 | 96 | ]
|
98 | 97 | }
|
|
500 | 499 | " return num_tokens\n"
|
501 | 500 | ]
|
502 | 501 | },
|
| 502 | + { |
| 503 | + "cell_type": "markdown", |
| 504 | + "id": "39d1b4a4-555f-4431-90d9-e365f9b67070", |
| 505 | + "metadata": {}, |
| 506 | + "source": [ |
| 507 | + "Instatiate the client" |
| 508 | + ] |
| 509 | + }, |
503 | 510 | {
|
504 | 511 | "cell_type": "code",
|
505 | 512 | "execution_count": 14,
|
| 513 | + "id": "beb9e74e-1c2c-4be5-b57c-f69e8078f0fa", |
| 514 | + "metadata": {}, |
| 515 | + "outputs": [], |
| 516 | + "source": [ |
| 517 | + "client = OpenAI()" |
| 518 | + ] |
| 519 | + }, |
| 520 | + { |
| 521 | + "cell_type": "code", |
| 522 | + "execution_count": 15, |
506 | 523 | "id": "c75f4844",
|
507 | 524 | "metadata": {},
|
508 | 525 | "outputs": [
|
|
578 | 595 | " # example token count from the function defined above\n",
|
579 | 596 | " print(f\"{num_tokens_from_messages(example_messages, model)} prompt tokens counted by num_tokens_from_messages().\")\n",
|
580 | 597 | " # example token count from the OpenAI API\n",
|
581 |
| - " response = openai.ChatCompletion.create(\n", |
| 598 | + " response = client.chat.completions.create(\n", |
582 | 599 | " model=model,\n",
|
583 | 600 | " messages=example_messages,\n",
|
584 | 601 | " temperature=0,\n",
|
585 | 602 | " max_tokens=1, # we're only counting input tokens here, so let's not waste tokens on the output\n",
|
586 | 603 | " )\n",
|
587 |
| - " print(f'{response[\"usage\"][\"prompt_tokens\"]} prompt tokens counted by the OpenAI API.')\n", |
| 604 | + " print(f'{response.usage.prompt_tokens} prompt tokens counted by the OpenAI API.')\n", |
588 | 605 | " print()\n"
|
589 | 606 | ]
|
590 | 607 | },
|
|
598 | 615 | },
|
599 | 616 | {
|
600 | 617 | "cell_type": "code",
|
601 |
| - "execution_count": 15, |
| 618 | + "execution_count": 16, |
602 | 619 | "id": "85acd120",
|
603 | 620 | "metadata": {},
|
604 | 621 | "outputs": [],
|
|
616 | 633 | },
|
617 | 634 | {
|
618 | 635 | "cell_type": "code",
|
619 |
| - "execution_count": 16, |
| 636 | + "execution_count": 17, |
620 | 637 | "id": "b925cf88",
|
621 | 638 | "metadata": {},
|
622 | 639 | "outputs": [
|
623 | 640 | {
|
624 | 641 | "data": {
|
625 | 642 | "application/vnd.jupyter.widget-view+json": {
|
626 |
| - "model_id": "e59a2da7b3e34e4ca2035b61db84785c", |
| 643 | + "model_id": "067e20a935294beabb4af3f0dc50bf3b", |
627 | 644 | "version_major": 2,
|
628 | 645 | "version_minor": 0
|
629 | 646 | },
|
|
652 | 669 | },
|
653 | 670 | {
|
654 | 671 | "cell_type": "code",
|
655 |
| - "execution_count": 17, |
| 672 | + "execution_count": 18, |
656 | 673 | "id": "3058681d",
|
657 | 674 | "metadata": {},
|
658 | 675 | "outputs": [],
|
|
674 | 691 | },
|
675 | 692 | {
|
676 | 693 | "cell_type": "code",
|
677 |
| - "execution_count": 18, |
| 694 | + "execution_count": 19, |
678 | 695 | "id": "a4ae8a55",
|
679 | 696 | "metadata": {},
|
680 | 697 | "outputs": [
|
|
697 | 714 | " 'Rubber': 0.0016806722689075631})"
|
698 | 715 | ]
|
699 | 716 | },
|
700 |
| - "execution_count": 18, |
| 717 | + "execution_count": 19, |
701 | 718 | "metadata": {},
|
702 | 719 | "output_type": "execute_result"
|
703 | 720 | }
|
|
708 | 725 | },
|
709 | 726 | {
|
710 | 727 | "cell_type": "code",
|
711 |
| - "execution_count": 19, |
| 728 | + "execution_count": 20, |
712 | 729 | "id": "d5911761",
|
713 | 730 | "metadata": {},
|
714 | 731 | "outputs": [
|
|
727 | 744 | " '.': 0.07142857142857142})"
|
728 | 745 | ]
|
729 | 746 | },
|
730 |
| - "execution_count": 19, |
| 747 | + "execution_count": 20, |
731 | 748 | "metadata": {},
|
732 | 749 | "output_type": "execute_result"
|
733 | 750 | }
|
|
746 | 763 | },
|
747 | 764 | {
|
748 | 765 | "cell_type": "code",
|
749 |
| - "execution_count": 20, |
| 766 | + "execution_count": 21, |
750 | 767 | "id": "544fef3a",
|
751 | 768 | "metadata": {},
|
752 | 769 | "outputs": [],
|
|
795 | 812 | },
|
796 | 813 | {
|
797 | 814 | "cell_type": "code",
|
798 |
| - "execution_count": 21, |
| 815 | + "execution_count": 22, |
799 | 816 | "id": "bbfdd491",
|
800 | 817 | "metadata": {},
|
801 | 818 | "outputs": [
|
802 | 819 | {
|
803 | 820 | "data": {
|
804 | 821 | "text/plain": [
|
805 |
| - "'United States and the assumption of certain assets by Olson .'" |
| 822 | + "'United States if it did not endorse a resolution of capacity in the year in Tokyo , which is not in the system today .'" |
806 | 823 | ]
|
807 | 824 | },
|
808 |
| - "execution_count": 21, |
| 825 | + "execution_count": 22, |
809 | 826 | "metadata": {},
|
810 | 827 | "output_type": "execute_result"
|
811 | 828 | }
|
|
816 | 833 | },
|
817 | 834 | {
|
818 | 835 | "cell_type": "code",
|
819 |
| - "execution_count": 22, |
| 836 | + "execution_count": 23, |
820 | 837 | "id": "e73054d6",
|
821 | 838 | "metadata": {},
|
822 | 839 | "outputs": [
|
823 | 840 | {
|
824 | 841 | "data": {
|
825 | 842 | "text/plain": [
|
826 |
| - "'today the company , seeking equilibrium , sends a surge in investments and pave the way for better business in the Middle East and Midwest .'" |
| 843 | + "\"today the options at a lower quota next year on March 5 . 93 and 142 . 50 dlrs a share , a government to supply the remaining 30 pct over Pioneer ' s next general elections , due to overhaul work on the St Louis Merchants ' Exchange call session , bond managers said .\"" |
827 | 844 | ]
|
828 | 845 | },
|
829 |
| - "execution_count": 22, |
| 846 | + "execution_count": 23, |
830 | 847 | "metadata": {},
|
831 | 848 | "output_type": "execute_result"
|
832 | 849 | }
|
|
837 | 854 | },
|
838 | 855 | {
|
839 | 856 | "cell_type": "code",
|
840 |
| - "execution_count": 23, |
| 857 | + "execution_count": 24, |
841 | 858 | "id": "15d6b819",
|
842 | 859 | "metadata": {},
|
843 | 860 | "outputs": [
|
844 | 861 | {
|
845 | 862 | "data": {
|
846 | 863 | "text/plain": [
|
847 |
| - "'financial markets .'" |
| 864 | + "'financial markets have become highly optimistic about improved profit margins previously constrained by the Holly board and conditioned on receipt of third country destinations , USDA Secretary Richard Lyng opens talks with American trade negotiators in a statement .'" |
848 | 865 | ]
|
849 | 866 | },
|
850 |
| - "execution_count": 23, |
| 867 | + "execution_count": 24, |
851 | 868 | "metadata": {},
|
852 | 869 | "output_type": "execute_result"
|
853 | 870 | }
|
|
883 | 900 | "name": "python",
|
884 | 901 | "nbconvert_exporter": "python",
|
885 | 902 | "pygments_lexer": "ipython3",
|
886 |
| - "version": "3.10.9" |
| 903 | + "version": "3.11.7" |
887 | 904 | },
|
888 | 905 | "varInspector": {
|
889 | 906 | "cols": {
|
|
0 commit comments