{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"gpuType":"T4","mount_file_id":"1mKOJzH3W0Hbq4uOwWd0_A8JWcu9h7-Kt","authorship_tag":"ABX9TyN0HJtMemhIoE//VSqQI7Vs"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"},"accelerator":"GPU"},"cells":[{"cell_type":"code","execution_count":1,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"rrVka8vkDUnk","executionInfo":{"status":"ok","timestamp":1687084683192,"user_tz":-330,"elapsed":8332,"user":{"displayName":"Growth Ai","userId":"13899479888288343300"}},"outputId":"ba6bf15b-464a-4df5-f0d7-30702fa2b6dd"},"outputs":[{"output_type":"stream","name":"stdout","text":["Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n","Collecting openai\n"," Downloading openai-0.27.8-py3-none-any.whl (73 kB)\n","\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/73.6 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m73.6/73.6 kB\u001b[0m \u001b[31m3.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25hRequirement already satisfied: requests>=2.20 in /usr/local/lib/python3.10/dist-packages (from openai) (2.27.1)\n","Requirement already satisfied: tqdm in /usr/local/lib/python3.10/dist-packages (from openai) (4.65.0)\n","Collecting aiohttp (from openai)\n"," Downloading aiohttp-3.8.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB)\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.0/1.0 MB\u001b[0m \u001b[31m22.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25hRequirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.20->openai) (1.26.15)\n","Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests>=2.20->openai) (2022.12.7)\n","Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.10/dist-packages (from requests>=2.20->openai) (2.0.12)\n","Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests>=2.20->openai) (3.4)\n","Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->openai) (23.1.0)\n","Collecting multidict<7.0,>=4.5 (from aiohttp->openai)\n"," Downloading multidict-6.0.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (114 kB)\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m114.5/114.5 kB\u001b[0m \u001b[31m14.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25hCollecting async-timeout<5.0,>=4.0.0a3 (from aiohttp->openai)\n"," Downloading async_timeout-4.0.2-py3-none-any.whl (5.8 kB)\n","Collecting yarl<2.0,>=1.0 (from aiohttp->openai)\n"," Downloading yarl-1.9.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (268 kB)\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m268.8/268.8 kB\u001b[0m \u001b[31m32.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25hCollecting frozenlist>=1.1.1 (from aiohttp->openai)\n"," Downloading frozenlist-1.3.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (149 kB)\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m149.6/149.6 kB\u001b[0m \u001b[31m17.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25hCollecting aiosignal>=1.1.2 (from aiohttp->openai)\n"," Downloading aiosignal-1.3.1-py3-none-any.whl (7.6 kB)\n","Installing collected packages: multidict, frozenlist, async-timeout, yarl, aiosignal, aiohttp, openai\n","Successfully installed aiohttp-3.8.4 aiosignal-1.3.1 async-timeout-4.0.2 frozenlist-1.3.3 multidict-6.0.4 openai-0.27.8 yarl-1.9.2\n"]}],"source":["!pip install openai"]},{"cell_type":"code","source":["import pandas as pd\n","import openai\n","\n","openai.api_key = \"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\"\n","\n","import warnings\n","warnings.filterwarnings('ignore')\n","\n","from IPython.display import HTML, display\n","\n","def set_css():\n"," display(HTML('''\n"," \n"," '''))\n","get_ipython().events.register('pre_run_cell', set_css)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":37},"id":"xlOoq63SFSnf","executionInfo":{"status":"ok","timestamp":1687087645213,"user_tz":-330,"elapsed":524,"user":{"displayName":"Growth Ai","userId":"13899479888288343300"}},"outputId":"1e9cc857-3a66-41e5-e45d-23cc2b64ed56"},"execution_count":5,"outputs":[{"output_type":"display_data","data":{"text/plain":[""],"text/html":["\n"," \n"," "]},"metadata":{}}]},{"cell_type":"markdown","source":["#Paraphrasing Text"],"metadata":{"id":"iINv9L-PHKko"}},{"cell_type":"code","source":["prompt = \"Rewrite the following abstract to avoid heavy scientific jargon and use simpler vocabulary: \"\n","\n","abstract = \\\n","\"Current treatments for depression are limited by suboptimal efficacy, delayed response, \\\n","and frequent side effects. Intermittent theta-burst stimulation (iTBS) is a non-invasive brain stimulation treatment that is \\\n","FDA-approved for treatment-resistant depression (TRD). Recent methodological advancements suggest iTBS could be improved \\\n","through 1) treating with multiple sessions per day at optimally-spaced intervals, 2) applying a higher overall pulse-dose \\\n","of stimulation and 3) precision targeting of the left dorsolateral prefrontal cortex (L-DLPFC) to subgenual anterior cingulate \\\n","cortex (sgACC) circuit. We examined the feasibility, tolerability, and preliminary efficacy of an accelerated, high-dose, \\\n","resting-state functional connectivity MRI (fcMRI)-guided iTBS protocol for TRD termed \\\n","‘Stanford Accelerated Intelligent Neuromodulation Therapy (SAINT)’.\"\n","\n","response = openai.Completion.create(\n"," model=\"text-davinci-003\",\n"," prompt= prompt + abstract,\n"," temperature=0.0,\n"," max_tokens=300,\n"," top_p=1.0,\n"," frequency_penalty=0.0,\n"," presence_penalty=0.0\n",")\n","# Will response in laymen language for news\n","print (response[\"choices\"][0][\"text\"])"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":213},"id":"8R2gLDDOGZtG","executionInfo":{"status":"ok","timestamp":1687088086818,"user_tz":-330,"elapsed":6806,"user":{"displayName":"Growth Ai","userId":"13899479888288343300"}},"outputId":"43ef4b7b-8726-4c73-e090-543eaadf72d1"},"execution_count":7,"outputs":[{"output_type":"display_data","data":{"text/plain":[""],"text/html":["\n"," \n"," "]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":[""],"text/html":["\n"," \n"," "]},"metadata":{}},{"output_type":"stream","name":"stdout","text":["\n","\n","Current treatments for depression can be limited by their lack of effectiveness, slow response time, and side effects. Intermittent theta-burst stimulation (iTBS) is a non-invasive brain stimulation treatment that has been approved by the FDA for treatment-resistant depression (TRD). Recent research suggests that iTBS could be improved by 1) having multiple sessions per day at the right intervals, 2) using a higher overall amount of stimulation, and 3) targeting the left dorsolateral prefrontal cortex (L-DLPFC) to subgenual anterior cingulate cortex (sgACC) circuit more precisely. We looked into the feasibility, tolerability, and preliminary effectiveness of an accelerated, high-dose, resting-state functional connectivity MRI (fcMRI)-guided iTBS protocol for TRD called 'Stanford Accelerated Intelligent Neuromodulation Therapy (SAINT)'.\n"]}]},{"cell_type":"markdown","source":["#Summarize"],"metadata":{"id":"O-lB9yg_S4VA"}},{"cell_type":"code","source":["import requests\n","from bs4 import BeautifulSoup\n","\n","prompt = \"Summarize what is journalistically newsworthy about the following proposed bill: \"\n","\n","url = \"http://malegislature.gov/Bills/193/SD1827/Senate/Bill/Text\"\n","response = requests.get(url, verify=False)\n","soup = BeautifulSoup(response.text, 'html.parser')\n","bill_text = soup.get_text()\n","\n","response = openai.Completion.create(\n"," model=\"text-davinci-003\",\n"," prompt= prompt + bill_text,\n"," temperature=0.7,\n"," max_tokens=250,\n"," top_p=1.0,\n"," frequency_penalty=0.0,\n"," presence_penalty=0.0\n",")\n","\n","print(response[\"choices\"][0][\"text\"])"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":178},"id":"hPZ6wWkUIdBy","executionInfo":{"status":"ok","timestamp":1687088605378,"user_tz":-330,"elapsed":6036,"user":{"displayName":"Growth Ai","userId":"13899479888288343300"}},"outputId":"7032af8c-34b7-4fc2-8d91-5d4a40225065"},"execution_count":8,"outputs":[{"output_type":"display_data","data":{"text/plain":[""],"text/html":["\n"," \n"," "]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":[""],"text/html":["\n"," \n"," "]},"metadata":{}},{"output_type":"stream","name":"stdout","text":["\n","The proposed bill, SD.1827, seeks to regulate large-scale generative artificial intelligence models, such as ChatGPT, in order to protect the public’s safety, privacy and intellectual property rights. It would require companies to adhere to certain operating standards, register with the attorney general, and would create an enforcement mechanism for violations. It would also provide a public registry of all companies registered under the act, and would include a disclaimer that any errors or inaccuracies in the bill should not be attributed to the language model but rather to its human authors. This proposed bill is newsworthy as it seeks to protect the public from potential harms related to the use of artificial intelligence models.\n"]}]},{"cell_type":"markdown","source":["#Prepare News Article"],"metadata":{"id":"qKcAzkX5VeKD"}},{"cell_type":"code","source":["import requests\n","from bs4 import BeautifulSoup\n","\n","prompt = \"Brainstorm three specific news article ideas by critically assessing the following press release, explaining each idea: \"\n","\n","url = \"https://www.nyc.gov/office-of-the-mayor/news/077-23/mayor-adams-helps-new-yorkers-save-up-150-million-overdue-water-bills\"\n","response = requests.get(url, verify=False)\n","soup = BeautifulSoup(response.text, 'html.parser')\n","press_release_text = soup.select_one(\".col-content\").get_text()\n","\n","response = openai.Completion.create(\n"," model=\"text-davinci-003\",\n"," prompt= prompt + press_release_text,\n"," temperature=0.7,\n"," max_tokens=500,\n"," top_p=1.0,\n"," frequency_penalty=0.0,\n"," presence_penalty=0.8\n",")\n","\n","print(response[\"choices\"][0][\"text\"])"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":248},"id":"-LwnxU-qUQvQ","executionInfo":{"status":"ok","timestamp":1687089424460,"user_tz":-330,"elapsed":8404,"user":{"displayName":"Growth Ai","userId":"13899479888288343300"}},"outputId":"2ea81bc1-c5b9-476e-9a5e-8da6d63504d0"},"execution_count":10,"outputs":[{"output_type":"display_data","data":{"text/plain":[""],"text/html":["\n"," \n"," "]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":[""],"text/html":["\n"," \n"," "]},"metadata":{}},{"output_type":"stream","name":"stdout","text":["1. \"New York City Mayor Eric Adams Launches Temporary Water Bill Amnesty Program to Help New Yorkers Save up to $150 Million\": This article would focus on the specifics of the program itself, what it offers, and how it is helping New Yorkers save money. \n","\n","2. \"Mayor Eric Adams' Program Helps Nearly 200,000 Customers Overcome their Outstanding Water Bill Debts\": This article would examine the impact of the program on those who are struggling with overdue water bills. It would explore the economic and financial benefits that the program provides to customers and why it is so needed in today's economy. \n","\n","3. \"Mayor Eric Adams' Water Bill Amnesty Program: How it is Impacting NYC's Water Infrastructure\": This article would examine how this program is helping New York City's infrastructure and how it is ensuring that the city can continue to invest in and maintain its critical water systems. It would also look at how this program is helping to reduce the amount of overdue bills to allow for more investment in the city's water infrastructure.\n"]}]},{"cell_type":"markdown","source":["#Segregation"],"metadata":{"id":"xISYLRIdaEIg"}},{"cell_type":"code","source":["import json\n","import time\n","from openai.error import RateLimitError\n","\n","sample_comments = [\"We were considering converting to gas when replacing our stove. We went with induction instead. It’s amazing. Cooks food/boils water faster. Is 90% efficient vs. gas 30% efficacy. Equipped with an air fryer function. We had to purchase new cook wear that is required because of the magnification properties on the burners. You need pots that are made to adhere so to speak to burners while heating. But it’s worth it! Love our new pots and get dinner ready faster. Now if it would only clean -up.\",\n"," \"When we first moved into our house (we weren't the first owner) it had a conventional electric cooktop. Conventional electric stoves just plain suck for a variety of reasons. But we were lucky, because the builder of our house included both a gas pipe and a 220 volt outlet in the island where the cooktop sat. We considered replacing the electric cooktop with an induction one but didn't want to spend the time, effort and money to replace the majority of our cookware with pots and pans that were magnetic. So in our case it was easy work to yank the electric cooktop and replace it with a gas one. It took the appliance store guys about 30 minutes to make the switch. A couple of years ago we remodeled our kitchen, and in the big scheme of cost and inconvenience, replacing our cookware was pretty trivial. So we finally got our induction cooktop. It combines the best features of electric (more efficient than gas, no air pollution) with the best features of gas (easy and quick to regulate temperature), and includes advantages neither one has (doesn't heat up the kitchen, cooktop doesn't stay burning hot for long when cooking is done), and it heats things faster than either electric or gas. Without a doubt induction cooking is the way of the future. And I'm sure prices will come down as more home owners who can't or don't want to spend on high-end appliances start to demand them.\",\n"," \"We have a gas stove, and like it. Our range hood is vented to the outside. We will be getting an induction range within 2 to 4 years. We are older, and it is a safer option since there will not be an open flame. We took this decision before the \\\"controversy\\\" arose. Gas stoves are better than standard electric in some areas (where gas is cheaper), and work very well. It is also true that the products of combustion are a problem. Houseplants help, opening windows helps, range hoods help. Nothing works perfectly.\",\n"," \"Unless you have a small home with little ventilation, the risk from gas stove emissions is quite small. After cooking on a induction stove top for a year in a rental we opted for gas when we put a new stove in our own house. It is well ventilated and this old house provides a lot of unplanned ventilation too.\",\n"," \"And just so we're all clear: the suitability of a pan for induction cooking is not \\\"adhesion\\\". Testing with a magnet is a quick way to determine whether the pan has enough ferrous metal to respond to the magnetic field generate by the element.\",\n"," \"The gas stove hullabaloo is absurd. The matter of the plastic straws is infinitely more serious because they stay out there essentially forever and affect other creatures. I have no problem banning them.\"\n"," ]\n","\n","prompt = 'Does the following comment describe someone\\'s experience of switching to an induction cooktop? Respond with JSON structured data with a \"label\" field that is either \"yes\" or \"no\" and and \"explanation\" field that provides an explanation of why it\\'s labeled that way: '\n","\n","output_data = []\n","\n","for ncomment, comment_text in enumerate(sample_comments):\n"," print (\"Testing comment\", ncomment)\n","\n"," try:\n"," response = openai.Completion.create(\n"," model=\"text-davinci-003\",\n"," prompt= prompt + comment_text,\n"," temperature=0.0, # We don't want any variability in the responses\n"," max_tokens=256,\n"," top_p=1.0,\n"," frequency_penalty=0.0,\n"," presence_penalty=0.0\n"," )\n","\n"," data = {}\n"," data[\"response\"] = json.loads(response[\"choices\"][0][\"text\"])\n"," data[\"comment\"] = comment_text\n"," output_data.append(data)\n"," #print (data)\n","\n"," # You need to sleep for 3 seconds in between API calls to avoid being rate limited (the rate limit is 20 calls / minute for the free tier)\n"," time.sleep(5)\n"," except RateLimitError as e:\n"," print (e)\n"," time.sleep (10) # Wait some more\n","\n","# Outcome the final data\n","print (json.dumps(output_data, indent=2))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":1000},"id":"2HYcRPyCXS1w","executionInfo":{"status":"ok","timestamp":1687090091696,"user_tz":-330,"elapsed":36682,"user":{"displayName":"Growth Ai","userId":"13899479888288343300"}},"outputId":"02a6d2b8-432d-4fa3-eec2-69383b07d85f"},"execution_count":11,"outputs":[{"output_type":"display_data","data":{"text/plain":[""],"text/html":["\n"," \n"," "]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":[""],"text/html":["\n"," \n"," "]},"metadata":{}},{"output_type":"stream","name":"stdout","text":["Testing comment 0\n","Testing comment 1\n","Testing comment 2\n","Testing comment 3\n","Testing comment 4\n","Testing comment 5\n","[\n"," {\n"," \"response\": {\n"," \"label\": \"yes\",\n"," \"explanation\": \"The comment describes a positive experience with an induction cooktop, including its efficiency, air fryer function, and the need to purchase new cookware.\"\n"," },\n"," \"comment\": \"We were considering converting to gas when replacing our stove. We went with induction instead. It\\u2019s amazing. Cooks food/boils water faster. Is 90% efficient vs. gas 30% efficacy. Equipped with an air fryer function. We had to purchase new cook wear that is required because of the magnification properties on the burners. You need pots that are made to adhere so to speak to burners while heating. But it\\u2019s worth it! Love our new pots and get dinner ready faster. Now if it would only clean -up.\"\n"," },\n"," {\n"," \"response\": {\n"," \"label\": \"Yes\",\n"," \"explanation\": \"The comment describes the experience of switching from an electric cooktop to an induction cooktop.\"\n"," },\n"," \"comment\": \"When we first moved into our house (we weren't the first owner) it had a conventional electric cooktop. Conventional electric stoves just plain suck for a variety of reasons. But we were lucky, because the builder of our house included both a gas pipe and a 220 volt outlet in the island where the cooktop sat. We considered replacing the electric cooktop with an induction one but didn't want to spend the time, effort and money to replace the majority of our cookware with pots and pans that were magnetic. So in our case it was easy work to yank the electric cooktop and replace it with a gas one. It took the appliance store guys about 30 minutes to make the switch. A couple of years ago we remodeled our kitchen, and in the big scheme of cost and inconvenience, replacing our cookware was pretty trivial. So we finally got our induction cooktop. It combines the best features of electric (more efficient than gas, no air pollution) with the best features of gas (easy and quick to regulate temperature), and includes advantages neither one has (doesn't heat up the kitchen, cooktop doesn't stay burning hot for long when cooking is done), and it heats things faster than either electric or gas. Without a doubt induction cooking is the way of the future. And I'm sure prices will come down as more home owners who can't or don't want to spend on high-end appliances start to demand them.\"\n"," },\n"," {\n"," \"response\": {\n"," \"label\": \"no\",\n"," \"explanation\": \"This comment does not describe someone's experience of switching to an induction cooktop, as they have not yet made the switch.\"\n"," },\n"," \"comment\": \"We have a gas stove, and like it. Our range hood is vented to the outside. We will be getting an induction range within 2 to 4 years. We are older, and it is a safer option since there will not be an open flame. We took this decision before the \\\"controversy\\\" arose. Gas stoves are better than standard electric in some areas (where gas is cheaper), and work very well. It is also true that the products of combustion are a problem. Houseplants help, opening windows helps, range hoods help. Nothing works perfectly.\"\n"," },\n"," {\n"," \"response\": {\n"," \"label\": \"no\",\n"," \"explanation\": \"The comment does not describe someone's experience of switching to an induction cooktop.\"\n"," },\n"," \"comment\": \"Unless you have a small home with little ventilation, the risk from gas stove emissions is quite small. After cooking on a induction stove top for a year in a rental we opted for gas when we put a new stove in our own house. It is well ventilated and this old house provides a lot of unplanned ventilation too.\"\n"," },\n"," {\n"," \"response\": {\n"," \"label\": \"no\",\n"," \"explanation\": \"This comment does not describe someone's experience of switching to an induction cooktop.\"\n"," },\n"," \"comment\": \"And just so we're all clear: the suitability of a pan for induction cooking is not \\\"adhesion\\\". Testing with a magnet is a quick way to determine whether the pan has enough ferrous metal to respond to the magnetic field generate by the element.\"\n"," },\n"," {\n"," \"response\": {\n"," \"label\": \"no\",\n"," \"explanation\": \"The comment does not describe someone's experience of switching to an induction cooktop.\"\n"," },\n"," \"comment\": \"The gas stove hullabaloo is absurd. The matter of the plastic straws is infinitely more serious because they stay out there essentially forever and affect other creatures. I have no problem banning them.\"\n"," }\n","]\n"]}]},{"cell_type":"markdown","source":["#Getting Structured Data"],"metadata":{"id":"ChgozN2abtr4"}},{"cell_type":"code","source":["import time\n","from openai.error import RateLimitError\n","\n","\n","sample_documents = [\"1996-1997 EXECUTIVE ASSISTANT MINISTER OF TRANSPORT\",\n","\"Special Assistant 1991 to 1993 Hon. Robert Kaplan\",\n","\"September 1984 to February 1988 Senior Policy Analyst - various assignments related to federal procurement and trade policy Department of Supply and Services\",\n","\"January 2002 to May 2002 Chief of Staff Office of the Minister of Public Works and Government Services Canada\"\n","]\n","\n","\n","prompt = 'Extract two dates or years from the input data. Also extract a job description from each line of text in the input data. Create a three-column table with the first date, second date, and job description. If there is no date or job description, leave the column blank. \\\n","Use the following format: first date || second date || job description \\\n","input data: '\n","\n","\n","for ndoc, document_text in enumerate(sample_documents):\n"," # Construct the API request\n"," try:\n"," response = openai.Completion.create(\n"," model=\"text-davinci-003\",\n"," prompt= prompt + document_text,\n"," temperature=0.7,\n"," max_tokens=256,\n"," top_p=1.0,\n"," frequency_penalty=0.0,\n"," presence_penalty=0.0\n"," )\n","\n"," print (response[\"choices\"][0][\"text\"])\n","\n"," time.sleep(3)\n"," except RateLimitError as e:\n"," print (e)\n"," time.sleep (10)\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":266},"id":"V_mqTAHcZ0Ql","executionInfo":{"status":"ok","timestamp":1687090676754,"user_tz":-330,"elapsed":15338,"user":{"displayName":"Growth Ai","userId":"13899479888288343300"}},"outputId":"01b836a2-f346-4a80-8a71-2eedce03bf1f"},"execution_count":12,"outputs":[{"output_type":"display_data","data":{"text/plain":[""],"text/html":["\n"," \n"," "]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":[""],"text/html":["\n"," \n"," "]},"metadata":{}},{"output_type":"stream","name":"stdout","text":["\n","\n","1996 || 1997 || Executive Assistant Minister of Transport\n","\n","\n","1991 || 1993 || Special Assistant Hon. Robert Kaplan\n","\n","\n","September 1984 || February 1988 || Senior Policy Analyst - various assignments related to federal procurement and trade policy\n","\n","\n","January 2002 || May 2002 || Chief of Staff Office of the Minister of Public Works and Government Services Canada\n"]}]},{"cell_type":"markdown","source":["# Table to Text"],"metadata":{"id":"iF-GwHacdq9e"}},{"cell_type":"code","source":["\n","prompt = \"Write a short description of this week's Accident activity based on the following data: \"\n","\n","\n","data = \"State: California \\\n","Activity Level: High \\\n","Rate for visits to emergency departments or urgent care centers: 21.1%\"\n","\n","response = openai.Completion.create(\n"," model=\"text-davinci-003\",\n"," prompt= prompt + data,\n"," temperature=0.7,\n"," max_tokens=256,\n"," top_p=1.0,\n"," frequency_penalty=0.0,\n"," presence_penalty=0.0\n",")\n","\n","print (response[\"choices\"][0][\"text\"])"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":108},"id":"hL81koAPduRd","executionInfo":{"status":"ok","timestamp":1687091246688,"user_tz":-330,"elapsed":1636,"user":{"displayName":"Growth Ai","userId":"13899479888288343300"}},"outputId":"abe0a723-e2b7-4f42-8c66-595dee5ec5a2"},"execution_count":14,"outputs":[{"output_type":"display_data","data":{"text/plain":[""],"text/html":["\n"," \n"," "]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":[""],"text/html":["\n"," \n"," "]},"metadata":{}},{"output_type":"stream","name":"stdout","text":["\n","\n","This week in California, the accident activity level is high, with a rate of 21.1% for visits to emergency departments or urgent care centers. This is an indication of a higher than average amount of accidents taking place in the state.\n"]}]},{"cell_type":"code","source":[],"metadata":{"id":"-aiiAhQsd0BW"},"execution_count":null,"outputs":[]}]}