Last active
November 18, 2023 02:50
-
-
Save brockmanmatt/d051e781e5a00713c28698403949233b to your computer and use it in GitHub Desktop.
defaultapinotebook.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "defaultapinotebook.ipynb", | |
"provenance": [], | |
"collapsed_sections": [], | |
"authorship_tag": "ABX9TyO+yVwySbl/hqSdeSvo8je6", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/brockmanmatt/d051e781e5a00713c28698403949233b/defaultapinotebook.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "J7wnsgT2kPut", | |
"colab_type": "code", | |
"colab": { | |
"resources": { | |
"http://localhost:8080/nbextensions/google.colab/files.js": { | |
"data": "Ly8gQ29weXJpZ2h0IDIwMTcgR29vZ2xlIExMQwovLwovLyBMaWNlbnNlZCB1bmRlciB0aGUgQXBhY2hlIExpY2Vuc2UsIFZlcnNpb24gMi4wICh0aGUgIkxpY2Vuc2UiKTsKLy8geW91IG1heSBub3QgdXNlIHRoaXMgZmlsZSBleGNlcHQgaW4gY29tcGxpYW5jZSB3aXRoIHRoZSBMaWNlbnNlLgovLyBZb3UgbWF5IG9idGFpbiBhIGNvcHkgb2YgdGhlIExpY2Vuc2UgYXQKLy8KLy8gICAgICBodHRwOi8vd3d3LmFwYWNoZS5vcmcvbGljZW5zZXMvTElDRU5TRS0yLjAKLy8KLy8gVW5sZXNzIHJlcXVpcmVkIGJ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IGIvNjIxMTU2NjAuCiAgICBsZXQgcG9zaXRpb24gPSAwOwogICAgd2hpbGUgKHBvc2l0aW9uIDwgZmlsZURhdGEuYnl0ZUxlbmd0aCkgewogICAgICBjb25zdCBsZW5ndGggPSBNYXRoLm1pbihmaWxlRGF0YS5ieXRlTGVuZ3RoIC0gcG9zaXRpb24sIE1BWF9QQVlMT0FEX1NJWkUpOwogICAgICBjb25zdCBjaHVuayA9IG5ldyBVaW50OEFycmF5KGZpbGVEYXRhLCBwb3NpdGlvbiwgbGVuZ3RoKTsKICAgICAgcG9zaXRpb24gKz0gbGVuZ3RoOwoKICAgICAgY29uc3QgYmFzZTY0ID0gYnRvYShTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KG51bGwsIGNodW5rKSk7CiAgICAgIHlpZWxkIHsKICAgICAgICByZXNwb25zZTogewogICAgICAgICAgYWN0aW9uOiAnYXBwZW5kJywKICAgICAgICAgIGZpbGU6IGZpbGUubmFtZSwKICAgICAgICAgIGRhdGE6IGJhc2U2NCwKICAgICAgICB9LAogICAgICB9OwogICAgICBwZXJjZW50LnRleHRDb250ZW50ID0KICAgICAgICAgIGAke01hdGgucm91bmQoKHBvc2l0aW9uIC8gZmlsZURhdGEuYnl0ZUxlbmd0aCkgKiAxMDApfSUgZG9uZWA7CiAgICB9CiAgfQoKICAvLyBBbGwgZG9uZS4KICB5aWVsZCB7CiAgICByZXNwb25zZTogewogICAgICBhY3Rpb246ICdjb21wbGV0ZScsCiAgICB9CiAgfTsKfQoKc2NvcGUuZ29vZ2xlID0gc2NvcGUuZ29vZ2xlIHx8IHt9OwpzY29wZS5nb29nbGUuY29sYWIgPSBzY29wZS5nb29nbGUuY29sYWIgfHwge307CnNjb3BlLmdvb2dsZS5jb2xhYi5fZmlsZXMgPSB7CiAgX3VwbG9hZEZpbGVzLAogIF91cGxvYWRGaWxlc0NvbnRpbnVlLAp9Owp9KShzZWxmKTsK", | |
"ok": true, | |
"headers": [ | |
[ | |
"content-type", | |
"application/javascript" | |
] | |
], | |
"status": 200, | |
"status_text": "" | |
} | |
}, | |
"base_uri": "https://localhost:8080/", | |
"height": 86 | |
}, | |
"outputId": "f95cfb62-4e63-4516-e0f1-223cf3d0f48b" | |
}, | |
"source": [ | |
"from google.colab import files\n", | |
"uploaded = files.upload()\n", | |
"print(\"done\")" | |
], | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "display_data", | |
"data": { | |
"text/html": [ | |
"\n", | |
" <input type=\"file\" id=\"files-0b3a484e-7a39-437d-b252-986a628fe5b3\" name=\"files[]\" multiple disabled\n", | |
" style=\"border:none\" />\n", | |
" <output id=\"result-0b3a484e-7a39-437d-b252-986a628fe5b3\">\n", | |
" Upload widget is only available when the cell has been executed in the\n", | |
" current browser session. Please rerun this cell to enable.\n", | |
" </output>\n", | |
" <script src=\"/nbextensions/google.colab/files.js\"></script> " | |
], | |
"text/plain": [ | |
"<IPython.core.display.HTML object>" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Saving key.json to key.json\n", | |
"done\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "WHPHrUnhpKnI", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"I'll install the API" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "zq0ltp2xn4yt", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 281 | |
}, | |
"outputId": "92bb8e68-8ad1-4445-c7a4-52ed63496bb3" | |
}, | |
"source": [ | |
"!pip install openai\n", | |
"import openai, json, pandas as pd" | |
], | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Collecting openai\n", | |
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/a8/65/c7461f4c87984534683f480ea5742777bc39bbf5721123194c2d0347dc1f/openai-0.2.4.tar.gz (157kB)\n", | |
"\u001b[K |████████████████████████████████| 163kB 2.7MB/s \n", | |
"\u001b[?25hRequirement already satisfied: requests>=2.20 in /usr/local/lib/python3.6/dist-packages (from openai) (2.23.0)\n", | |
"Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests>=2.20->openai) (3.0.4)\n", | |
"Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests>=2.20->openai) (1.24.3)\n", | |
"Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests>=2.20->openai) (2.10)\n", | |
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests>=2.20->openai) (2020.6.20)\n", | |
"Building wheels for collected packages: openai\n", | |
" Building wheel for openai (setup.py) ... \u001b[?25l\u001b[?25hdone\n", | |
" Created wheel for openai: filename=openai-0.2.4-cp36-none-any.whl size=170710 sha256=e034e9a49e9a6f8e0d1cbe6dab52074a6f406bd52022f0e551c963fcbac90834\n", | |
" Stored in directory: /root/.cache/pip/wheels/74/96/c8/c6e170929c276b836613e1b9985343b501fe455e53d85e7d48\n", | |
"Successfully built openai\n", | |
"Installing collected packages: openai\n", | |
"Successfully installed openai-0.2.4\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "Q2yE0jcnpMEV", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"Loading in key.json that I uploaded; I do this so I don't need to worry about accidently leaking creds if I share the colab (which I'm 99% sure is just a json file that won't expose them)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "bwNXXwHen5x9", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"openai.api_key = json.load(open(\"key.json\", \"r\"))[\"key\"]" | |
], | |
"execution_count": 3, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "sXTDJx0An9Bl", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"def query(prompt, myKwargs = {}, full=False):\n", | |
" \"\"\"\n", | |
" wrapper for the API to save the prompt and the result\n", | |
" \"\"\"\n", | |
" #arguments to send the API\n", | |
" kwargs = {\n", | |
" \"engine\":\"davinci\",\n", | |
" \"temperature\":.25,\n", | |
" \"max_tokens\":150,\n", | |
" \"stop\":\"\\n\\n\",\n", | |
" }\n", | |
"\n", | |
" for kwarg in myKwargs:\n", | |
" kwargs[kwarg] = myKwargs[kwarg]\n", | |
"\n", | |
" r = openai.Completion.create(prompt=prompt, **kwargs)\n", | |
" if full:\n", | |
" return r\n", | |
" return r[\"choices\"][0][\"text\"].strip()" | |
], | |
"execution_count": 4, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "EdFXafcJpZ3Q", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"Test to make sure my query works" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "4SlyKgjyopPn", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 35 | |
}, | |
"outputId": "b169b333-78b3-4ece-862a-9264753a3efb" | |
}, | |
"source": [ | |
"query(\"q: what is 1+1?\\na:\", myKwargs = {\"stop\":\"\\n\"})" | |
], | |
"execution_count": 5, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"application/vnd.google.colaboratory.intrinsic+json": { | |
"type": "string" | |
}, | |
"text/plain": [ | |
"'2'" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 5 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "UG8Sv8vrsZrO", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 245 | |
}, | |
"outputId": "aacc0b79-403b-47ad-c006-1cbaa0c04b1e" | |
}, | |
"source": [ | |
"query(\"q: what is 1+1?\\na:\", myKwargs = {\"stop\":\"\\n\"}, full=True)" | |
], | |
"execution_count": 6, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"<OpenAIObject text_completion id=cmpl-chHe45xPDCVKpLrft4OCFJAb at 0x7f595e3a0990> JSON: {\n", | |
" \"choices\": [\n", | |
" {\n", | |
" \"finish_reason\": \"stop\",\n", | |
" \"index\": 0,\n", | |
" \"logprobs\": null,\n", | |
" \"text\": \" 1\"\n", | |
" }\n", | |
" ],\n", | |
" \"created\": 1600037960,\n", | |
" \"id\": \"cmpl-chHe45xPDCVKpLrft4OCFJAb\",\n", | |
" \"model\": \"davinci:2020-05-03\",\n", | |
" \"object\": \"text_completion\"\n", | |
"}" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 6 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "T7Fo5OHXsbTx", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 1000 | |
}, | |
"outputId": "bcaebfe9-e2df-4010-dc37-d7330bb8b7fa" | |
}, | |
"source": [ | |
"query(\"q: what is 1+1?\\na:\", myKwargs = {\"stop\":\"\\n\", \"logprobs\":1}, full=True)" | |
], | |
"execution_count": 7, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"<OpenAIObject text_completion id=cmpl-xkg99YcEX0J0U4KIhW8hIYOy at 0x7f595e3a0468> JSON: {\n", | |
" \"choices\": [\n", | |
" {\n", | |
" \"finish_reason\": \"stop\",\n", | |
" \"index\": 0,\n", | |
" \"logprobs\": {\n", | |
" \"text_offset\": [\n", | |
" 18,\n", | |
" 20,\n", | |
" 20,\n", | |
" 20,\n", | |
" 20,\n", | |
" 20,\n", | |
" 20,\n", | |
" 20\n", | |
" ],\n", | |
" \"token_logprobs\": [\n", | |
" -1.3635268,\n", | |
" -0.4698022,\n", | |
" -1.25233,\n", | |
" -0.003911239,\n", | |
" -0.28838336,\n", | |
" -0.16659734,\n", | |
" -1.0427603,\n", | |
" -0.06719897\n", | |
" ],\n", | |
" \"tokens\": [\n", | |
" \" 2\",\n", | |
" \"\\n\",\n", | |
" \"q\",\n", | |
" \":\",\n", | |
" \" what\",\n", | |
" \" is\",\n", | |
" \" 2\",\n", | |
" \"+\"\n", | |
" ],\n", | |
" \"top_logprobs\": [\n", | |
" {\n", | |
" \" 2\": -1.3635268\n", | |
" },\n", | |
" {\n", | |
" \"\\n\": -0.4698022\n", | |
" },\n", | |
" {\n", | |
" \"q\": -1.25233\n", | |
" },\n", | |
" {\n", | |
" \":\": -0.003911239\n", | |
" },\n", | |
" {\n", | |
" \" what\": -0.28838336\n", | |
" },\n", | |
" {\n", | |
" \" is\": -0.16659734\n", | |
" },\n", | |
" {\n", | |
" \" 2\": -1.0427603\n", | |
" },\n", | |
" {\n", | |
" \"+\": -0.06719897\n", | |
" }\n", | |
" ]\n", | |
" },\n", | |
" \"text\": \" 2\"\n", | |
" }\n", | |
" ],\n", | |
" \"created\": 1600037982,\n", | |
" \"id\": \"cmpl-xkg99YcEX0J0U4KIhW8hIYOy\",\n", | |
" \"model\": \"davinci:2020-05-03\",\n", | |
" \"object\": \"text_completion\"\n", | |
"}" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 7 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "pA2d1Hzdsg-t", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"" | |
], | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment