Datasets:
File size: 51,670 Bytes
9caafd9 |
1 |
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyOibBjeE+j+tt0c+s7SXVqJ"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"p38hXaVqPusR","executionInfo":{"status":"ok","timestamp":1705441723997,"user_tz":300,"elapsed":17116,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"1d9af1f3-2d86-4f67-ba7e-b80fbd01c255"},"outputs":[{"output_type":"stream","name":"stdout","text":["Collecting datasets\n"," Downloading datasets-2.16.1-py3-none-any.whl (507 kB)\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m507.1/507.1 kB\u001b[0m \u001b[31m2.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25hRequirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from datasets) (3.13.1)\n","Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.10/dist-packages (from datasets) (1.23.5)\n","Requirement already satisfied: pyarrow>=8.0.0 in /usr/local/lib/python3.10/dist-packages (from datasets) (10.0.1)\n","Requirement already satisfied: pyarrow-hotfix in /usr/local/lib/python3.10/dist-packages (from datasets) (0.6)\n","Collecting dill<0.3.8,>=0.3.0 (from datasets)\n"," Downloading dill-0.3.7-py3-none-any.whl (115 kB)\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m115.3/115.3 kB\u001b[0m \u001b[31m9.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25hRequirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from datasets) (1.5.3)\n","Requirement already satisfied: requests>=2.19.0 in /usr/local/lib/python3.10/dist-packages (from datasets) (2.31.0)\n","Requirement already satisfied: tqdm>=4.62.1 in /usr/local/lib/python3.10/dist-packages (from datasets) (4.66.1)\n","Requirement already satisfied: xxhash in /usr/local/lib/python3.10/dist-packages (from datasets) (3.4.1)\n","Collecting multiprocess (from datasets)\n"," Downloading multiprocess-0.70.15-py310-none-any.whl (134 kB)\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m134.8/134.8 kB\u001b[0m \u001b[31m8.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25hRequirement already satisfied: fsspec[http]<=2023.10.0,>=2023.1.0 in /usr/local/lib/python3.10/dist-packages (from datasets) (2023.6.0)\n","Requirement already satisfied: aiohttp in /usr/local/lib/python3.10/dist-packages (from datasets) (3.9.1)\n","Requirement already satisfied: huggingface-hub>=0.19.4 in /usr/local/lib/python3.10/dist-packages (from datasets) (0.20.2)\n","Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from datasets) (23.2)\n","Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.10/dist-packages (from datasets) (6.0.1)\n","Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (23.2.0)\n","Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (6.0.4)\n","Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (1.9.4)\n","Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (1.4.1)\n","Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (1.3.1)\n","Requirement already satisfied: async-timeout<5.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (4.0.3)\n","Requirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.4->datasets) (4.5.0)\n","Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests>=2.19.0->datasets) (3.3.2)\n","Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests>=2.19.0->datasets) (3.6)\n","Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.19.0->datasets) (2.0.7)\n","Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests>=2.19.0->datasets) (2023.11.17)\n","Requirement already satisfied: python-dateutil>=2.8.1 in /usr/local/lib/python3.10/dist-packages (from pandas->datasets) (2.8.2)\n","Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->datasets) (2023.3.post1)\n","Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.1->pandas->datasets) (1.16.0)\n","Installing collected packages: dill, multiprocess, datasets\n","Successfully installed datasets-2.16.1 dill-0.3.7 multiprocess-0.70.15\n"]}],"source":["pip install datasets"]},{"cell_type":"code","source":["type(b'abc')"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"s_fFmyZSQzYq","executionInfo":{"status":"ok","timestamp":1705442045074,"user_tz":300,"elapsed":97,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"cb4117e1-b364-4027-b15a-91a665adfcc5"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["bytes"]},"metadata":{},"execution_count":5}]},{"cell_type":"code","source":["type(True)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"mIjPwj6jRHNs","executionInfo":{"status":"ok","timestamp":1705442363331,"user_tz":300,"elapsed":120,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"68f4d6bd-0064-4d2f-84bb-be2b39cc6a9c"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["bool"]},"metadata":{},"execution_count":11}]},{"cell_type":"code","source":["class Dog:\n"," def __init__(self,name,age):\n"," self.name=name\n"," self.age=age\n"," def bark(self):\n"," print(f'{self.name} is barking')\n","\n","d = Dog('Fido',3)\n","d.bark()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"ahLFcJS7SUw_","executionInfo":{"status":"ok","timestamp":1705442369399,"user_tz":300,"elapsed":2,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"6343f352-988a-403e-be77-08116e5baa2d"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Fido is barking\n"]}]},{"cell_type":"code","source":["class Dog:\n"," def __init__(self,name,age):\n"," self.name=name\n"," self.age=age\n"," print('A new dog is born!')\n","\n"," def bark(self):\n"," print(f'{self.name} is barking')\n","\n","d = Dog('Fido',3) #instance of this class\n","d.name = 'Apple'\n","d.bark()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"IX0DIMmNazxf","executionInfo":{"status":"ok","timestamp":1705444596914,"user_tz":300,"elapsed":100,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"78cc4454-c4d5-4a00-8d60-ac8d7fa5b9f7"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["A new dog is born!\n","Apple is barking\n"]}]},{"cell_type":"code","source":["class MyDataset:\n"," def __init__(self,name,age):\n"," self.name=name\n"," self.age=age\n"," print('A new dog is born!')\n","\n"," def bark(self):\n"," print(f'{self.name} is barking')"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"aCHLm8LfZ04z","executionInfo":{"status":"ok","timestamp":1705444557889,"user_tz":300,"elapsed":103,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"67f701fb-a48c-4fc2-913e-7b8154093e3d"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Apple is barking\n"]}]},{"cell_type":"code","source":["from datasets import load_dataset\n","\n","dataset=load_dataset('zeroshot/twitter-financial-news-sentiment')"],"metadata":{"id":"tEsOTOMdPy5G"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["dataset"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"YrCqQWopQskH","executionInfo":{"status":"ok","timestamp":1705441947560,"user_tz":300,"elapsed":3,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"5f59c874-16fb-4db6-e81a-f272174631cc"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["DatasetDict({\n"," train: Dataset({\n"," features: ['text', 'label'],\n"," num_rows: 9543\n"," })\n"," validation: Dataset({\n"," features: ['text', 'label'],\n"," num_rows: 2388\n"," })\n","})"]},"metadata":{},"execution_count":4}]},{"cell_type":"code","source":["training_set = dataset['train']"],"metadata":{"id":"sQOWNGI8RYiM"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["training_set"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"gBGqOlhjSEz5","executionInfo":{"status":"ok","timestamp":1705442409620,"user_tz":300,"elapsed":4,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"e4bf66d9-42d8-4119-89fb-fe50d8ec5b60"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["Dataset({\n"," features: ['text', 'label'],\n"," num_rows: 9543\n","})"]},"metadata":{},"execution_count":14}]},{"cell_type":"code","source":["#tuple() = return keys: 'y'=0.5 ; 'y' is key"],"metadata":{"id":"MDMX_lcjTqSI"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["true_dictionary = {\n"," 'train': [1,2,3,4],\n"," 'validation': [1,2,'winner',4]\n","}\n","\n","true_dictionary['validation'][2]"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":35},"id":"zpBAcwaETxdN","executionInfo":{"status":"ok","timestamp":1705442924339,"user_tz":300,"elapsed":6,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"3487b57b-b30f-4677-8547-e392304c58dc"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["'winner'"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"string"}},"metadata":{},"execution_count":21}]},{"cell_type":"code","source":["my_dataset = {\n"," 'train' : dataset['train'],\n"," 'validation': dataset['validation']\n","}"],"metadata":{"id":"3md_OTcTVCoY"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["my_dataset"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"BiqiAsv3VLHd","executionInfo":{"status":"ok","timestamp":1705443112269,"user_tz":300,"elapsed":3,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"615c97f4-3e3d-48c5-c7cd-b734778bc7c6"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["{'train': Dataset({\n"," features: ['text', 'label'],\n"," num_rows: 9543\n"," }),\n"," 'validation': Dataset({\n"," features: ['text', 'label'],\n"," num_rows: 2388\n"," })}"]},"metadata":{},"execution_count":24}]},{"cell_type":"code","source":["# path:str doesn't have to be str, just for annotation.\n","def my_load_datase(path:str) -> str:\n"," print('I do something with',path)\n"," print(path)\n"," return path"],"metadata":{"id":"7DfQm-y9WK04"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["my_load_datase('hello!')\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":71},"id":"stgiMo_AWQYt","executionInfo":{"status":"ok","timestamp":1705443705384,"user_tz":300,"elapsed":118,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"bd947972-ddaa-4842-9651-3edc084b0e7f"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["I do something with hello!\n","hello!\n"]},{"output_type":"execute_result","data":{"text/plain":["'hello!'"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"string"}},"metadata":{},"execution_count":45}]},{"cell_type":"code","source":["df = dataset['train'].to_pandas()"],"metadata":{"id":"q6xzMNIdWvnn"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["df.head()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":206},"id":"f44y0J_JbmkQ","executionInfo":{"status":"ok","timestamp":1705445069459,"user_tz":300,"elapsed":115,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"4a75a86e-899f-492c-d8bc-a6c1a95a4632"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" text label\n","0 $BYND - JPMorgan reels in expectations on Beyo... 0\n","1 $CCL $RCL - Nomura points to bookings weakness... 0\n","2 $CX - Cemex cut at Credit Suisse, J.P. Morgan ... 0\n","3 $ESS: BTIG Research cuts to Neutral https://t.... 0\n","4 $FNKO - Funko slides after Piper Jaffray PT cu... 0"],"text/html":["\n"," <div id=\"df-5d357d6b-9c2b-40df-9339-eb6b227280a1\" class=\"colab-df-container\">\n"," <div>\n","<style scoped>\n"," .dataframe tbody tr th:only-of-type {\n"," vertical-align: middle;\n"," }\n","\n"," .dataframe tbody tr th {\n"," vertical-align: top;\n"," }\n","\n"," .dataframe thead th {\n"," text-align: right;\n"," }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n"," <thead>\n"," <tr style=\"text-align: right;\">\n"," <th></th>\n"," <th>text</th>\n"," <th>label</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n"," <td>$BYND - JPMorgan reels in expectations on Beyo...</td>\n"," <td>0</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n"," <td>$CCL $RCL - Nomura points to bookings weakness...</td>\n"," <td>0</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>$CX - Cemex cut at Credit Suisse, J.P. Morgan ...</td>\n"," <td>0</td>\n"," </tr>\n"," <tr>\n"," <th>3</th>\n"," <td>$ESS: BTIG Research cuts to Neutral https://t....</td>\n"," <td>0</td>\n"," </tr>\n"," <tr>\n"," <th>4</th>\n"," <td>$FNKO - Funko slides after Piper Jaffray PT cu...</td>\n"," <td>0</td>\n"," </tr>\n"," </tbody>\n","</table>\n","</div>\n"," <div class=\"colab-df-buttons\">\n","\n"," <div class=\"colab-df-container\">\n"," <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-5d357d6b-9c2b-40df-9339-eb6b227280a1')\"\n"," title=\"Convert this dataframe to an interactive table.\"\n"," style=\"display:none;\">\n","\n"," <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n"," <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n"," </svg>\n"," </button>\n","\n"," <style>\n"," .colab-df-container {\n"," display:flex;\n"," gap: 12px;\n"," }\n","\n"," .colab-df-convert {\n"," background-color: #E8F0FE;\n"," border: none;\n"," border-radius: 50%;\n"," cursor: pointer;\n"," display: none;\n"," fill: #1967D2;\n"," height: 32px;\n"," padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\n"," .colab-df-convert:hover {\n"," background-color: #E2EBFA;\n"," box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n"," fill: #174EA6;\n"," }\n","\n"," .colab-df-buttons div {\n"," margin-bottom: 4px;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n"," background-color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n"," [theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n"," box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\n","\n"," <script>\n"," const buttonEl =\n"," document.querySelector('#df-5d357d6b-9c2b-40df-9339-eb6b227280a1 button.colab-df-convert');\n"," buttonEl.style.display =\n"," google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function convertToInteractive(key) {\n"," const element = document.querySelector('#df-5d357d6b-9c2b-40df-9339-eb6b227280a1');\n"," const dataTable =\n"," await google.colab.kernel.invokeFunction('convertToInteractive',\n"," [key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml = 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n"," + ' to learn more about interactive tables.';\n"," element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n"," await google.colab.output.renderOutput(dataTable, element);\n"," const docLink = document.createElement('div');\n"," docLink.innerHTML = docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n"," </script>\n"," </div>\n","\n","\n","<div id=\"df-e6e037aa-db57-40dc-8ab5-75e1bcb4f8f4\">\n"," <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-e6e037aa-db57-40dc-8ab5-75e1bcb4f8f4')\"\n"," title=\"Suggest charts\"\n"," style=\"display:none;\">\n","\n","<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n"," width=\"24px\">\n"," <g>\n"," <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n"," </g>\n","</svg>\n"," </button>\n","\n","<style>\n"," .colab-df-quickchart {\n"," --bg-color: #E8F0FE;\n"," --fill-color: #1967D2;\n"," --hover-bg-color: #E2EBFA;\n"," --hover-fill-color: #174EA6;\n"," --disabled-fill-color: #AAA;\n"," --disabled-bg-color: #DDD;\n"," }\n","\n"," [theme=dark] .colab-df-quickchart {\n"," --bg-color: #3B4455;\n"," --fill-color: #D2E3FC;\n"," --hover-bg-color: #434B5C;\n"," --hover-fill-color: #FFFFFF;\n"," --disabled-bg-color: #3B4455;\n"," --disabled-fill-color: #666;\n"," }\n","\n"," .colab-df-quickchart {\n"," background-color: var(--bg-color);\n"," border: none;\n"," border-radius: 50%;\n"," cursor: pointer;\n"," display: none;\n"," fill: var(--fill-color);\n"," height: 32px;\n"," padding: 0;\n"," width: 32px;\n"," }\n","\n"," .colab-df-quickchart:hover {\n"," background-color: var(--hover-bg-color);\n"," box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n"," fill: var(--button-hover-fill-color);\n"," }\n","\n"," .colab-df-quickchart-complete:disabled,\n"," .colab-df-quickchart-complete:disabled:hover {\n"," background-color: var(--disabled-bg-color);\n"," fill: var(--disabled-fill-color);\n"," box-shadow: none;\n"," }\n","\n"," .colab-df-spinner {\n"," border: 2px solid var(--fill-color);\n"," border-color: transparent;\n"," border-bottom-color: var(--fill-color);\n"," animation:\n"," spin 1s steps(1) infinite;\n"," }\n","\n"," @keyframes spin {\n"," 0% {\n"," border-color: transparent;\n"," border-bottom-color: var(--fill-color);\n"," border-left-color: var(--fill-color);\n"," }\n"," 20% {\n"," border-color: transparent;\n"," border-left-color: var(--fill-color);\n"," border-top-color: var(--fill-color);\n"," }\n"," 30% {\n"," border-color: transparent;\n"," border-left-color: var(--fill-color);\n"," border-top-color: var(--fill-color);\n"," border-right-color: var(--fill-color);\n"," }\n"," 40% {\n"," border-color: transparent;\n"," border-right-color: var(--fill-color);\n"," border-top-color: var(--fill-color);\n"," }\n"," 60% {\n"," border-color: transparent;\n"," border-right-color: var(--fill-color);\n"," }\n"," 80% {\n"," border-color: transparent;\n"," border-right-color: var(--fill-color);\n"," border-bottom-color: var(--fill-color);\n"," }\n"," 90% {\n"," border-color: transparent;\n"," border-bottom-color: var(--fill-color);\n"," }\n"," }\n","</style>\n","\n"," <script>\n"," async function quickchart(key) {\n"," const quickchartButtonEl =\n"," document.querySelector('#' + key + ' button');\n"," quickchartButtonEl.disabled = true; // To prevent multiple clicks.\n"," quickchartButtonEl.classList.add('colab-df-spinner');\n"," try {\n"," const charts = await google.colab.kernel.invokeFunction(\n"," 'suggestCharts', [key], {});\n"," } catch (error) {\n"," console.error('Error during call to suggestCharts:', error);\n"," }\n"," quickchartButtonEl.classList.remove('colab-df-spinner');\n"," quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n"," }\n"," (() => {\n"," let quickchartButtonEl =\n"," document.querySelector('#df-e6e037aa-db57-40dc-8ab5-75e1bcb4f8f4 button');\n"," quickchartButtonEl.style.display =\n"," google.colab.kernel.accessAllowed ? 'block' : 'none';\n"," })();\n"," </script>\n","</div>\n","\n"," </div>\n"," </div>\n"]},"metadata":{},"execution_count":55}]},{"cell_type":"code","source":["pip install openai"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"zo-z4MdBcpB2","executionInfo":{"status":"ok","timestamp":1705614528823,"user_tz":300,"elapsed":22187,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"a1797b19-024e-48e7-bff0-e654b6b166cf"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Collecting openai\n"," Downloading openai-1.8.0-py3-none-any.whl (222 kB)\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m222.3/222.3 kB\u001b[0m \u001b[31m2.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25hRequirement already satisfied: anyio<5,>=3.5.0 in /usr/local/lib/python3.10/dist-packages (from openai) (3.7.1)\n","Requirement already satisfied: distro<2,>=1.7.0 in /usr/lib/python3/dist-packages (from openai) (1.7.0)\n","Collecting httpx<1,>=0.23.0 (from openai)\n"," Downloading httpx-0.26.0-py3-none-any.whl (75 kB)\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m75.9/75.9 kB\u001b[0m \u001b[31m5.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25hRequirement already satisfied: pydantic<3,>=1.9.0 in /usr/local/lib/python3.10/dist-packages (from openai) (1.10.13)\n","Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from openai) (1.3.0)\n","Requirement already satisfied: tqdm>4 in /usr/local/lib/python3.10/dist-packages (from openai) (4.66.1)\n","Collecting typing-extensions<5,>=4.7 (from openai)\n"," Downloading typing_extensions-4.9.0-py3-none-any.whl (32 kB)\n","Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.10/dist-packages (from anyio<5,>=3.5.0->openai) (3.6)\n","Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio<5,>=3.5.0->openai) (1.2.0)\n","Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx<1,>=0.23.0->openai) (2023.11.17)\n","Collecting httpcore==1.* (from httpx<1,>=0.23.0->openai)\n"," Downloading httpcore-1.0.2-py3-none-any.whl (76 kB)\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m76.9/76.9 kB\u001b[0m \u001b[31m4.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25hCollecting h11<0.15,>=0.13 (from httpcore==1.*->httpx<1,>=0.23.0->openai)\n"," Downloading h11-0.14.0-py3-none-any.whl (58 kB)\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m3.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25hInstalling collected packages: typing-extensions, h11, httpcore, httpx, openai\n"," Attempting uninstall: typing-extensions\n"," Found existing installation: typing_extensions 4.5.0\n"," Uninstalling typing_extensions-4.5.0:\n"," Successfully uninstalled typing_extensions-4.5.0\n","\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n","llmx 0.0.15a0 requires cohere, which is not installed.\n","llmx 0.0.15a0 requires tiktoken, which is not installed.\n","tensorflow-probability 0.22.0 requires typing-extensions<4.6.0, but you have typing-extensions 4.9.0 which is incompatible.\u001b[0m\u001b[31m\n","\u001b[0mSuccessfully installed h11-0.14.0 httpcore-1.0.2 httpx-0.26.0 openai-1.8.0 typing-extensions-4.9.0\n"]}]},{"cell_type":"code","source":["from openai import OpenAI"],"metadata":{"id":"O2T0DAJDc3b-"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# https://huggingface.co/docs/datasets/v2.16.1/loading\n","# https://huggingface.co/docs/datasets/v2.16.1/en/package_reference/loading_methods#datasets.load_dataset\n","dataset = load_dataset(\"zeroshot/twitter-financial-news-sentiment\")\n","\n","df = dataset[\"train\"].to_pandas()"],"metadata":{"id":"FDevjxWxc3gB"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["print(df.iloc[0].text)"],"metadata":{"id":"aMHcoXuFc3jj"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["client = OpenAI(\n"," # https://platform.openai.com/docs/overview\n"," api_key=API_KEY,\n",")\n","\n","chat_completion = client.chat.completions.create(\n"," messages=[\n"," {\"role\": \"system\", \"content\": \"You are an API which extracts stock tickers from tweets. Only provide the ticker.\"},\n"," {\"role\": \"user\", \"content\": df.iloc[0].text}\n"," ],\n"," model=\"gpt-3.5-turbo\",\n",")"],"metadata":{"id":"NyqgMq9Zc3m1","colab":{"base_uri":"https://localhost:8080/","height":250},"executionInfo":{"status":"error","timestamp":1705614540658,"user_tz":300,"elapsed":145,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"ad550488-f040-4e06-d1e0-0bdc831ec06c"},"execution_count":null,"outputs":[{"output_type":"error","ename":"NameError","evalue":"name 'API_KEY' is not defined","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)","\u001b[0;32m<ipython-input-4-3ce586a18164>\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m client = OpenAI(\n\u001b[1;32m 2\u001b[0m \u001b[0;31m# https://platform.openai.com/docs/overview\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mapi_key\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mAPI_KEY\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m )\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;31mNameError\u001b[0m: name 'API_KEY' is not defined"]}]},{"cell_type":"code","source":["chat_completion.choices[0].message.content"],"metadata":{"id":"J7OnVqJJc3px"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["def get_tickers(text):\n"," client = OpenAI(\n"," api_key= \"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\",\n"," )\n","\n"," chat_completion = client.chat.completions.create(\n"," messages=[\n"," {\"role\": \"system\", \"content\": \"You are an API which extracts stock tickers from tweets. Only provide the ticker.\"},\n"," {\"role\": \"user\", \"content\": text}\n"," ],\n"," model=\"gpt-3.5-turbo\",\n"," )\n","\n"," return chat_completion.choices[0].message.content"],"metadata":{"id":"vQ3OTNtTcuQf"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["get_tickers()"],"metadata":{"id":"Ny1dlDH6rjMq","colab":{"base_uri":"https://localhost:8080/","height":381},"executionInfo":{"status":"error","timestamp":1705615026232,"user_tz":300,"elapsed":3133,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"a0f010f7-5edd-442b-f768-64c40ab67c91"},"execution_count":null,"outputs":[{"output_type":"error","ename":"RateLimitError","evalue":"Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mRateLimitError\u001b[0m Traceback (most recent call last)","\u001b[0;32m<ipython-input-10-92cf810a02f5>\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mget_tickers\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;32m<ipython-input-8-49b396972038>\u001b[0m in \u001b[0;36mget_tickers\u001b[0;34m(text)\u001b[0m\n\u001b[1;32m 4\u001b[0m )\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m chat_completion = client.chat.completions.create(\n\u001b[0m\u001b[1;32m 7\u001b[0m messages=[\n\u001b[1;32m 8\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m\"role\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m\"system\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"content\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m\"You are an API which extracts stock tickers from tweets. Only provide the ticker.\"\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.10/dist-packages/openai/_utils/_utils.py\u001b[0m in \u001b[0;36mwrapper\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 269\u001b[0m \u001b[0mmsg\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34mf\"Missing required argument: {quote(missing[0])}\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 270\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmsg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 271\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 272\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 273\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mwrapper\u001b[0m \u001b[0;31m# type: ignore\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.10/dist-packages/openai/resources/chat/completions.py\u001b[0m in \u001b[0;36mcreate\u001b[0;34m(self, messages, model, frequency_penalty, function_call, functions, logit_bias, logprobs, max_tokens, n, presence_penalty, response_format, seed, stop, stream, temperature, tool_choice, tools, top_logprobs, top_p, user, extra_headers, extra_query, extra_body, timeout)\u001b[0m\n\u001b[1;32m 646\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mfloat\u001b[0m \u001b[0;34m|\u001b[0m \u001b[0mhttpx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mTimeout\u001b[0m \u001b[0;34m|\u001b[0m \u001b[0;32mNone\u001b[0m \u001b[0;34m|\u001b[0m \u001b[0mNotGiven\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mNOT_GIVEN\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 647\u001b[0m ) -> ChatCompletion | Stream[ChatCompletionChunk]:\n\u001b[0;32m--> 648\u001b[0;31m return self._post(\n\u001b[0m\u001b[1;32m 649\u001b[0m \u001b[0;34m\"/chat/completions\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 650\u001b[0m body=maybe_transform(\n","\u001b[0;32m/usr/local/lib/python3.10/dist-packages/openai/_base_client.py\u001b[0m in \u001b[0;36mpost\u001b[0;34m(self, path, cast_to, body, options, files, stream, stream_cls)\u001b[0m\n\u001b[1;32m 1165\u001b[0m \u001b[0mmethod\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"post\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0murl\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mjson_data\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mbody\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfiles\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mto_httpx_files\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfiles\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0moptions\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1166\u001b[0m )\n\u001b[0;32m-> 1167\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mcast\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mResponseT\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrequest\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcast_to\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mopts\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstream\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mstream\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstream_cls\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mstream_cls\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1168\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1169\u001b[0m def patch(\n","\u001b[0;32m/usr/local/lib/python3.10/dist-packages/openai/_base_client.py\u001b[0m in \u001b[0;36mrequest\u001b[0;34m(self, cast_to, options, remaining_retries, stream, stream_cls)\u001b[0m\n\u001b[1;32m 854\u001b[0m \u001b[0mstream_cls\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mtype\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0m_StreamT\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m|\u001b[0m \u001b[0;32mNone\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 855\u001b[0m ) -> ResponseT | _StreamT:\n\u001b[0;32m--> 856\u001b[0;31m return self._request(\n\u001b[0m\u001b[1;32m 857\u001b[0m \u001b[0mcast_to\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcast_to\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 858\u001b[0m \u001b[0moptions\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0moptions\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.10/dist-packages/openai/_base_client.py\u001b[0m in \u001b[0;36m_request\u001b[0;34m(self, cast_to, options, remaining_retries, stream, stream_cls)\u001b[0m\n\u001b[1;32m 930\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mretries\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m0\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_should_retry\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0merr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresponse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 931\u001b[0m \u001b[0merr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresponse\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclose\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 932\u001b[0;31m return self._retry_request(\n\u001b[0m\u001b[1;32m 933\u001b[0m \u001b[0moptions\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 934\u001b[0m \u001b[0mcast_to\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.10/dist-packages/openai/_base_client.py\u001b[0m in \u001b[0;36m_retry_request\u001b[0;34m(self, options, cast_to, remaining_retries, response_headers, stream, stream_cls)\u001b[0m\n\u001b[1;32m 978\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 979\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 980\u001b[0;31m return self._request(\n\u001b[0m\u001b[1;32m 981\u001b[0m \u001b[0moptions\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0moptions\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 982\u001b[0m \u001b[0mcast_to\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcast_to\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.10/dist-packages/openai/_base_client.py\u001b[0m in \u001b[0;36m_request\u001b[0;34m(self, cast_to, options, remaining_retries, stream, stream_cls)\u001b[0m\n\u001b[1;32m 930\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mretries\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m0\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_should_retry\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0merr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresponse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 931\u001b[0m \u001b[0merr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresponse\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclose\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 932\u001b[0;31m return self._retry_request(\n\u001b[0m\u001b[1;32m 933\u001b[0m \u001b[0moptions\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 934\u001b[0m \u001b[0mcast_to\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.10/dist-packages/openai/_base_client.py\u001b[0m in \u001b[0;36m_retry_request\u001b[0;34m(self, options, cast_to, remaining_retries, response_headers, stream, stream_cls)\u001b[0m\n\u001b[1;32m 978\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 979\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 980\u001b[0;31m return self._request(\n\u001b[0m\u001b[1;32m 981\u001b[0m \u001b[0moptions\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0moptions\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 982\u001b[0m \u001b[0mcast_to\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcast_to\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.10/dist-packages/openai/_base_client.py\u001b[0m in \u001b[0;36m_request\u001b[0;34m(self, cast_to, options, remaining_retries, stream, stream_cls)\u001b[0m\n\u001b[1;32m 945\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 946\u001b[0m \u001b[0mlog\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdebug\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Re-raising status error\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 947\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_make_status_error_from_response\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0merr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresponse\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 948\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 949\u001b[0m return self._process_response(\n","\u001b[0;31mRateLimitError\u001b[0m: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}"]}]},{"cell_type":"code","source":["def get_ticket_dummy(text: str) -> str:\n"," raise ValueError (\"Needs to be a string\")\n"," return \"the stock ticker\""],"metadata":{"id":"QqktCzdTkWe6"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["get_ticket_dummy('$nvda going strong!')"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":268},"id":"Azt0unVglTc9","executionInfo":{"status":"error","timestamp":1705615136769,"user_tz":300,"elapsed":127,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"4dd5123f-dafc-4022-8ad3-0defc50eb880"},"execution_count":null,"outputs":[{"output_type":"error","ename":"ValueError","evalue":"Needs to be a string","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)","\u001b[0;32m<ipython-input-14-9436908cf828>\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mget_ticket_dummy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'$nvda going strong!'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;32m<ipython-input-12-3c692c303b52>\u001b[0m in \u001b[0;36mget_ticket_dummy\u001b[0;34m(text)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mget_ticket_dummy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m\"Needs to be a string\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;34m\"the stock ticker\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;31mValueError\u001b[0m: Needs to be a string"]}]},{"cell_type":"code","source":["def get_ticket_dummy(text: str) -> str:\n"," if type(text) is not str:\n"," raise ValueError (\"Needs to be a string\")\n"," return \"the stock ticker\""],"metadata":{"id":"VC2dwZizlZY5"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["get_ticket_dummy(10)"],"metadata":{"id":"BrgTdxkwlqKa","executionInfo":{"status":"error","timestamp":1705615214394,"user_tz":300,"elapsed":126,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"f2b06dac-df36-4c29-b62d-5e82466b1019","colab":{"base_uri":"https://localhost:8080/","height":286}},"execution_count":null,"outputs":[{"output_type":"error","ename":"ValueError","evalue":"Needs to be a string","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)","\u001b[0;32m<ipython-input-16-d5947b92d53d>\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mget_ticket_dummy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;32m<ipython-input-15-9b45e6dc05cc>\u001b[0m in \u001b[0;36mget_ticket_dummy\u001b[0;34m(text)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mget_ticket_dummy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m\"Needs to be a string\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;34m\"the stock ticker\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;31mValueError\u001b[0m: Needs to be a string"]}]},{"cell_type":"markdown","source":["Lecture3"],"metadata":{"id":"LYysqhwudGfA"}},{"cell_type":"code","source":["def my_decorator(func):\n"," print('I have decorated the function')\n"," return func\n","\n","@my_decorator\n","def say_something():\n"," print('hello')\n"],"metadata":{"id":"xlucUq1BlsWW","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1706049246928,"user_tz":300,"elapsed":138,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"c3a972c0-729b-406d-8f03-918d8718a4e3"},"execution_count":2,"outputs":[{"output_type":"stream","name":"stdout","text":["I have decorated the function\n"]}]},{"cell_type":"code","source":["my_decorator(say_something)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"XkxcxaZiekT6","executionInfo":{"status":"ok","timestamp":1706049589176,"user_tz":300,"elapsed":116,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"b718f5a1-91ec-441c-b630-7442243c0aa6"},"execution_count":12,"outputs":[{"output_type":"stream","name":"stdout","text":["I have decorated the function\n"]},{"output_type":"execute_result","data":{"text/plain":["<function __main__.say_something()>"]},"metadata":{},"execution_count":12}]},{"cell_type":"code","source":["say_something = my_decorator(say_something)\n","#same as above"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"tbnVCWGXdwRC","executionInfo":{"status":"ok","timestamp":1706049583152,"user_tz":300,"elapsed":109,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"3fc8bf1f-4e9f-482b-cf50-ac9a39081f0b"},"execution_count":11,"outputs":[{"output_type":"stream","name":"stdout","text":["I have decorated the function\n"]}]},{"cell_type":"code","source":["say_something()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"ArgRpSMeeMD3","executionInfo":{"status":"ok","timestamp":1706049460723,"user_tz":300,"elapsed":4,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"1f16aba3-fe50-4d94-8876-7ea060ae2085"},"execution_count":6,"outputs":[{"output_type":"stream","name":"stdout","text":["hello\n"]}]},{"cell_type":"code","source":["---"],"metadata":{"id":"CAEPy6pofb26"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["def goodbye():\n"," return 'bye'\n","\n","def my_decorator(func):\n"," print('I have decorated the function')\n"," return goodbye\n","\n","def hello():\n"," print('hello')\n","\n","\n","what_is_this = my_decorator(hello)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"gVsOIpLDfd5s","executionInfo":{"status":"ok","timestamp":1706049912068,"user_tz":300,"elapsed":133,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"9b514c31-77b9-4c38-8757-7de6c06c6ad4"},"execution_count":15,"outputs":[{"output_type":"stream","name":"stdout","text":["I have decorated the function\n"]}]},{"cell_type":"code","source":["def goodbye():\n"," return 'bye'\n","\n","def my_decorator(func):\n"," print('I have decorated the function')\n"," return goodbye\n","\n","@my_decorator\n","def hello():\n"," print('hello')\n","\n","hello()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":53},"id":"a7rHnQWwhHqz","executionInfo":{"status":"ok","timestamp":1706050690195,"user_tz":300,"elapsed":6,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"e8629089-728f-4922-86b0-3e5395086947"},"execution_count":28,"outputs":[{"output_type":"stream","name":"stdout","text":["I have decorated the function\n"]},{"output_type":"execute_result","data":{"text/plain":["'bye'"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"string"}},"metadata":{},"execution_count":28}]},{"cell_type":"code","source":["hello()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":35},"id":"LjLdoxDLhOf9","executionInfo":{"status":"ok","timestamp":1706050254134,"user_tz":300,"elapsed":6,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"47b51e29-ac82-49e9-8c9d-aeb1ec703c41"},"execution_count":21,"outputs":[{"output_type":"execute_result","data":{"text/plain":["'bye'"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"string"}},"metadata":{},"execution_count":21}]},{"cell_type":"code","source":["what_is_this()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":35},"id":"qP8X_L3qfwdN","executionInfo":{"status":"ok","timestamp":1706050001611,"user_tz":300,"elapsed":4,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"921b86aa-b18f-49ac-e211-43daf7d37b22"},"execution_count":17,"outputs":[{"output_type":"execute_result","data":{"text/plain":["'bye'"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"string"}},"metadata":{},"execution_count":17}]},{"cell_type":"code","source":["x = goodbye\n","y=x\n","y()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":35},"id":"uMBh-64zgbyB","executionInfo":{"status":"ok","timestamp":1706050055988,"user_tz":300,"elapsed":5,"user":{"displayName":"Johnny Ye","userId":"16268450102215689935"}},"outputId":"109aa117-9444-4066-e5cc-478c1e51d8c9"},"execution_count":19,"outputs":[{"output_type":"execute_result","data":{"text/plain":["'bye'"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"string"}},"metadata":{},"execution_count":19}]}]} |