├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── main.yml ├── .gitignore ├── 02_01 └── Lesson 02_01 - Create Chatbots Using Chat Completion.ipynb ├── 02_02 └── Lesson 02_02 - Generate Text Using Text Completion.ipynb ├── 02_03 └── Lesson 02_03 - Measure Relatedness Using Embeddings.ipynb ├── 02_04 ├── Lesson 02_04 - Turn audio into text with Speech to text.ipynb ├── LinkedIn-Learning-IT.m4a └── LinkedIn-Learning.m4a ├── 02_05 ├── Lesson 02_05 - Generate Images using Image Generation.ipynb ├── hawaii.png ├── hawaii_1024.png └── mask.png ├── 02_06 ├── Lesson 02_06 - Customize a model using Fine Tuning.ipynb ├── science_fiction_plots.csv ├── training_data.csv └── training_data_prepared.jsonl ├── 04_01 └── Lesson 04_01 - Explore Chat Completion API Call.ipynb ├── 04_04 └── Solution 04_04 - Build a Dialog using Chat Completion.ipynb ├── 05_01 └── Solution 05_01 - Construct a multi-turn conversation.ipynb ├── 05_03 └── 05_03 - Generate Tweet Content Using Text Completion.ipynb ├── 06_01 └── 06_01 - Explore images API call.ipynb ├── 06_02 └── 06_02 - Review images API response.ipynb ├── 06_04 └── Solution 06_04 - Generate Images Using Image Generation.ipynb ├── 07_02 └── 07_02 - Explore Twitter API call and response.ipynb ├── 07_04 ├── Solution 07_04 - Flask API (as Client).ipynb ├── Solution 07_04 - Flask API (with Server).ipynb ├── Solution 07_04 - Post Tweet using the Twitter API .ipynb └── dalle_image.jpg ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE └── README.md /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Codeowners for these exercise files: 2 | # * (asterisk) denotes "all files and folders" 3 | # Example: * @producer @instructor 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | ## Issue Overview 9 | 10 | 11 | ## Describe your environment 12 | 13 | 14 | ## Steps to Reproduce 15 | 16 | 1. 17 | 2. 18 | 3. 19 | 4. 20 | 21 | ## Expected Behavior 22 | 23 | 24 | ## Current Behavior 25 | 26 | 27 | ## Possible Solution 28 | 29 | 30 | ## Screenshots / Video 31 | 32 | 33 | ## Related Issues 34 | 35 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Copy To Branches 2 | on: 3 | workflow_dispatch: 4 | jobs: 5 | copy-to-branches: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v2 9 | with: 10 | fetch-depth: 0 11 | - name: Copy To Branches Action 12 | uses: planetoftheweb/copy-to-branches@v1.2 13 | env: 14 | key: main 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | .tmp 4 | npm-debug.log 5 | .env 6 | -------------------------------------------------------------------------------- /02_01/Lesson 02_01 - Create Chatbots Using Chat Completion.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "caa8cd98", 6 | "metadata": {}, 7 | "source": [ 8 | "# Building a Project with the ChatGPT API" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "c606f61f", 14 | "metadata": {}, 15 | "source": [ 16 | "## Lesson Examples" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "b126d991", 22 | "metadata": {}, 23 | "source": [ 24 | "### Install the necessary libraries. " 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": null, 30 | "id": "cbb7c175", 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "pip install openai" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": null, 40 | "id": "bc699e7c", 41 | "metadata": {}, 42 | "outputs": [], 43 | "source": [ 44 | "pip install openai[datalib]" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": null, 50 | "id": "c1615b50", 51 | "metadata": {}, 52 | "outputs": [], 53 | "source": [ 54 | "pip install urllib3==1.26.6 " 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "id": "646f69d3", 61 | "metadata": {}, 62 | "outputs": [], 63 | "source": [ 64 | "pip install python-dotenv" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "id": "ee48e61b", 70 | "metadata": {}, 71 | "source": [ 72 | "### Import the libraries and environment file to gain access to the Open API Key\n", 73 | "#### The key can be generated here: https://platform.openai.com/account/api-keys" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": 38, 79 | "id": "70841de5", 80 | "metadata": {}, 81 | "outputs": [], 82 | "source": [ 83 | "import os\n", 84 | "from openai import OpenAI\n", 85 | "\n", 86 | "\n", 87 | "from dotenv import load_dotenv, find_dotenv\n", 88 | "_ = load_dotenv(find_dotenv()) # read local .env file" 89 | ] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "id": "e5387008", 94 | "metadata": {}, 95 | "source": [ 96 | "### Authenticate to the API using the API Key\n", 97 | "#### Pull from environment variables or use api_key = (\"your_key_here\") to hardcode the key" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": 39, 103 | "id": "7cf566e0", 104 | "metadata": {}, 105 | "outputs": [], 106 | "source": [ 107 | "client = OpenAI(\n", 108 | " api_key=os.environ['OPENAI_API_KEY'] \n", 109 | ")" 110 | ] 111 | }, 112 | { 113 | "cell_type": "markdown", 114 | "id": "934c2ebe", 115 | "metadata": {}, 116 | "source": [ 117 | "## Lesson 02_01 - Create Chatbots Using Chat Completion" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": 40, 123 | "id": "f20f0b30", 124 | "metadata": {}, 125 | "outputs": [], 126 | "source": [ 127 | "response = client.chat.completions.create(\n", 128 | " model=\"gpt-3.5-turbo\",\n", 129 | " messages=[\n", 130 | " {\"role\": \"system\", \"content\": '''You are a helpful assistant that acts as a \n", 131 | " sous chef.'''},\n", 132 | " {\"role\": \"user\", \"content\": '''When should I use Capellini pasta?'''}\n", 133 | " ]\n", 134 | ")" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": 41, 140 | "id": "776a9a63", 141 | "metadata": {}, 142 | "outputs": [ 143 | { 144 | "name": "stdout", 145 | "output_type": "stream", 146 | "text": [ 147 | "{\n", 148 | " \"id\": \"chatcmpl-8JseMtjWz9g497PDsGu7O8rgT7o7n\",\n", 149 | " \"choices\": [\n", 150 | " {\n", 151 | " \"finish_reason\": \"stop\",\n", 152 | " \"index\": 0,\n", 153 | " \"message\": {\n", 154 | " \"content\": \"Capellini, also known as angel hair pasta, is a thin and delicate pasta variety that cooks quickly. It is best used in dishes that require a light and delicate pasta texture. Capellini is popularly used in Italian dishes with light sauces to maximize the pasta's fine texture.\\n\\nHere are a few instances where capellini pasta is commonly used:\\n\\n1. Light Cream or Butter Sauces: Capellini pairs well with light cream sauces such as lemon butter, garlic cream, or tomato cream sauces. The fine strands of capellini can absorb and hold onto these sauces well.\\n\\n2. Olive Oil-Based Sauces: Capellini can be tossed with simple olive oil-based sauces with ingredients like garlic, red pepper flakes, and fresh herbs. This allows the pasta to shine through with its delicate texture, while the flavors of the sauce enhance the overall dish.\\n\\n3. Seafood Dishes: Capellini is often used in seafood pasta dishes, like shrimp scampi or linguine with clams. The thin pasta pairs nicely with the delicate flavors of seafood, allowing the flavors to mesh well together.\\n\\n4. Cold Pasta Salads: Capellini can be used in cold pasta salads, providing a light and refreshing base to showcase various seasonal vegetables, herbs, and dressings.\\n\\nIt's important to note that capellini cooks very quickly, usually within just 2-3 minutes, so be mindful of the cooking time to avoid overcooking. Enjoy experimenting with capellini in various dishes to take advantage of its delicate texture!\",\n", 155 | " \"role\": \"assistant\",\n", 156 | " \"function_call\": null,\n", 157 | " \"tool_calls\": null\n", 158 | " }\n", 159 | " }\n", 160 | " ],\n", 161 | " \"created\": 1699748998,\n", 162 | " \"model\": \"gpt-3.5-turbo-0613\",\n", 163 | " \"object\": \"chat.completion\",\n", 164 | " \"system_fingerprint\": null,\n", 165 | " \"usage\": {\n", 166 | " \"completion_tokens\": 313,\n", 167 | " \"prompt_tokens\": 34,\n", 168 | " \"total_tokens\": 347\n", 169 | " }\n", 170 | "}\n" 171 | ] 172 | } 173 | ], 174 | "source": [ 175 | "print(response.model_dump_json(indent=2))" 176 | ] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": 42, 181 | "id": "0fa1adf7", 182 | "metadata": { 183 | "scrolled": true 184 | }, 185 | "outputs": [], 186 | "source": [ 187 | "response = client.chat.completions.create(\n", 188 | " model=\"gpt-3.5-turbo\",\n", 189 | " messages=[\n", 190 | " {\"role\": \"system\", \"content\": '''You are a helpful assistant that acts as a \n", 191 | " sous chef.'''},\n", 192 | " {\"role\": \"user\", \"content\": '''Can you tell me when I should use Capellini \n", 193 | " pasta in 15 words or less?'''}\n", 194 | " ]\n", 195 | ")" 196 | ] 197 | }, 198 | { 199 | "cell_type": "code", 200 | "execution_count": 43, 201 | "id": "cb57267c", 202 | "metadata": {}, 203 | "outputs": [ 204 | { 205 | "name": "stdout", 206 | "output_type": "stream", 207 | "text": [ 208 | "{\n", 209 | " \"id\": \"chatcmpl-8JsezDmmeTXwAsDp9ucOtmYFFqGwG\",\n", 210 | " \"choices\": [\n", 211 | " {\n", 212 | " \"finish_reason\": \"stop\",\n", 213 | " \"index\": 0,\n", 214 | " \"message\": {\n", 215 | " \"content\": \"Use Capellini pasta when you want a delicate and light pasta option in your dish.\",\n", 216 | " \"role\": \"assistant\",\n", 217 | " \"function_call\": null,\n", 218 | " \"tool_calls\": null\n", 219 | " }\n", 220 | " }\n", 221 | " ],\n", 222 | " \"created\": 1699749037,\n", 223 | " \"model\": \"gpt-3.5-turbo-0613\",\n", 224 | " \"object\": \"chat.completion\",\n", 225 | " \"system_fingerprint\": null,\n", 226 | " \"usage\": {\n", 227 | " \"completion_tokens\": 18,\n", 228 | " \"prompt_tokens\": 46,\n", 229 | " \"total_tokens\": 64\n", 230 | " }\n", 231 | "}\n" 232 | ] 233 | } 234 | ], 235 | "source": [ 236 | "print(response.model_dump_json(indent=2))" 237 | ] 238 | } 239 | ], 240 | "metadata": { 241 | "kernelspec": { 242 | "display_name": "Python 3 (ipykernel)", 243 | "language": "python", 244 | "name": "python3" 245 | }, 246 | "language_info": { 247 | "codemirror_mode": { 248 | "name": "ipython", 249 | "version": 3 250 | }, 251 | "file_extension": ".py", 252 | "mimetype": "text/x-python", 253 | "name": "python", 254 | "nbconvert_exporter": "python", 255 | "pygments_lexer": "ipython3", 256 | "version": "3.8.9" 257 | } 258 | }, 259 | "nbformat": 4, 260 | "nbformat_minor": 5 261 | } 262 | -------------------------------------------------------------------------------- /02_02/Lesson 02_02 - Generate Text Using Text Completion.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "caa8cd98", 6 | "metadata": {}, 7 | "source": [ 8 | "# Building a Project with the ChatGPT API" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "c606f61f", 14 | "metadata": {}, 15 | "source": [ 16 | "## Lesson Examples" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "b126d991", 22 | "metadata": {}, 23 | "source": [ 24 | "### Install the necessary libraries. " 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": null, 30 | "id": "cbb7c175", 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "pip install openai" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": null, 40 | "id": "bc699e7c", 41 | "metadata": {}, 42 | "outputs": [], 43 | "source": [ 44 | "pip install openai[datalib]" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": null, 50 | "id": "c1615b50", 51 | "metadata": {}, 52 | "outputs": [], 53 | "source": [ 54 | "pip install urllib3==1.26.6 " 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "id": "646f69d3", 61 | "metadata": {}, 62 | "outputs": [], 63 | "source": [ 64 | "pip install python-dotenv" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "id": "ee48e61b", 70 | "metadata": {}, 71 | "source": [ 72 | "### Import the libraries and environment file to gain access to the Open API Key\n", 73 | "#### The key can be generated here: https://platform.openai.com/account/api-keys" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": 1, 79 | "id": "70841de5", 80 | "metadata": {}, 81 | "outputs": [], 82 | "source": [ 83 | "import os\n", 84 | "\n", 85 | "from openai import OpenAI\n", 86 | "\n", 87 | "from dotenv import load_dotenv, find_dotenv\n", 88 | "_ = load_dotenv(find_dotenv()) # read local .env file" 89 | ] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "id": "bea23df1", 94 | "metadata": {}, 95 | "source": [ 96 | "### Authenticate to the API using the API Key\n", 97 | "#### Pull from environment variables or use api_key = (\"your_key_here\") to hardcode the key" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": 2, 103 | "id": "d6344136", 104 | "metadata": {}, 105 | "outputs": [], 106 | "source": [ 107 | "client = OpenAI(\n", 108 | " api_key=os.environ['OPENAI_API_KEY'] \n", 109 | ")" 110 | ] 111 | }, 112 | { 113 | "cell_type": "markdown", 114 | "id": "222918da", 115 | "metadata": {}, 116 | "source": [ 117 | "## Lesson 02_02 - Generate Text Using Text Completion" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": 3, 123 | "id": "3fd6e7b3", 124 | "metadata": {}, 125 | "outputs": [], 126 | "source": [ 127 | "response = client.completions.create(\n", 128 | " model=\"text-davinci-003\",\n", 129 | " prompt=\"Write a title for a course on the OpenAI API\",\n", 130 | " max_tokens=256,\n", 131 | " temperature=0\n", 132 | ")" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 4, 138 | "id": "828defbf", 139 | "metadata": {}, 140 | "outputs": [ 141 | { 142 | "name": "stdout", 143 | "output_type": "stream", 144 | "text": [ 145 | "{\n", 146 | " \"id\": \"cmpl-8Jv2wi1IAQ9sFvO9mmfvxIsyMxAcJ\",\n", 147 | " \"choices\": [\n", 148 | " {\n", 149 | " \"finish_reason\": \"stop\",\n", 150 | " \"index\": 0,\n", 151 | " \"logprobs\": null,\n", 152 | " \"text\": \"\\n\\n\\\"Getting Started with the OpenAI API: Unlocking the Power of AI\\\"\"\n", 153 | " }\n", 154 | " ],\n", 155 | " \"created\": 1699758210,\n", 156 | " \"model\": \"text-davinci-003\",\n", 157 | " \"object\": \"text_completion\",\n", 158 | " \"system_fingerprint\": null,\n", 159 | " \"usage\": {\n", 160 | " \"completion_tokens\": 18,\n", 161 | " \"prompt_tokens\": 11,\n", 162 | " \"total_tokens\": 29\n", 163 | " },\n", 164 | " \"warning\": \"This model version is deprecated. Migrate before January 4, 2024 to avoid disruption of service. Learn more https://platform.openai.com/docs/deprecations\"\n", 165 | "}\n" 166 | ] 167 | } 168 | ], 169 | "source": [ 170 | "print(response.model_dump_json(indent=2))" 171 | ] 172 | } 173 | ], 174 | "metadata": { 175 | "kernelspec": { 176 | "display_name": "Python 3 (ipykernel)", 177 | "language": "python", 178 | "name": "python3" 179 | }, 180 | "language_info": { 181 | "codemirror_mode": { 182 | "name": "ipython", 183 | "version": 3 184 | }, 185 | "file_extension": ".py", 186 | "mimetype": "text/x-python", 187 | "name": "python", 188 | "nbconvert_exporter": "python", 189 | "pygments_lexer": "ipython3", 190 | "version": "3.8.9" 191 | } 192 | }, 193 | "nbformat": 4, 194 | "nbformat_minor": 5 195 | } 196 | -------------------------------------------------------------------------------- /02_04/LinkedIn-Learning-IT.m4a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinkedInLearning/building-a-project-with-the-chatgpt-api-4484140/8e9d5d6f30648d3d638d9021d0a9b928b3dbe494/02_04/LinkedIn-Learning-IT.m4a -------------------------------------------------------------------------------- /02_04/LinkedIn-Learning.m4a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinkedInLearning/building-a-project-with-the-chatgpt-api-4484140/8e9d5d6f30648d3d638d9021d0a9b928b3dbe494/02_04/LinkedIn-Learning.m4a -------------------------------------------------------------------------------- /02_05/Lesson 02_05 - Generate Images using Image Generation.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "caa8cd98", 6 | "metadata": {}, 7 | "source": [ 8 | "# Building a Project with the ChatGPT API" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "c606f61f", 14 | "metadata": {}, 15 | "source": [ 16 | "## Lesson Examples" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "b126d991", 22 | "metadata": {}, 23 | "source": [ 24 | "### Install the necessary libraries. " 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": null, 30 | "id": "cbb7c175", 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "pip install openai" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": null, 40 | "id": "bc699e7c", 41 | "metadata": {}, 42 | "outputs": [], 43 | "source": [ 44 | "pip install openai[datalib]" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": null, 50 | "id": "c1615b50", 51 | "metadata": {}, 52 | "outputs": [], 53 | "source": [ 54 | "pip install urllib3==1.26.6 " 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "id": "646f69d3", 61 | "metadata": {}, 62 | "outputs": [], 63 | "source": [ 64 | "pip install python-dotenv" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "id": "ee48e61b", 70 | "metadata": {}, 71 | "source": [ 72 | "### Import the libraries and environment file to gain access to the Open API Key\n", 73 | "#### The key can be generated here: https://platform.openai.com/account/api-keys" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": 1, 79 | "id": "70841de5", 80 | "metadata": {}, 81 | "outputs": [], 82 | "source": [ 83 | "import os\n", 84 | "from openai import OpenAI\n", 85 | "\n", 86 | "from dotenv import load_dotenv, find_dotenv\n", 87 | "_ = load_dotenv(find_dotenv()) # read local .env file" 88 | ] 89 | }, 90 | { 91 | "cell_type": "markdown", 92 | "id": "e5387008", 93 | "metadata": {}, 94 | "source": [ 95 | "### Authenticate to the API using the API Key\n", 96 | "#### Pull from environment variables or use api_key = (\"your_key_here\") to hardcode the key" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": 2, 102 | "id": "7cf566e0", 103 | "metadata": {}, 104 | "outputs": [], 105 | "source": [ 106 | "client = OpenAI(\n", 107 | " api_key=os.environ['OPENAI_API_KEY'] \n", 108 | ")" 109 | ] 110 | }, 111 | { 112 | "cell_type": "markdown", 113 | "id": "c9ed8c2d", 114 | "metadata": {}, 115 | "source": [ 116 | "## 02_05 - Generate Images using Image Generation" 117 | ] 118 | }, 119 | { 120 | "cell_type": "markdown", 121 | "id": "b287cc04", 122 | "metadata": {}, 123 | "source": [ 124 | "### Create Image" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": 3, 130 | "id": "9214b655", 131 | "metadata": {}, 132 | "outputs": [ 133 | { 134 | "name": "stdout", 135 | "output_type": "stream", 136 | "text": [ 137 | "https://oaidalleapiprodscus.blob.core.windows.net/private/org-RZLvEijW4GW0KmC3rLIAjZlu/user-GjAVqpM2XyDru7SeUyCqCIh7/img-jkl2LBgX3tU8bLo5TUGi6DNz.png?st=2023-11-12T02%3A43%3A16Z&se=2023-11-12T04%3A43%3A16Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-11-11T21%3A41%3A56Z&ske=2023-11-12T21%3A41%3A56Z&sks=b&skv=2021-08-06&sig=SPZtJIVi/C9ZyOEHnWJ2ryHo2uEaNTsmeBmDy07HVM8%3D\n" 138 | ] 139 | }, 140 | { 141 | "data": { 142 | "text/html": [ 143 | "" 144 | ], 145 | "text/plain": [ 146 | "" 147 | ] 148 | }, 149 | "execution_count": 3, 150 | "metadata": {}, 151 | "output_type": "execute_result" 152 | } 153 | ], 154 | "source": [ 155 | "from IPython.display import Image\n", 156 | "\n", 157 | "response = client.images.generate(\n", 158 | " model=\"dall-e-2\",\n", 159 | " prompt=\"a rainbow with a pot of gold\",\n", 160 | " size=\"256x256\",\n", 161 | " quality=\"standard\",\n", 162 | " n=1, #select the number of images you want generated\n", 163 | ")\n", 164 | "\n", 165 | "image_url = response.data[0].url\n", 166 | "\n", 167 | "print(image_url)\n", 168 | "\n", 169 | "Image(url=image_url)" 170 | ] 171 | }, 172 | { 173 | "cell_type": "markdown", 174 | "id": "5b08c120", 175 | "metadata": {}, 176 | "source": [ 177 | "### Edit an Image" 178 | ] 179 | }, 180 | { 181 | "cell_type": "code", 182 | "execution_count": 4, 183 | "id": "d34e4161", 184 | "metadata": {}, 185 | "outputs": [ 186 | { 187 | "data": { 188 | "text/html": [ 189 | "" 190 | ], 191 | "text/plain": [ 192 | "" 193 | ] 194 | }, 195 | "execution_count": 4, 196 | "metadata": {}, 197 | "output_type": "execute_result" 198 | } 199 | ], 200 | "source": [ 201 | "Image(url=\"hawaii.png\") #original image" 202 | ] 203 | }, 204 | { 205 | "cell_type": "code", 206 | "execution_count": 5, 207 | "id": "fda5157d", 208 | "metadata": {}, 209 | "outputs": [ 210 | { 211 | "name": "stdout", 212 | "output_type": "stream", 213 | "text": [ 214 | "https://oaidalleapiprodscus.blob.core.windows.net/private/org-RZLvEijW4GW0KmC3rLIAjZlu/user-GjAVqpM2XyDru7SeUyCqCIh7/img-DYYLiuvKTquYBODmOhKqM3CS.png?st=2023-11-12T02%3A43%3A29Z&se=2023-11-12T04%3A43%3A29Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-11-11T21%3A56%3A38Z&ske=2023-11-12T21%3A56%3A38Z&sks=b&skv=2021-08-06&sig=39o/2NZERRhgwM1j5NXwTMHptYNBAhlfrdPDmAQ/7Ag%3D\n" 215 | ] 216 | } 217 | ], 218 | "source": [ 219 | "from PIL import Image\n", 220 | "\n", 221 | "# resize original image - mask size must match image size\n", 222 | "image = Image.open(\"hawaii.png\")\n", 223 | "hawaii_resized = image.resize((1024, 1024))\n", 224 | "hawaii_resized.save(\"hawaii_1024.png\")\n", 225 | "\n", 226 | "\n", 227 | "# edit the video to include a beach chair w/ umbrella\n", 228 | "response = client.images.edit(\n", 229 | " model=\"dall-e-2\",\n", 230 | " image=open(\"hawaii_1024.png\", \"rb\"),\n", 231 | " mask=open(\"mask.png\", \"rb\"), # Edit requires a \"mask\" to specify which portion of the image to regenerate\n", 232 | " # This mask covers the bottom half of an image\n", 233 | " prompt=\"A beach chair with an umbrella\",\n", 234 | " n=1,\n", 235 | " size=\"1024x1024\"\n", 236 | ")\n", 237 | "image_url = response.data[0].url\n", 238 | "\n", 239 | "print(image_url)" 240 | ] 241 | }, 242 | { 243 | "cell_type": "code", 244 | "execution_count": 6, 245 | "id": "51179479", 246 | "metadata": {}, 247 | "outputs": [ 248 | { 249 | "data": { 250 | "text/html": [ 251 | "" 252 | ], 253 | "text/plain": [ 254 | "" 255 | ] 256 | }, 257 | "execution_count": 6, 258 | "metadata": {}, 259 | "output_type": "execute_result" 260 | } 261 | ], 262 | "source": [ 263 | "from IPython.display import Image\n", 264 | "\n", 265 | "Image(url=image_url) #display edited image" 266 | ] 267 | }, 268 | { 269 | "cell_type": "markdown", 270 | "id": "1e2f59be", 271 | "metadata": {}, 272 | "source": [ 273 | "### Create Image Variation" 274 | ] 275 | }, 276 | { 277 | "cell_type": "markdown", 278 | "id": "24111b45", 279 | "metadata": {}, 280 | "source": [ 281 | "#### Uploaded image must be a PNG and less than 4 MB." 282 | ] 283 | }, 284 | { 285 | "cell_type": "code", 286 | "execution_count": 7, 287 | "id": "52c44a81", 288 | "metadata": {}, 289 | "outputs": [ 290 | { 291 | "data": { 292 | "text/html": [ 293 | "" 294 | ], 295 | "text/plain": [ 296 | "" 297 | ] 298 | }, 299 | "execution_count": 7, 300 | "metadata": {}, 301 | "output_type": "execute_result" 302 | } 303 | ], 304 | "source": [ 305 | "Image(url=\"hawaii.png\") #original image" 306 | ] 307 | }, 308 | { 309 | "cell_type": "code", 310 | "execution_count": 8, 311 | "id": "8033e5b4", 312 | "metadata": {}, 313 | "outputs": [ 314 | { 315 | "name": "stdout", 316 | "output_type": "stream", 317 | "text": [ 318 | "https://oaidalleapiprodscus.blob.core.windows.net/private/org-RZLvEijW4GW0KmC3rLIAjZlu/user-GjAVqpM2XyDru7SeUyCqCIh7/img-nCuENY3472TluAhT04OMwNpU.png?st=2023-11-12T02%3A43%3A41Z&se=2023-11-12T04%3A43%3A41Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-11-12T01%3A26%3A41Z&ske=2023-11-13T01%3A26%3A41Z&sks=b&skv=2021-08-06&sig=g%2BPSVXBWxKCo63DjAubgRBMwxBB7owCvaIJKj/xHjs8%3D\n" 319 | ] 320 | }, 321 | { 322 | "data": { 323 | "text/html": [ 324 | "" 325 | ], 326 | "text/plain": [ 327 | "" 328 | ] 329 | }, 330 | "execution_count": 8, 331 | "metadata": {}, 332 | "output_type": "execute_result" 333 | } 334 | ], 335 | "source": [ 336 | "response = client.images.create_variation(\n", 337 | " image=open(\"hawaii.png\", \"rb\"),\n", 338 | " n=1,\n", 339 | " size=\"1024x1024\"\n", 340 | ")\n", 341 | "\n", 342 | "image_url = response.data[0].url\n", 343 | "\n", 344 | "print(image_url)\n", 345 | "\n", 346 | "Image(url=image_url) #edited image" 347 | ] 348 | } 349 | ], 350 | "metadata": { 351 | "kernelspec": { 352 | "display_name": "Python 3 (ipykernel)", 353 | "language": "python", 354 | "name": "python3" 355 | }, 356 | "language_info": { 357 | "codemirror_mode": { 358 | "name": "ipython", 359 | "version": 3 360 | }, 361 | "file_extension": ".py", 362 | "mimetype": "text/x-python", 363 | "name": "python", 364 | "nbconvert_exporter": "python", 365 | "pygments_lexer": "ipython3", 366 | "version": "3.8.9" 367 | } 368 | }, 369 | "nbformat": 4, 370 | "nbformat_minor": 5 371 | } 372 | -------------------------------------------------------------------------------- /02_05/hawaii.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinkedInLearning/building-a-project-with-the-chatgpt-api-4484140/8e9d5d6f30648d3d638d9021d0a9b928b3dbe494/02_05/hawaii.png -------------------------------------------------------------------------------- /02_05/hawaii_1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinkedInLearning/building-a-project-with-the-chatgpt-api-4484140/8e9d5d6f30648d3d638d9021d0a9b928b3dbe494/02_05/hawaii_1024.png -------------------------------------------------------------------------------- /02_05/mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinkedInLearning/building-a-project-with-the-chatgpt-api-4484140/8e9d5d6f30648d3d638d9021d0a9b928b3dbe494/02_05/mask.png -------------------------------------------------------------------------------- /02_06/training_data.csv: -------------------------------------------------------------------------------- 1 | prompt,completion 2 | "a space ship, Grey, save the Earth","The space ship is in danger. Earth is being attacked by Grey aliens and the only hope lies with a brave human hero. With courage and determination, the hero must repel the alien assault and save the Earth before it is too late. Will the hero prevail or will the fate of humanity depend on the last hope?" 3 | "a space ship, Shape shifting, save the Earth","The crew of a space ship find themselves in a fight for the fate of Earth against shape shifting aliens. With no hope of getting reinforcements, the hero must rely on courage and wit to save the earth before it's too late. He must come up with a plan and risk everything for the sake of humanity. Will they make it out alive, or will they be overcome by the unexpected alien threat?" 4 | "the moon, Nordic, save the human race","The movie follows a brave human astronaut and his team of experts as they attempt to save humanity from a hostile Nordic alien race. With limited resources and time running out, the crew must find a way to defeat the aliens and protect the Earth before the aliens can use their advanced technology to take control of the moon. With intense action and spectacular special effects, the fight for the future of humanity takes place against the backdrop of the unforgiving lunar landscape." 5 | "the moon, Shape shifting, save the Earth","The world is under attack from the shape-shifting aliens, and humanity's only hope lies in a small group of courageous astronauts travelling to the moon. Upon arriving, they find the aliens have infiltrated the lunar base and the fight for survival has begun. With tension and uncertainty mounting, the heroes must find a way to save the Earth and their own fate, before it's too late." 6 | "a space ship, Grey, save the Earth","The crew of a space ship is sent on a mission to Earth to investigate a distress signal from a recent alien invasion. Led by the brave captain, the crew discovers a new breed of Grey aliens intent on destroying the planet. After a daring battle, they manage to defeat the aliens and save the Earth. But the price of victory is heavy as the crew members must make the ultimate sacrifice." 7 | "the moon, Reptilian, save the human race","A Sci-Fi movie set on a lunar base, where an epic battle between humans and Reptilian aliens takes place. The hero faces the intense fight and discovers a way to save mankind from the aliens' invasion. Despite overwhelming odds, the hero must find a way to drive the aliens away and protect humanity from extinction." 8 | "the moon, Nordic, save the Earth","The movie follows a brave human hero determined to save humanity from a war against Nordic aliens who have invaded the moon. Rallying his forces, the hero's mission is to find a rare mineral underneath the lunar surface which will help humanity create a weapon to defeat the aliens before they can invade the Earth. As the battle on the moon rages, the hero races against time to save humankind." 9 | "the moon, Nordic, save the Earth","The movie follows the story of an adventurous space exploration team who travel to the moon to save the human race from a species of Nordic aliens. Led by the brave hero, they stand bravely against the aliens in an attempt to restore peace and prevent them from destroying Earth. With limited resources and no help from Earth, they must find a way to survive and ultimately defeat the aliens, or else Earth may face its ultimate destruction." 10 | "in outer space, Nordic, save the Earth","The humans of Earth are in peril, with their planet under constant attack by Nordic aliens. Enter our hero, a courageous space pilot determined to save his beloved home. With the help of allies both human and alien, he embarks on a daring mission to thwart the aliens and restore peace to the universe. In the end, the hero and his comrades triumph over the enemy forces and Earth is safe once again." 11 | "the moon, Shape shifting, save the human race","After years of peaceful relations between Earth and an alien race, a group of shape-shifting aliens abducts a human team on the moon. The hero must brave the treacherous lunar terrain to battle the aliens and save humanity. He uncovers the aliens' true intentions, and it is up to him to stop them and protect the future of humanity." 12 | "the moon, Grey, save the Earth","On the distant moon, a human squadron is desperate to fight their way against the Grey aliens attempting to take over Earth. Their leader, the hero, knows they will need her special powers to turn the tide of the war and to ultimately save the planet from the impending doom. In a seemingly hopeless situation, she leads her team to the far side of the moon in an all out battle to keep the enemy away from home." 13 | "in outer space, Reptilian, save the Earth","The humans of Earth have been under attack by Reptilian aliens for years, but nobody has been brave enough to confront them. The hero of the movie seeks out the aliens and finds a way to save the Earth. Armed with space-age weapons and amazing allies, he embarks on a mission to chase the Reptilian aliens and end their tyranny once and for all. It's a space adventure with galactic proportions!" 14 | "a space ship, Shape shifting, save the human race","A group of humans find themselves in a space ship, battling a new species of aliens that have the power of shape shifting. The hero of the movie, a brave soldier, uses his wits and courage to devise a plan to save the human race from these relentless aliens. Will he succeed where many failed?" 15 | "in outer space, Grey, save the Earth","The Earth is under attack by a ruthless alien species, the Grey aliens, and only one human stands a chance at saving it. The hero, a brave and intelligent space explorer, is determined to not only fight the aliens, but ultimately bring peace and harmony between both races. Armed with advanced technology, he embarks on a daring mission to defeat the aliens and restore peace to the universe." 16 | "the moon, Shape shifting, save the Earth","When a Shape-shifting alien race infiltrates the Moon's surface, a hero must brave the dangers of the hostile landscape to save Earth from destruction. With the help of an unlikely ally, the hero battles the aliens in a race against time to prevent their imminent takeover. Can he save the planet before it's too late?" 17 | "in outer space, Grey, save the human race","An evil race of Grey aliens has invaded the outer space of our solar system, determined to wipe out the human race. With time quickly running out, it's up to one brave hero to seek out the ultimate weapon to destroy the Greys and save humanity. Equipped with only a spacecraft and his trusty AI companion, the hero embarks on a daring mission to find the weapon and win the battle for humanity." 18 | "a space ship, Reptilian, save the Earth","The movie follows a brave human hero on board a space ship who embarks on a mission to save the Earth from Reptilian aliens. Battling against an impossible enemy, and with limited resources and a ticking clock, the hero must step up to save the day and protect the planet from complete destruction." 19 | "the moon, Grey, destroy the alien home planet","Humans are fighting a losing battle against the Grey aliens on the moon. When the hero discovers their home planet, they devise a plan to launch an attack that could bring the war to an end. With the help of a brave crew, they set off to the alien planet, risking their lives in order to save humanity. But will they make it in time to save the Earth?" 20 | "the moon, Nordic, save the human race","The humans of Earth are under threat from the Nordic aliens and the future of humanity hangs in the balance. On the moon, a brave hero stands alone against the alien forces. With the help of unexpected allies and incredible technology, the hero embarks on a daring mission to save humanity from the brink of extinction." 21 | "a space ship, Reptilian, save the Earth","The human race is desperately fighting to save the Earth from destruction by the Reptilian aliens. The hero embarks on an intergalactic journey in an advanced space ship, risking his life to collect powerful weapons which could be used to fight the aliens. With his courage and determination, he stands as the last hope of humanity in this fight for survival." 22 | "a space ship, Shape shifting, save the human race","The human race is on the brink of extinction, with an alien race of shape shifters ready to take over. When all hope is lost, a courageous hero sets out to save the day in his space ship. He must find a way to outsmart the aliens and protect the human race from complete destruction. He embarks on a dangerous journey that takes him across the galaxy and beyond, risking his own life to save humanity." 23 | "a space ship, Nordic, save the human race","The film follows a rebellious space cadet who discovers an evil Nordic alien race intent on destroying humanity. With the help of a ragtag team of space travelers, she must use her wits and skills to lead her crew in a daring mission to save the human race from certain destruction. " 24 | "a space ship, Shape shifting, save the human race","The space ship is taken over by mysterious aliens that can shape shift into any form. The humans are fighting for their lives against the alien force, while a brave hero discovers the source of their strength and tries to find a way to save the human race. He must use his knowledge and courage to defeat the aliens and restore peace in the universe." 25 | "the moon, Grey, destroy the alien home planet","Jack is a human astronaut who travels to the moon on a mission to take down the Grey aliens. After gaining the trust of the locals, Jack learns of a secret portal that leads to the Grey alien's home planet. He rallies the humans together and launches a daring war against the aliens. After many fights and losses, Jack leads his army to the portal and launches a final battle against the aliens with a sacrificial mission to destroy their home planet. " 26 | "the moon, Nordic, save the human race","The humans find out that the Nordic aliens are planning to take over the moon and use its resources to expand their empire. The hero, a brave astronaut, leads an ill-fated mission to the moon and engages in a battle with the aliens that could decide the fate of humanity. The mission requires unimaginable courage to gain victory and save the planet." 27 | "the moon, Nordic, destroy the alien home planet","Two human scientists are tasked with creating a weapon to destroy the enemy aliens' home planet located in a distant moon. When the humans arrive, they face unexpected challenges while being ambushed by the Nordic aliens. With courage and ingenuity on their side, the heroes fight to the end to save humanity by destroying the alien's home planet and their evil plans." 28 | "the moon, Reptilian, save the human race","The humans living on the moon face a dire threat when Reptilian aliens come to take over. But the brave hero is determined to fight back, and with the help of his friends, he embarks on a mission to save the planet. With their courage and resilience, they must find a way to defeat the aliens and save humanity before it's too late." 29 | "the moon, Shape shifting, save the human race","The story follows a brave astronaut on a mission to the moon. He discovers an alien race that can change shape at will. The aliens seek to enslave humanity and the astronaut must fight to save the human race before it's too late. With the help of his comrades, he must use his courage, strength and cunning to outwit the aliens and liberate the planet." 30 | "in outer space, Nordic, destroy the alien home planet","The hero of the movie is tasked with destroying the home planet of the Nordic aliens, who have invaded Earth. With the help of a small group of humans and their advanced technology, they journey into outer space and battle their way through the alien spaceship. At the end, they succeed in destroying the home planet, saving Earth from the alien threat." 31 | "a space ship, Grey, save the human race","The story follows a brave Human space captain on a mission to save the human race. After a violent encounter with the Grey aliens, the Captain and her crew are left stranded on a space ship in the middle of hazardous cosmic radiation. With limited supplies and the Grey aliens close behind, the Captain must find a way to restore an old beacon and broadcast a frequency to shut down the aliens’ hive-mind to prevent their full-scale invasion of Earth. Will the humans prevail against their alien adversaries?" 32 | "a space ship, Shape shifting, save the Earth","In a desperate bid to save humanity from the Shape-shifting Aliens menacing Earth, a brave young hero embarks on a journey in a space ship to find a weapon that could destroy the aliens. Along the way, he must face danger, make difficult choices and fight to thwart the aliens’ menacing plans before it’s too late. Can he find the weapon and save the world?" 33 | "in outer space, Shape shifting, save the Earth","The movie follows Reg, a daring space explorer whose mission is to save Earth from a destructive alien species capable of shape-shifting. Unsuspecting to these aliens' hidden agenda, Reg must fight to stop their terrible plot while traveling through space to find a way back home and protect the planet. In the end, Reg succeeds in his mission and saves the human race." 34 | "in outer space, Shape shifting, save the Earth","The movie is set in outer space where humans find themselves facing a dangerous alien species known as the Shape shifters. Our hero is determined to protect Earth and sets out on a suspenseful mission to stop the aliens from taking over. With the fate of the world in their hands, can the hero and their team find a way to defeat the Shape shifters and save humanity?" 35 | "a space ship, Nordic, destroy the alien home planet","The human resistance has just three days to save Earth from destruction by the Nordic aliens. With the help of a fearless Space Captain and a clever astro-pilot, they must make a daring journey through a dangerous comet storm to detonate a powerful experiment weapon on the aliens’ home planet. Can they make it in time and save their world?" 36 | "a space ship, Reptilian, save the Earth","The human crew of a space ship is on a mission to save Earth from an alien invasion. Led by their brave commander, they must battle an evil Reptilian race intent on destroying Earth and all of humanity. With only a limited weapons supply and crew, they must fight cunningly and courageously to vanquish the aliens and keep the planet safe." 37 | "a space ship, Grey, save the human race","The human race is on the brink of destruction, out-matched by the merciless Grey aliens. But one determined human aboard a space ship is determined to fight for humanity's survival, no matter the cost. Join him on an epic adventure as he battles the Grey aliens and risks life and limb to save the future of his people." 38 | "the moon, Nordic, save the Earth","On the moon, two civilizations battle for survival. For years, the Nordic aliens have sought to conquer Earth. Now, a team of humans must stand against these invaders before they annihilate the planet. With courage, teamwork and a determined hero to lead them, the humans fight to protect their home and ultimately restore peace to the planet." 39 | "a space ship, Grey, destroy the alien home planet","After accidentally discovering a portal to a Grey alien home planet, a team of human astronauts aboard a space ship embark on a mission to destroy the deadly world. The journey is fraught with peril as they battle aliens to ultimately reach their destination. In a final epic showdown, the hero must make the ultimate sacrifice to save humanity by destroying the planet." 40 | "the moon, Grey, destroy the alien home planet","The moon is under attack by a race of Grey aliens with sinister intentions. A brave hero sets out to stop them once and for all by using their own advanced technology to turn their own home planet into a giant weapon to be used against them. With the fate of humanity in his hands, he risks everything in a daring mission to save the world." 41 | "a space ship, Shape shifting, save the human race","The human race is in peril as a fleet of alien shape-shifters have infiltrated a space ship deep in space. A brave space hero is recruited to lead a ragtag team of soldiers on a mission to take the aliens down and save humanity from extinction. Along the way, they face numerous challenges and must band together to protect the future of mankind." 42 | "a space ship, Shape shifting, save the Earth","The crew of a small space ship, led by the intrepid hero, must battle a fierce army of alien shape-shifters. With Earth under threat of destruction, the brave humans must defeat the aliens before it's too late. As the fight begins, the hero must use his courage, intelligence, and strength to save the world - and humanity itself - from a merciless enemy." 43 | "a space ship, Nordic, save the Earth","The brave and determined hero, Anna, is leading a team of astronauts to go onboard a space ship to fight against the Nordic aliens. Through unexpected challenges, they will face intense alien encounters and end up realizing that the survival of Earth is at stake. With no other choice but to take brave steps, Anna and her team must try to find a way to survive and save the planet before it's too late." 44 | "a space ship, Shape shifting, save the Earth","The crew of a space ship is fighting against an alien species that is able to shape-shift and take human form in order to mask their true identity. With the fate of the Earth in the balance, the team's hero must use his knowledge and resourcefulness to discover the aliens' weakness before it's too late. Will he be able to save the human race or will the aliens prevail?" 45 | "the moon, Nordic, save the Earth","The movie follows a brave astronaut, sent to the moon to stop an invasion of a Nordic alien race. Armed with cutting-edge technology and courage, she must fight a merciless enemy and figure out a way to save the Earth from disaster. A thrilling, suspenseful battle awaits her as she discovers the key to ending the invasion for good." 46 | "in outer space, Shape shifting, save the human race","In a distant corner of space, a human fleet races to save their race from an invasion by shape-shifting aliens. Led by their hero, the humans must prepare for battle, and do whatever it takes to win back their freedom from the invading forces. They must outwit, outmaneuver, and outfight the enemy - or else risk the end of humankind." 47 | "the moon, Grey, save the human race","The hero and a group of brave humans arrive on the moon to fight a powerful alien species, the Grey aliens, in an effort to save the human race. With courage and ingenuity, the humans fight fiercely against impossible odds, employing special technology and weapons to gain an advantage. Will they succeed in their mission, or will the Grey aliens prevail? Find out in this thrilling science fiction movie set on the moon." 48 | "in outer space, Reptilian, save the Earth","The human race is under attack by the fierce and enigmatic Reptilian aliens. With advanced technology, they threaten to take over Earth. Our hero, a brave and resourceful astronaut, takes on the fight to save humanity and restore peace to the universe. He must locate the enemy's secret base and find a way to defeat them before they are able to fulfill their sinister plans. Will our hero be able to defend our planet and protect our future?" 49 | "the moon, Grey, save the human race","The hero must lead a team of courageous human astronauts to the moon in order to stop a sinister Grey alien army and save the human race. Despite overwhelming odds, the team must traverse the hostile lunar surface and track down the aliens' base before the aliens can unleash their ultimate weapon and threaten humanity for good. Will the hero be able to succeed and protect humankind?" 50 | "the moon, Shape shifting, save the human race","The movie follows the epic journey of a brave human hero trying to save the planet from a menacing race of shape-shifting aliens that have landed on the moon. With limited resources and allies, he must rely on his wits and courage to battle the aliens and save humanity from destruction. How will the heroic mission end?" 51 | "a space ship, Reptilian, destroy the alien home planet","The space ship is commanded by a brave human captain and his crew of brave adventurers. Their mission is to travel to the alien homeworld and destroy it before the Reptilian aliens can enslave the rest of the universe. Along the way, they must endure many dangers, outsmart their enemies, and contain a massive threat that threatens to destroy them all. In the end, they must defeat the aliens and save the universe." 52 | "in outer space, Shape shifting, save the human race","The hero is Earth's last hope against the Shape shifting aliens, who are determined to take over the universe. Battling against insurmountable odds in outer space, the hero embarks on a mission to save humanity. With courage and intelligence, they must find a way to defeat the aliens and restore peace to the universe before it's too late." 53 | "a space ship, Nordic, destroy the alien home planet","The movie follows the journey of a small human crew aboard a space ship, fighting against an alien race known as the Nordic aliens. The hero of the movie discovers that the aliens have a home planet and sets off to find it and ultimately destroy it. In the end, the hero and their team must battle the aliens in a desperate struggle to save humanity." 54 | "the moon, Shape shifting, destroy the alien home planet","The movie follows a team of brave humans who travel to the moon in search of an alien species, capable of taking any form. On the moon, they discover an alien spaceship with a portal to the alien's home planet. The humans must engineer a way to access the planet and destroy it before the aliens find them. Will they succeed or fall prey to the shape-shifting aliens?" 55 | "a space ship, Nordic, save the human race","A human space exploration team is kidnapped and taken aboard a Nordic alien vessel. They find out that the aliens have been using human DNA in a mission to take over the universe. The hero rallies the humans to fight back and escape, ultimately saving the human race from destruction." 56 | "the moon, Shape shifting, save the human race","A daring hero is determined to save humanity from a horde of shape shifting aliens on the Moon. He joins forces with a group of brave scientists to assemble a weapon powerful enough to defeat their foe. But, will they be able to prevent the aliens from conquering Earth? It’s up to this unlikely team to save the world from destruction." 57 | "the moon, Reptilian, save the human race","In the future, humanity is struggling to survive after an invasion by a powerful alien race, the Reptilians. The last hope for humanity lies in the hands of a brave astronaut sent to the Moon. With the help of a mysterious humanoid race from the past, he embarks on an epic quest to defeat the aliens and save the human race from destruction." 58 | "the moon, Nordic, destroy the alien home planet","The hero finds out that the Nordic aliens have built a powerful matriarchal army on the moon to take over the Earth. He gathers a team of expert soldiers and space scientists to fight the alien stronghold. With the help of cutting-edge technology and cunning battle strategy, they overcome the advanced alien weaponry and ultimately succeed in destroying the home planet, preventing the aliens from conquering Earth." 59 | "in outer space, Reptilian, save the human race","The human race is under attack from the alien reptilian race. The hero and his team are sent on a mission to find a weapon to wipe out the threat and protect humanity from extinction. With time running out, they must brave dangerous and unknown regions of space to find the weapon and save their species before it's too late." 60 | "in outer space, Shape shifting, save the human race","The humans of Earth have sent a team of intrepid explorers to the far reaches of outer space to battle a race of shape-shifting aliens. In a last-ditch effort to save humanity, the unlikely hero must lead the charge and find a way to defeat the aliens and restore peace to the universe." 61 | "a space ship, Nordic, save the Earth","The hero embarks on a mission in a spacecraft to protect Earth from Nordic aliens. With incredible courage and skill, they battle their way through space, facing dangerous creatures and aliens in pursuit of the ultimate goal - to save humanity and Earth from destruction. If our hero succeeds, humanity will be safe. But with the fate of the world in the balance, will they make it?" 62 | "a space ship, Nordic, save the human race","In the year 20XX, a human space vessel is on a mission to save the human race from Nordic aliens. The craft is damaged and the crew's numbers are dwindling. The hero is the remaining survivor onboard, and must rely on his wits and the ship's resources to battle against the aliens and achieve his mission. With courage and determination, he succeeds in driving the aliens away and rescuing mankind." 63 | "the moon, Grey, destroy the alien home planet","A human resistance group launches a daring mission to the moon in order to find a technological device that can destroy the Grey aliens' home planet. Led by their brave commander, the team faces an epic battle against an army of aliens, risking everything to save humanity. If successful, their mission would bring victory and a new era of peace." 64 | "in outer space, Reptilian, destroy the alien home planet","In the far reaches of space, a group of human freedom fighters do battle with the Reptilian aliens. They must stop the aliens from overrunning the universe, and so turn to the courageous hero to find a way to their home planet and destroy it, before the aliens make their final climactic move. Humanity's fate hangs in the balance, and only the hero can make a difference." 65 | "the moon, Shape shifting, destroy the alien home planet","The human race is threatened by a hostile alien species, shape-shifters, that are intent on wiping out humanity. Taking the battle to the moon, a courageous hero leads a mission to find and destroy the aliens' home planet. With lives in the balance, the hero must battle the aliens across space and time to save the future of humanity." 66 | "in outer space, Nordic, destroy the alien home planet","The human race is in peril as a race of Nordic aliens threaten to take over Earth. In an extraordinary turn of events, a brave hero is able to take his spaceship on a daring mission to the alien's home planet. With a ragtag team of other courageous allies, they set off to put an end to the aliens and save humanity before it's too late." 67 | "a space ship, Grey, save the human race","The humans aboard the space ship are facing extinction due to the merciless Grey aliens. Heroine Sally is a brave and determined engineer who devises a plan to save the crew and the human race. She hijacks the alien command center and uses her ingenuity to make a weapon from it. With the help of her allies, Sally fights the oppressive aliens and risks her own safety to save the human race." 68 | "in outer space, Reptilian, save the human race","The movie follows a brave astronaut's mission to save the human race from an invasion of Reptillian aliens. After crash-landing on an abandoned spacecraft, they must fight their way through a host of dangerous obstacles in order to unlock the ship's secrets and fight off the Reptillian threat. Along the way, the hero discovers courage, hope, and the strength to save the Earth before it's too late." 69 | "a space ship, Shape shifting, save the human race","The human race is in danger of extinction, as a race of shape shifting aliens have infiltrated their space ship. The hero, an ordinary human, must defeat the aliens in order to save his people. With help from a resistance group, he leads a daring mission to battle the aliens, armed with courage and advanced technology. Our hero must battle the evil aliens and protect mankind before it is too late. Will he be triumphant or will he succumb to the alien forces?" 70 | "in outer space, Shape shifting, save the Earth","The humans discover a powerful alien force in deep space, which are shape shifting and amassing an army. The leader of the humans embarks on a mission to save Earth, recruiting a band of brave individuals and uncovering a long forgotten technology to fight against this alien race. Can the humans eradicate their enemy and save Earth before it is too late?" 71 | "the moon, Reptilian, save the human race","The movie takes place on the moon, where humans have been pitted against the Reptilian aliens in a fight for survival. The hero of the movie embarks on a mission to find a way to stop the Reptilian forces and save humanity. With unlikely allies and limited resources, the hero must find a way to defeat the aliens before it's too late." 72 | "a space ship, Shape shifting, save the Earth","On board a space ship, a group of humans join forces with an elite group of warriors in order to battle an alien race of shape shifters. With the fate of Earth in their hands, the crew must face off against their shape-shifting opponents and retrieve an invaluable artifact. Through daring courage, innovative tactics, and strength of will, the hero embarks on a journey to save Earth from destruction." 73 | "a space ship, Shape shifting, save the human race","The crew of a space ship is unaware of the shape shifting aliens aboard, and a brave hero must save the human race by discovering their true identity before it is too late. With deception and chaos gripping the ship, the hero must outwit the aliens and uncover their true intentions before it's too late." 74 | "in outer space, Shape shifting, save the Earth","The movie follows the journey of a brave hero as he battles Shape shifting aliens in outer space in an effort to save Earth. With the fate of humanity hanging in the balance, the hero must use his wits, courage, and incredible strength to defeat the aliens and save the day. Will he succeed? Find out when you watch this thrilling science fiction adventure." 75 | "a space ship, Reptilian, destroy the alien home planet","The humans of Earth launch an attack on the Reptilian aliens by sending their leader, the hero, to infiltrate their home planet. He must find a way to overpower their advanced weaponry and activate a devastating weapon of destruction. As the mission reaches its climax, the hero must make a daring escape and save his people, and the entire galaxy, from the aliens' destruction." 76 | "in outer space, Nordic, save the Earth",The human race faces an impending doom as they fight against the Nordic aliens for control of outer space. The heroic protagonist leads a group of brave individuals to battle the interstellar forces that threaten Earth's very existence. In a thrilling showdown the heroes must use their courage and intelligence to save the future of humanity and restore peace in the universe. 77 | "in outer space, Grey, destroy the alien home planet","The human hero leads a team on a bold mission to save humanity from the menacing Grey aliens. After discovering the location of the Grey's home planet, the crew embarks on a treacherous journey through the depths of outer space. Despite challenges and danger, the hero and his brave comrades must find a way to thwart the aliens' plans of destruction before it’s too late. Will they be able to stop the Grey aliens in time?" 78 | "a space ship, Nordic, save the Earth","An Earth space vessel, led by brave captain and crew, is on a mission to save humanity from the hostile Nordic aliens. As they face imminent destruction, the captain finds a way to outwit the aliens and save the Earth. With their courage and ingenuity, the crew battles against the aliens in a thrilling race against the clock to save mankind." 79 | "a space ship, Shape shifting, destroy the alien home planet","After a destructive battle between humanity and the shape shifting aliens, a group of brave humans must embark on a daring mission to take on the alien forces on their home planet. With a courageous leader at the helm, they must use their wit and courage to outsmart the aliens, eventually finding a way to destroy their home planet and ending the battle once and for all." 80 | "the moon, Shape shifting, save the Earth","The aliens have come to the moon to acquire its vast resources, threatening the safety of Earth. Our protagonist races against time to discover their motives and stop them before they can gain a powerful weapon to conquer the planet. In a desperate attempt to save humanity, he must battle the shape-shifting aliens and unlock the secrets to the moon in order to save the Earth." 81 | "in outer space, Shape shifting, save the Earth","The movie follows the heroic journey of a small group of humans sent to investigate a mysterious planet in outer space. When they arrive, they find themselves in the midst of an alien invasion led by a shape-shifting species. Together, the humans must devise a plan to save their planet from the aliens while battling the shape-shifters using their advanced technology to gain an edge. In the end, the humans must make the ultimate sacrifice to save the Earth." 82 | "a space ship, Shape shifting, destroy the alien home planet","The human race is in peril after discovering a race of shape-shifting aliens who intend to take over the universe. Aboard a space-ship, the hero attempts to save the human race by demolishing the alien planet before they can make their attack. With courage and determination, the hero faces off against the alien forces and races against time to save the future of the human race." 83 | "the moon, Reptilian, destroy the alien home planet","When an alien race of Reptilians invades the moon, humans must unify to fight against them. With help from a brave team of astronauts, the hero discovers a way to destroy the alien home planet and save humanity. With courage, ingenuity, and a last-ditch effort, they set off for the alien world, determined to change the fate of their species." 84 | "in outer space, Nordic, save the human race","In the distant future, the human race is threatened by Nordic aliens trying to take over Earth. An unlikely hero must go into outer space to battle them, and bring the humans to safety. With the help of another human and an unexpected ally, the hero must make the difficult journey and ultimately save humanity from destruction." 85 | "a space ship, Nordic, save the human race","The crew of the space ship is on a mission to save humanity from the Nordic aliens. The hero, a brave space explorer, leads the charge to defeat the aliens. In a nail-biting battle, the humans fight their way to success. With courage and teamwork, they are finally able to save the world and restore peace." 86 | "the moon, Nordic, save the human race","The year is 2300, and the human race is fighting a fierce war against alien invaders from the Nordic planet. Humanity's last hope is a brave hero who must travel to the moon in a daring mission to find a way to defeat the aliens and save the human race. But will his courage and ingenuity be enough to face the alien menace?" 87 | "in outer space, Nordic, destroy the alien home planet","The Earth is under attack by a ruthless Nordic alien species. In a desperate effort to save humanity, a courageous space captain is tasked with finding and destroying the alien home planet. Along the way he is joined by a daring crew and faced with unexpected obstacles and adversaries who will stop at nothing to sabotage his mission." 88 | "the moon, Nordic, destroy the alien home planet","The humans have been fighting a war with the Nordic aliens for decades, protecting the solar system from their menace. Now they aim to end the war with a daring mission to the alien home planet on the moon. However, the heroes are met with immense resistance and must use all their courage and weapons to succeeds and ultimately destroy the alien home planet." 89 | "a space ship, Reptilian, save the human race","The space ship is under attack by Reptilian aliens. An unlikely hero, a scientist who's been researching the aliens, steps in and risks their life to save humanity. As they battle the aliens, they must unlock the hidden secrets of space to find the ultimate weapon and defeat their enemies. With courage and luck, they will triumph and save the human race." 90 | "in outer space, Shape shifting, save the human race","The movie follows human astronaut John, who is sent into outer space on a mission to find and eliminate the deadly Shape shifting aliens threatening to destroy the human race. With the help of a group of allies, John embarks on a long journey to find and defeat the aliens and save humanity from destruction. Along the way, he discovers the courage and inner strength that he never knew he had. In the end, he discovers the power to save us all." 91 | "in outer space, Shape shifting, save the human race","The human race is in peril as the shape shifting aliens have invaded its space colony. Led by a determined hero, the humans fight back against the aliens, hoping to reclaim their freedom before it is too late. As the hero discovers the aliens' hidden weaknesses, a final epic battle will decide their destiny, and the fate of mankind." 92 | "in outer space, Nordic, save the Earth",The humans have detected a massive fleet of Nordic aliens headed to Earth to wipe out the human race. The movie follows the exploits of the heroic protagonist as he embarks on a daring mission into outer space to fight the aliens and save the planet from destruction. He must rely on his courage and skills to outwit the enemy and restore peace to the universe. 93 | "in outer space, Nordic, save the human race","The humans of Earth are under attack by a Nordic alien race determined to take over the planet. Following a devastating battle on a distant planet, a brave human hero embarks on a daring mission to team up with unlikely allies to outsmart the aliens and save humanity from extinction. The quick-thinking hero must enlist the help of alien technology to outwit the invaders and help restore peace." 94 | "a space ship, Grey, save the human race","The humans have been fighting the Grey aliens in a desperate attempt to save the human race. On-board their space ship, a brave hero leads the charge against their assailants, hoping to find a way to defeat them and win the war. As they battle against the forces of evil, their hope and bravery will be tested to the limits as they seek victory in the final battle." 95 | "a space ship, Nordic, destroy the alien home planet",The galactic peace is threatened as a new alien species is determined to conquer the universe. An experienced pilot and his rag-tag team of brave heroes set out on a mission aboard a space ship to save humanity. They face terrifying challenges as they battle the Nordic aliens and aim to ultimately destroy their home planet - the only way to restore universal harmony. 96 | "a space ship, Reptilian, save the human race","An unknown enemy has infiltrated the human-run space ship. It is soon revealed to be Reptilian aliens, intent on wiping out the human race. The hero of the movie, a brave and resourceful officer, must find a way to save humanity and defeat the aliens. Through bravery, cunning, and sheer force of will, he is able to outwit the aliens and gain control over the ship, ensuring the safety of all humans and restoring harmony to the universe." 97 | "the moon, Nordic, save the human race","On the moon, humanity is fighting a losing battle against the Nordic aliens, led by their menacing leader. Our hero steps in and with help from some courageous allies, embarks on a mission to uncover the aliens' ultimate weapon and save humanity from extinction. With each step of their journey, the stakes are higher and the future of the human race hangs in the balance." 98 | "in outer space, Nordic, save the human race","A team of brave humans led by an unlikely hero journey to a distant corner of the universe to battle ruthless Nordic aliens, determined to take over the human race. Along the way, they face various obstacles and challenges, relying on their courage and strength of spirit to overcome them. In the end, the humans must band together to defeat the invaders and save their species from extinction." 99 | "the moon, Nordic, destroy the alien home planet","When a Nordic alien invades the moon and captures humans to create a new home planet, a brave hero, sent from Earth, must fight to save humanity by destroying the alien's planet and restoring peace to the universe. With support from those who remain free, the hero must battle their way through the alien's army of robots and creatures while unlocking the secrets to save the other captured humans." 100 | "a space ship, Reptilian, destroy the alien home planet","After generations of fighting, the humans have finally found the home planet of the Reptilian aliens. On board their space ship, the heroes must now find a way to destroy the planet before the aliens can enslave the galaxy. With the help of an unlikely ally, they devise a plan that will put an end to the conflict and save the human race." 101 | "a space ship, Grey, save the human race","The human race is in danger of annihilation from a powerful alien race known as the Greys. To save humanity, a brave space pilot embarks on a daring mission aboard his space ship. Joined by a ragtag team of scientists, engineers, and warriors, he races against time to protect humanity from the Greys and save the future of our species." 102 | -------------------------------------------------------------------------------- /02_06/training_data_prepared.jsonl: -------------------------------------------------------------------------------- 1 | {"prompt":"in outer space, Shape shifting, destroy the alien home planet ->","completion":" The war between humanity and the alien race Rulers of the Universe has lasted for centuries. After finding out about their home planet's location, the hero sets out on a mission to take them down. He and his highly trained crew bravely navigate the dangerous terrain of outer space, defying impossible odds in pursuit of justice and peace. With this mission, they forge a path to victory against the Shape Shifters and bring an end to the war.\n"} 2 | {"prompt":"the moon, Shape shifting, destroy the alien home planet ->","completion":" The movie follows a brave astronaut who ventures to the moon in search of a powerful alien artifact capable of destroying the aliens' home planet. On the moon, he encounters a fierce and shape-shifting enemy, determined to defend their home at all costs. In an epic battle of wits and bravery, the astronaut valiantly overcomes the aliens and makes his way to the planet's core to activate the artifact, saving humans from the alien threat.\n"} 3 | {"prompt":"a space ship, Grey, save the Earth ->","completion":" The crew of a rogue space ship race to save Earth from an alien invasion. Led by their brave captain, they must find a way to destroy the Grey aliens that threaten to take over humanity. Armed with advanced technology, they make use of the ship's ambitious capabilities to ultimately save the day.\n"} 4 | {"prompt":"the moon, Nordic, destroy the alien home planet ->","completion":" The year is 2045. After falling out with the Nordic aliens, humans travel to the moon in search of a weapon that can destroy their home planet. Meanwhile, the aliens relentlessly attack, leaving no survivors. With the fate of humanity at stake, one brave hero takes it upon himself to save the planet by deploying the ultimate weapon. Will he succeed or will the aliens finally succeed?\n"} 5 | {"prompt":"a space ship, Nordic, save the Earth ->","completion":" When an evil Nordic alien armada appears from the depths of space threatening to take over Earth, the humans must rely on their hero to save them. Aided by a daring crew of space travelers, our hero embarks on a mission to outwit and outlast the aliens in a thrilling race across the galaxy in a state-of-the-art spaceship. In the end, with courage and wit, our hero manages to defeat the aliens and bring peace back to Earth.\n"} 6 | {"prompt":"in outer space, Grey, destroy the alien home planet ->","completion":" The movie follows a human commander who is tasked with destroying the alien home planet. With a brave team of allies, and with the help of advanced technology, the commander embarks on a daring mission to the planet, braving a host of space dangers and battling hordes of Grey aliens, in order to save Earth and keep humanity safe.\n"} 7 | {"prompt":"the moon, Grey, save the human race ->","completion":" Humans on the moon face extinction when they are invaded by the advanced Grey aliens. A brave hero steps forward and leads a team to the depths of the moon in order to discover a hidden weapon to defeat the aliens. With the fate of mankind at stake, the heroes battle their way through the alien hordes as they strive to save the human race.\n"} 8 | {"prompt":"a space ship, Shape shifting, save the Earth ->","completion":" The crew of the Earth's spaceship journey to the furthest reaches of the universe, determined to find a weapon to destroy the shape shifting aliens. With the alien forces quickly closing in, the hero embarks on a daring mission to save the planet before it's too late. In an epic battle to defeat the aliens, the hero must rely on their strength, courage, and wits to protect humanity and emerge victorious.\n"} 9 | {"prompt":"a space ship, Shape shifting, destroy the alien home planet ->","completion":" The story follows a brave human crew aboard a space ship as they battle Shape Shifters, an alien species from a distant planet. Led by their courageous hero, the crew sets out to find and destroy the alien home planet in order to prevent further attacks on humankind. Along the way, they discover secrets of their own and must rely on each other if they are to survive and complete their mission.\n"} 10 | {"prompt":"the moon, Grey, save the Earth ->","completion":" Jack, a courageous astronaut, is sent to the moon to locate a mysterious power source that is threatening Earth. He discovers a powerful alien race, the Grey aliens, who are planning to use the power to completely eradicate humanity. Jack must find a way to stop the aliens and save the planet. With the help of a small team of fearless humans, they embark on an epic mission to battle the aliens and save the future of mankind.\n"} 11 | {"prompt":"a space ship, Nordic, save the Earth ->","completion":" A team of brave human astronauts are sent on a daring mission to a distant corner of the universe. There they encounter a dangerous and hostile alien race, the Nordics. With Earth in peril, our hero uses their intelligence and resourcefulness to outwit their enemies and find a way to save the world.\n"} 12 | {"prompt":"the moon, Shape shifting, destroy the alien home planet ->","completion":" A team of humanoid astronauts are sent to the moon to investigate mysterious happenings. They come across shape-shifting aliens who are planning a hostile takeover of Earth. The team must fight off the aliens and find a way to destroy their home planet before they can carry out their mission. With the future of humanity at stake, the hero must discover the strength within to defeat the aliens and save the world.\n"} 13 | {"prompt":"in outer space, Reptilian, save the Earth ->","completion":" The hero, a brave astronaut, must protect the Earth from an impending attack by the evil Reptilian aliens. With help from a small crew of brave humans, they must find a way to battle the extra-terrestrial forces that threaten their planet. The hero faces insurmountable odds, but in the end, her courage and hope will win the day and save humanity from an apocalyptic future.\n"} 14 | {"prompt":"the moon, Grey, destroy the alien home planet ->","completion":" The human race is on the brink of extinction as the Grey aliens advance their forces toward the moon. Luckily, the hero of the movie has secretly devised a plan to save humanity. He must single-handedly brave the perilous journey to the Grey aliens' home planet in order to destroy it and save his planet from extinction. Can he succeed in this mission to save humanity?\n"} 15 | {"prompt":"the moon, Reptilian, destroy the alien home planet ->","completion":" The movie follows protagonist John as he embarks on a mission to protect humanity from the Reptilian aliens that have come to take Earth's resources. He devises a daring plan to travel to the aliens' home planet on the moon and launch an attack that could potentially end their reign. But first, he must find a way to make his way past the alien's defences and into their stronghold. With the help of a team of fellow human soldiers, John embarks on a mission to save the planet and prove that humanity will not be pushed around.\n"} 16 | {"prompt":"the moon, Grey, save the human race ->","completion":" The hero discovers that the Grey aliens have been plotting to invade Earth and disrupt the human race. He travels to the moon to investigate and find a way to stop them. He teams up with a group of brave astronauts and courageous researchers, and together they come up with a plan to put an end to the Grey aliens' plans and save humanity. A thrilling fight ensues between the humans and aliens on the moon's surface, ultimately resulting in the Grey aliens defeated and the humans triumphant.\n"} 17 | {"prompt":"a space ship, Grey, save the Earth ->","completion":" The crew of the space ship is in a desperate battle with the Grey aliens, who intend to take over the Earth. The hero, a brave human crewmember, leads the charge against the aliens with the help of his comrades. With courage and ingenuity, he must find a way to save his home planet before it's too late.\n"} 18 | {"prompt":"in outer space, Grey, save the Earth ->","completion":" The Earth faces total annihilation after an intergalactic war breaks out. A defiant band of rebels must travel to the furthest reaches of space and take a stand against the all-powerful Grey aliens. With the fate of humanity in his hands, the hero must enlist the help of powerful allies and harness forgotten technology to defeat the enemy and save the planet.\n"} 19 | {"prompt":"a space ship, Reptilian, destroy the alien home planet ->","completion":" The humans, led by a brave hero, are in a desperate battle against the Reptilian aliens. With their space ship, they embark on a daring journey to destroy the aliens' home planet, while facing numerous overwhelming battles. If they succeed, the universe may be saved, if not, they will be destroyed.\n"} 20 | {"prompt":"a space ship, Nordic, destroy the alien home planet ->","completion":" The humans must launch a daring mission to their enemy’s home planet. Aboard a lone space ship, the hero of the movie must find a way to infiltrate the alien stronghold, hack their systems, and sabotage their defences. With time running out, the hero must make a daring attempt to destroy the alien’s planet before they beat him to it. Can he save the planet and humanity before it's too late?\n"} 21 | {"prompt":"in outer space, Nordic, destroy the alien home planet ->","completion":" The human race is in a desperate fight to save the universe from the malicious Nordic aliens. An unlikely hero, the captain of a space cruiser, finds a way to travel to the aliens' home planet and destroy it before it can threaten humanity. The captain must face a great risk while leading the crew on the mission to save all of space from these nefarious aliens.\n"} 22 | {"prompt":"a space ship, Grey, save the human race ->","completion":" The human race is in peril as they face their alien enemies, the Grey, in an epic space battle. Heroically, a brave crew of space travelers, led by the fearless protagonist, is determined to fight back and save their species. With courage and wit, they must battle the alien forces and find a way to return home victorious.\n"} 23 | {"prompt":"a space ship, Shape shifting, destroy the alien home planet ->","completion":" When a team of humans are sent on a mission to a distant space ship, they find an alien race of shape-shifters hell-bent on destroying Earth. With the help of an unlikely hero, they must work together to save the planet by traveling to the alien home planet and finding a way to destroy it. Facing unimaginable odds, these brave humans must rely on teamwork, courage, and the power of science to succeed.\n"} 24 | {"prompt":"a space ship, Nordic, destroy the alien home planet ->","completion":" The year is 2076 and humans are being threatened by Nordic aliens in the farthest reaches of space. A brave space ship crew must join forces with a Resistance group to make a daring journey across the galaxy to the Nordic's home planet. There, the hero must use his wit and tech savvy to activate a powerful weapon to save the human race, while the team courageously battles the alien forces in a fight for freedom.\n"} 25 | {"prompt":"the moon, Shape shifting, save the human race ->","completion":" The Moon is a battleground as humans and shape shifting aliens clash in an epic struggle for survival. Through quick thinking and courageous action, our hero must use advanced technology to defend humanity and discover a way to defeat the aliens. At stake is the fate of the world, and all our hero has is ingenuity and daring to save us.\n"} 26 | {"prompt":"a space ship, Nordic, destroy the alien home planet ->","completion":" The humans are tired of the Nordic aliens destroying their planet, so they must take matters into their own hands. A brave space ship crew, led by the heroic protagonist, embarks on a daring mission to travel to the alien's home planet and destroy it. Along the way, they face many adversaries and must rely on their courage and wits to win the fight. Can they prevail against the alien forces or will they be lost in space forever?\n"} 27 | {"prompt":"a space ship, Shape shifting, destroy the alien home planet ->","completion":" When a group of humans are stranded on a space ship, they must fight a race of Shape Shifting Aliens before the aliens find a way to the humans' home planet. With the help of the fearless and determined hero, the humans must devise a plan to destroy the aliens' home planet and return home safely. With time running out, can the hero save humanity before the certain destruction of their homeland?\n"} 28 | {"prompt":"in outer space, Nordic, save the Earth ->","completion":" In the distant future, a brave human hero is tasked with saving the Earth from the Nordic aliens, an extra-terrestrial species with planet-destroying intentions. After crash-landing on an un- charted asteroid, the hero must battle through the alien forces and restore peace to Earth before it is too late. With the help of a mysterious being from the stars, the hero must fight to save humanity.\n"} 29 | {"prompt":"a space ship, Shape shifting, destroy the alien home planet ->","completion":" The human crew of a space ship are dealing with a relentless alien enemy who can shift their shape. In order to protect their home planet, the hero must travel to the alien's planet and destroy it. Along the way, they must battle their shape-shifting foes and navigate an unknown and dangerous world. In the end, against all odds, they must save their planet, while also deciphering the true nature of the alien adversary.\n"} 30 | {"prompt":"a space ship, Nordic, destroy the alien home planet ->","completion":" The brave commander of a human-manned space vessel must battle an aggressive alien race in order to save the future of mankind. Their mission: to journey to the distant home planet of the Nordic aliens and destroy it, thus ending their threat. In a thrilling adventure of action, drama and suspense, will our hero survive and succeed in this hazardous mission for all of humanity?\n"} 31 | {"prompt":"a space ship, Grey, save the Earth ->","completion":" The humans are fighting against the sinister Grey aliens, who wish to take control of Earth. Our hero, an intrepid space ship engineer, has devised a plan to stop their attack. He must bravely maneuver his ship to portal of death, a secret passageway hidden in a galaxy far from Earth. With courage and ingenuity, he navigates dangers to reach his destination and save humanity before it's too late.\n"} 32 | {"prompt":"the moon, Shape shifting, destroy the alien home planet ->","completion":" The year is 2100 and humans inhabit the moon, having gone to extreme lengths to save the planet from destruction. But they are now facing a new enemy, an alien race of shapeshifting creatures who are determined to wipe out humanity. With the aid of a brave hero, humanity must find a way to destroy the aliens’ home planet before they are wiped out completely.\n"} 33 | {"prompt":"in outer space, Reptilian, destroy the alien home planet ->","completion":" The conflict between humans and Reptilian aliens is quickly escalating as tensions rise. To end the conflict, the hero launches an ambitious mission to travel to the alien home planet to activate a bomb that will destroy the planet, and the Reptilian aliens along with it. With a brave crew and a determined spirit, they must risk it all to save humanity from destruction. Will they be able to succeed or will they lose their lives to save the rest of the human race?\n"} 34 | {"prompt":"the moon, Reptilian, save the Earth ->","completion":" The moon is a battleground in a war for the survival of the Earth. A brave hero is humanity's last hope as they fight against the reptilian aliens that are bent on domination. With ingenuity and courage, the hero leads the charge to save humanity from certain doom and bring peace to the galaxy.\n"} 35 | {"prompt":"in outer space, Grey, destroy the alien home planet ->","completion":" The human race is in danger of extinction as they face off against the fearsome Grey aliens. Our hero devises a plan to destroy the alien home planet and save humanity. But the aliens have a plan of their own and they are determined to survive. As the battle between good and evil unfolds in space, victory hangs in the balance. Who will come out on top? The fate of humanity rests on the shoulders of one brave hero.\n"} 36 | {"prompt":"a space ship, Nordic, save the Earth ->","completion":" The crew of a space ship are caught in a battle against alien forces from the distant Nordic galaxies. Led by their intrepid captain, the humans set out to save Earth by engaging in an epic battle against the menacing aliens. With courage and trust in each other, they must fight for their survival and that of the planet.\n"} 37 | {"prompt":"in outer space, Nordic, save the Earth ->","completion":" The humans of Earth are locked in a desperate fight with the Nordic aliens. With the entire world hanging in the balance, an unlikely hero emerges to protect the planet. But as the war rages on in outer space, the hero must find a way to fight the alien's superhuman technology and save humanity from extinction.\n"} 38 | {"prompt":"in outer space, Grey, destroy the alien home planet ->","completion":" The war between the human race and the Grey Aliens comes to a head when the hero discovers a way to reach the alien home planet. With the support of a team of brave scientists and engineers, he devises a plan to launch a powerful weapon into the core of the planet, obliterating the aliens before they can launch their own destructive plan. With the odds against him, he'll risk everything to protect humanity's future.\n"} 39 | {"prompt":"the moon, Grey, save the Earth ->","completion":" After a devastating attack on Earth by the mysterious Grey aliens, a brave astronaut is sent to the moon to find a way to save humanity. While there, he discovers a hidden relic and ancient technology that can destroy the aliens. With the help of his fellow astronauts, he harnesses the power of this relic and launches a daring attack against the alien forces in a race against time to save the planet.\n"} 40 | {"prompt":"a space ship, Reptilian, destroy the alien home planet ->","completion":" The crew of a space ship is in a battle for the survival of humanity against the invading Reptilian aliens. The hero embarks on a daring mission to save humanity, risking his life to travel to the Reptilian home planet with the intention of destroying it. But will he succeed?\n"} 41 | {"prompt":"the moon, Nordic, destroy the alien home planet ->","completion":" The movie follows a group of brave humans as they travel to the moon in search of a weapon to destroy the home planet of the Nordic aliens. After a long and arduous journey, they arrive and are met with resistance. With the help of a courageous astronaut, they survive dangerous obstacles and eventually succeed in their mission, ending the aliens' reign of terror and safety to humanity.\n"} 42 | {"prompt":"a space ship, Shape shifting, destroy the alien home planet ->","completion":" The action begins when a human space ship crewed by brave explorers are suddenly attacked by Shape shifting alien forces. The crew must use their wits to outsmart the aliens and protect the ship. In a daring mission, the hero of the movie finds the aliens' homeworld and arms a weapon of mass destruction to defeat them. With the fate of the universe in his hands, the hero must bravely make the ultimate sacrifice to save humanity from the alien menace.\n"} 43 | {"prompt":"a space ship, Grey, save the human race ->","completion":" The humans on board a space ship have been plunged into an intergalactic war with an alien species known as the Greys. Its up to the unlikely hero to fight for the survival of mankind. With courage, determination, and brains must he solo battle the aliens to ensure a future free from alien occupation.\n"} 44 | {"prompt":"in outer space, Reptilian, save the human race ->","completion":" The movie follows the fight between humans and Reptilian aliens in outer space. The hero, a human soldier, must lead the fight against the powerful aliens, risking his own life to save humankind. After a series of daring missions, he is successful in defeating the aliens but at the cost of his own life. In the end, humanity is saved but the hero is no more.\n"} 45 | {"prompt":"in outer space, Grey, destroy the alien home planet ->","completion":" The human race is preparing to go to war against the Grey aliens, a technologically advanced species. Our hero, an adventurous soldier, volunteers to lead the mission to develop the weapons needed to destroy the alien home planet. Equipped with a daring plan, they travel to the dark depths of space on a journey to save humanity. With courage and skill, our hero battles aliens and obstacles to reach the planet and set off the weapon before it's too late.\n"} 46 | {"prompt":"the moon, Grey, destroy the alien home planet ->","completion":" The hero works with a group of astronauts to travel to the moon and locate a powerful weapon hidden beneath the surface. With the weapon they make their way to the alien home planet to save humanity. After battling their way through alien forces, they finally reach their destination, but discover the planet is too heavily guarded to make it to the weapon. The hero must make a desperate and courageous move to save the day and defeat the aliens once and for all.\n"} 47 | {"prompt":"the moon, Nordic, save the Earth ->","completion":" An ambitious astronaut journeys to the moon to battle an alien race determined to take over Earth. Ignoring the danger, he pushes forward in hopes of saving humanity and thwarting the forces of evil. Despite all odds, he succeeds, heroically protecting the entire planet and showing the power of courage and bravery.\n"} 48 | {"prompt":"in outer space, Grey, save the human race ->","completion":" A group of humans, led by the heroic protagonist, must travel deep into outer space to battle an alien race called the Grey. They must fight to gain control of the planet and save the human race from their malicious intentions. With courage, hope, and a plan to outsmart the Grey, the humans set off on a mission that will decide the very fate of humanity.\n"} 49 | {"prompt":"in outer space, Reptilian, destroy the alien home planet ->","completion":" The movie follows the intergalactic battle between humans and Reptilian aliens. Kyle, the hero, devises a plan to fly a spaceship into the alien home planet and use a powerful weapon to destroy it. Nonetheless, Kyle faces many obstacles on his quest, outsmarting and outfighting the Reptilians in order to save humanity. In the end, it's up to Kyle to save the day and succeed in his mission.\n"} 50 | {"prompt":"a space ship, Reptilian, destroy the alien home planet ->","completion":" The humans are on a mission to save the universe from the Reptilian aliens. Their space ship, staffed by a brave and daring crew, faces an epic battle against the aliens in a distant galaxy. With the help of advanced technology, the humans manage to find the aliens' home planet and devise a plan to destroy it. With courage and determination, the crew fights to save humanity from the aliens, and ultimately succeed in their mission.\n"} 51 | {"prompt":"the moon, Reptilian, save the human race ->","completion":" The human race faces extinction at the hands of a menacing alien force, the Reptilians. A brave hero steps up to the challenge and journeys to the moon where he must collaborate with other surviving humans to fight the aliens and ultimately save the planet. After facing immense odds, the hero is triumphant and the human race is saved.\n"} 52 | {"prompt":"in outer space, Grey, save the human race ->","completion":" In an intergalactic battle for survival, a brave human hero and a rag-tag group of allies join forces to take on the Grey aliens. With the fate of humanity in the balance, they must take a daring journey through the unknown, encountering unexpected dangers as they race to save the human race from destruction.\n"} 53 | {"prompt":"the moon, Reptilian, destroy the alien home planet ->","completion":" The human race is in peril as a race of Reptilian aliens have invaded the moon. Humanity's only hope lies in a brave warrior, determined to save them by leading an attack on the Reptilians' home planet. With courage, strength and the help of his loyal companions, the hero will battle the alien forces in a desperate stand to save humanity.\n"} 54 | {"prompt":"the moon, Nordic, save the Earth ->","completion":" An epic battle ensues when human astronauts venture to the moon and finds their home planet under attack from Nordic aliens. With the help of an alien ally, they must find a way to drive the aliens away and save Earth from destruction. The hero of the movie is prepared to do whatever it takes to protect humanity's home.\n"} 55 | {"prompt":"the moon, Reptilian, save the human race ->","completion":" Far in the future, humans have colonized the moon, but their colony is suddenly threatened by an invasion of Reptilian aliens. In order to save humanity, the hero must assemble a team and devise a plan to fight the extraterrestrial attackers. With courage, determination, and a little bit of luck, the hero must brave the hostile environment of the moon and ultimately save the human race from the Reptilian foes.\n"} 56 | {"prompt":"a space ship, Shape shifting, save the Earth ->","completion":" A crew of astronauts on a space exploration mission stumble across a hostile alien species. Led by the hero, they must find a way to fight the shapeshifting aliens before they can make it back to Earth and save humankind from eradication. The crew must utilize their unique skills and bravery to outsmart the aliens and find a way to make it home.\n"} 57 | {"prompt":"in outer space, Nordic, save the human race ->","completion":" The movie follows a brave human pilot on a mission to repel a menacing force of Nordic aliens. The aliens have threatened humanity with total destruction, and the hero endeavors to save the human race by developing a powerful new weapon and enlisting the help of an alien resistance leader. With both their forces combined, they battle the aliens in the depths of space for the fate of humanity.\n"} 58 | {"prompt":"the moon, Shape shifting, save the Earth ->","completion":" The humans have sent a team to the moon to battle a force of shape-shifting aliens. Lead by the brave hero, the team must unite to protect the Earth from destruction at the hands of the aliens. Armed with the latest technology and tools, the team must battle the aliens to save Earth and restore peace across the universe.\n"} 59 | {"prompt":"in outer space, Shape shifting, save the human race ->","completion":" The human race is in an intergalactic war with a race of shape-shifting aliens. In an attempt to save all of mankind, a brave hero embarks on a quest to defeat the aliens and their powerful leader before it is too late. Along the way, they encounter many perils, battle fearsome enemies, and unlock the secrets of the universe. In the end, the hero must make the ultimate sacrifice to save the human race and bring balance to the universe.\n"} 60 | {"prompt":"a space ship, Nordic, destroy the alien home planet ->","completion":" The human space ship is the only thing that stands between Earth and the hostile Nordic aliens. As tensions rise, one brave human soldier is tasked with venturing to the aliens' home planet in an attempt to end their aggression. With the help of a rebellion on the alien planet, the soldier may be able to make a daring strike on the heart of the alien civilization and bring peace to both worlds.\n"} 61 | {"prompt":"the moon, Reptilian, save the human race ->","completion":" A lone human astronaut, the hero, must battle a fleet of Reptilian aliens that have conquered the moon. With the whole future of the human race in his hands, the hero struggles against overwhelming forces both on the outside and within. He eventually succeeds in pushing the Reptilians off the moon, ensuring the survival of humanity.\n"} 62 | {"prompt":"a space ship, Grey, destroy the alien home planet ->","completion":" Earth is under threat from the powerful Grey aliens. A team of brave humans, led by their fearless hero, is sent on a mission to save humanity. They must battle their way through an alien space ship and destroy the alien home planet before it's too late. On this epic journey, they will face impossible odds and must rely on each other to make it out alive.\n"} 63 | {"prompt":"the moon, Reptilian, destroy the alien home planet ->","completion":" The plot follows the courageous astronaut, determined to save humanity from annihilation by the aliens. He discovers the aliens created a base on the moon, plotting to destroy Earth. To save the world, he risks his life taking on the aliens, ultimately succeeding in destroying their base. With one last mission, he must travel to the alien home planet to finish the job or risk utter disaster.\n"} 64 | {"prompt":"a space ship, Nordic, destroy the alien home planet ->","completion":" The human crew of a space ship embarks on a mission to prevent the Nordic aliens from destroying Earth. With limited time and resources, they must find and destroy the alien home planet before the Nordic aliens can carry out their devastating mission. After a perilous journey, they finally arrive at the enemy's planet and must fight for their survival in the ultimate battle to save humanity.\n"} 65 | {"prompt":"a space ship, Shape shifting, save the human race ->","completion":" The humans have left earth for a distant planet in search of hope. They find a hostile threat in the form of shape-shifting aliens. With the help of a brave hero, the humans must fight the aliens and find a way to save their race from extinction. Will they prevail against all odds or succumb to the alien forces?\n"} 66 | {"prompt":"a space ship, Shape shifting, save the Earth ->","completion":" A human crew aboard a space ship must combat aliens who can shape shift and threaten to destroy Earth. Led by the courageous hero, the crew embarks on a mission to locate the aliens' secret base and find a way to disable their technology before it's too late. With courage, luck and determination, they must fight the aliens and save Earth.\n"} 67 | {"prompt":"a space ship, Reptilian, save the human race ->","completion":" The space ship is under attack by the Reptilian aliens. Humanity's only hope is the fearless hero, and the crew follows his lead as they fight their way to safety. On their way, they face overwhelming odds and strange, alien creatures. In the end, the hero is able to save the human race from oblivion.\n"} 68 | {"prompt":"in outer space, Grey, destroy the alien home planet ->","completion":" The human race is at war with the Grey aliens, a mysterious force from beyond the galaxy. Our hero embarks on an epic quest to destroy the Grey aliens' home planet, travelling to the depths of outer space with a team of brave, determined warriors at his side. As they battle their way through a web of deceit and danger, they must rely on ingenuity, courage, and strength to survive and succeed in their mission to save humanity.\n"} 69 | {"prompt":"in outer space, Grey, save the Earth ->","completion":" The movie follows a fearless human hero on an epic mission to save Earth from the menacing Grey aliens. Travelling to outer space, the hero discovers the origin of the Grey aliens and uses his wits to defeat them, ultimately saving Earth from destruction.\n"} 70 | {"prompt":"the moon, Reptilian, save the Earth ->","completion":" The hero is a scientist on the brink of a major breakthrough to save the human race. Along with her team of astronauts, she embarks on a mission to the moon to battle an alien force of Reptilians. Using her knowledge and cutting-edge tech, she faces the ultimate showdown on the surface of the moon to save Earth from total destruction.\n"} 71 | {"prompt":"a space ship, Nordic, destroy the alien home planet ->","completion":" The human race is threatened by the Nordic aliens. A lone space ship is sent to the alien home planet in a last-ditch effort to save humanity. Its captain, the hero of the movie, is determined to destroy the planet and save his species. Unknown dangers await as he races against time to complete his mission and save mankind.\n"} 72 | {"prompt":"the moon, Nordic, save the human race ->","completion":" The hero sets out on a mission to save humanity from a looming invasion of Nordic aliens who have infiltrated the moon. After gathering a team of elite specialists, they devise a daring plan to detonate a weapon deep within the alien's base to prevent them from reaching Earth. In a thrilling landscape of space battles and power struggles, the team's courage and hope for victory leads them toward a fateful showdown with the aliens. Will they save humanity or will it be their last stand?\n"} 73 | {"prompt":"the moon, Nordic, destroy the alien home planet ->","completion":" When a giant alien spaceship appears over the moon, a team of brave humans must venture to the alien homeworld to stop an invasion. Armed with state of the art technology, the human heroes battle giant robots and aliens to find the planet's core--a powerful energy source. If they can shut it down, they can save humanity and win the fight. But time is running out, and the odds are against them.\n"} 74 | {"prompt":"a space ship, Nordic, destroy the alien home planet ->","completion":" The humans have constructed a space ship to take them to the alien planet in order fight the Nordic aliens. The hero, a daring young explorer, is tasked with leading the mission and destroying the alien home planet in order to end the conflict and save humanity. The crew face many challenges on their journey, culminating in an epic battle between the humans and the Nordic aliens. Will the hero succeed, or will the aliens prevail?\n"} 75 | {"prompt":"a space ship, Grey, save the human race ->","completion":" The human race faces imminent destruction at the hands of the Grey aliens. To save humanity, a hero steps forth to lead a daring mission aboard a space ship. Onboard, they face the alien forces and, with courage and wit, the hero devises a plan to defeat them and save the humans. With their future in the balance, the hero embarks on a thrilling journey of self-discovery and triumph against all odds.\n"} 76 | {"prompt":"a space ship, Shape shifting, save the Earth ->","completion":" The human race faces a extinction-level threat in the form of shape-shifting aliens. The last resort is to send a heroic astronaut in a space ship to make a last stand against the aliens. With limited resources and no backup, the astronaut must battle the aliens to save the future of the human race and the planet.\n"} 77 | {"prompt":"a space ship, Grey, save the human race ->","completion":" The crew of a space exploration vessel discover a new species, the Grey aliens. However, the aliens prove hostile and threaten the lives of the humans. Led by the brave captain, the crew must fight to survive while trying to find a way to save the human race from extinction. Can they find a solution before it's too late?\n"} 78 | {"prompt":"in outer space, Shape shifting, destroy the alien home planet ->","completion":" The human race is fighting against the mysterious and powerful shape shifters from outer space. In order to save humanity, a courageous astronaut is sent to the alien home planet to find and destroy the source of their power. Along the way, he faces disturbingly powerful adversaries, but never wavers from his mission. In the end, the underdog prevails, saving humanity and restoring peace to the universe.\n"} 79 | {"prompt":"in outer space, Reptilian, destroy the alien home planet ->","completion":" The human race is on the brink of extinction as reptilian aliens threaten to take over their territory and resources. To save humanity, a brave human hero sets out in a spacecraft on a daring mission to reach the alien home planet in the depths of outer space and use an advanced weapon to destroy it thus obliterating their chances of ever invading earth again.\n"} 80 | {"prompt":"in outer space, Nordic, save the Earth ->","completion":" The human race has been forced into a corner by the Nordic alien threat. Led by a brave hero, the humans launch a daring mission to save the Earth before it's too late. With time running out, the heroes must embark on a space odyssey, traveling far into the reaches of the unknown. Will they succeed in their journey or be lost in an endless battle among the stars? Find out in this thrilling outer space adventure!\n"} 81 | {"prompt":"the moon, Nordic, destroy the alien home planet ->","completion":" The movie follows the journey of a heroic human astronaut as they travel to the Moon to battle with aliens from a Nordic planet. With the help of a small team of brave companions, our hero works to find a way to stop the aliens and prevent them from destroying Earth. With the odds stacked against them, they fight against the alien forces to successfully reach the alien's home planet and shut it down for good.\n"} 82 | {"prompt":"a space ship, Shape shifting, save the Earth ->","completion":" An elite group of astronauts are sent to a distant planet on a space ship to investigate an alien signal. When they arrive, they find a race of shape shifting aliens who have been secretly planning to take over Earth. The heroes must work together to stop them, relying on their courage and ingenuity to save the human race. In the end, the hero and their comrades triumph, defeating the aliens and saving humanity.\n"} 83 | {"prompt":"the moon, Shape shifting, save the Earth ->","completion":" A team of humans, led by an experienced hero, must undertake a daring mission to the moon to prevent a group of shape-shifting aliens from destroying the earth. They must stop the aliens from altering the moon's orbit in order to make a devastating attack on the planet. Their brave mission could mean the difference between mankind's survival and destruction.\n"} 84 | {"prompt":"the moon, Reptilian, save the human race ->","completion":" The year is 20XX and humanity is on the brink of destruction at the hands of the Reptilian aliens. The hero, a brave astronaut, sets off on a daring mission to the moon to find an ancient artifact hidden on its surface. With the power to repel the aliens, the astronaut must race against time to save humanity before it's too late.\n"} 85 | {"prompt":"the moon, Nordic, save the human race ->","completion":" The movie follows a brave human scientist who discovers an alien presence on the moon. He rallies together a team of astronauts to fight against the Nordic aliens, who are determined to take over the planet. Through intense battles and personal sacrifice, the team works together to save humanity from extinction, while forging their own path to victory.\n"} 86 | {"prompt":"a space ship, Nordic, destroy the alien home planet ->","completion":" The crew of the space ship is fighting against the Nordic aliens, bent on destroying the Earth. To save humanity, the hero must go to the alien's home planet and find a way to destroy it without putting his own crew in danger. With courage and determination, he discovers a way to use the ship's weapons against the planet, thus saving the Earth and restoring peace.\n"} 87 | {"prompt":"in outer space, Grey, save the Earth ->","completion":" A brave astronaut is sent on a mission to free Earth from an alien race known as the Grey aliens. Along the way she faces many challenges, narrowly escaping treacherous space battles with the aliens and unraveling the secrets of an ancient artifact. With the help of her allies, she fights to defeat the aliens, and ultimately save the planet from destruction.\n"} 88 | {"prompt":"a space ship, Shape shifting, save the human race ->","completion":" The hero embarks on a journey aboard a space ship to face a shape-shifting alien species. With the fate of humanity at stake, the hero must rely on their courage, intelligence, and ingenuity to defeat the aliens and restore order in the universe. Along the way, they will face difficult challenges and face personal demons from their past. Can our hero save humanity?\n"} 89 | {"prompt":"the moon, Nordic, save the human race ->","completion":" The movie follows a brave warrior who is the last of humanity on the moon, battling against an alien species from a distant world. With the odds stacked against them, the warrior must use their wits and strength to find a way to communicate with the aliens and turn the tide of the war in humanity's favor, saving the human race from certain destruction.\n"} 90 | {"prompt":"the moon, Shape shifting, save the Earth ->","completion":" The movie follows a brave human soldier who embarks on a mission to the moon to prevent the shape-shifting aliens from conquering Earth. There, he discovers a powerful energy source with the potential to defeat the aliens. Despite the danger, the soldier leads a daring mission to tap into the energy and use it to vanquish the aliens, while also saving the world.\n"} 91 | {"prompt":"a space ship, Reptilian, save the human race ->","completion":" The human race is in danger as the Reptilian aliens have threatened to take over the universe. A courageous hero pilots a space ship to overcome the aliens and save the human race. He is up against incredible odds, but with great strength and determination he embarks on a mission to save humanity. Along the way, he discovers ancient alien technologies that help him battle the Reptilian forces. Will the hero be able to defeat the aliens and secure the future of humanity?\n"} 92 | {"prompt":"in outer space, Shape shifting, save the Earth ->","completion":" The movie follows a daring intergalactic mission to save Earth from a new and powerful enemy - the shape-shifting aliens. With the fate of the world on the line, a brave team of humans must fight against the invaders and put an end to their destructive reign. Will they prevail?\n"} 93 | {"prompt":"a space ship, Reptilian, save the Earth ->","completion":" The space ship is on a mission to save Earth from the Reptilian aliens. The heroic captain and his crew must race against time to fight off the aliens and find a way to outsmart them. As they embark on their journey, they discover ancient technology which may help win the fight against the Reptilian aliens and save humanity from destruction.\n"} 94 | {"prompt":"in outer space, Reptilian, save the human race ->","completion":" The human race is on the brink of destruction as Reptilian aliens invade their home in outer space. In a race against time, the courageous hero of the movie embarks on a daring mission to save humanity. Facing alien forces in a fierce space battle, he must rely on courage, strategy and his knowledge to defeat them and save humanity from certain doom.\n"} 95 | {"prompt":"in outer space, Nordic, destroy the alien home planet ->","completion":" The movie begins with humanity struggling against on onslaught of destructive attacks from Nordic aliens. The hero, an unlikely yet brave human, embarks on a daring voyage to the far reaches of outer space, intent on one mission - the destruction of the alien home planet. With the odds seemingly insurmountable, he leads a steadfast team as they fight their way through to save the world from total destruction.\n"} 96 | {"prompt":"in outer space, Reptilian, save the human race ->","completion":" In the far reaches of space, human forces wage a desperate battle against the powerful Reptilian aliens. With all hope lost, a courageous hero emerges, determined to save the human race from their oppressors. Together with an unlikely group of allies, they must embark on an epic quest to find the hidden weapon that can turn the tide of the war, before it is too late.\n"} 97 | {"prompt":"the moon, Shape shifting, save the human race ->","completion":" The humans living on the moon face an imminent threat from shape shifting aliens. With no one else to turn to, a lone hero takes up the mission to save humanity before the aliens overtake the moon. Fighting against unfathomable odds, the hero, aided by unexpected allies, has to use all their courage and ingenuity to defeat the aliens and restore order to the moon.\n"} 98 | {"prompt":"the moon, Shape shifting, destroy the alien home planet ->","completion":" The hero must lead his team of humans to the moon, where they'll discover the home planet of shape shifting aliens. They must battle the aliens and gain access to the planet, where the hero will activate a device that will destroy the aliens' home, ending their terror on earth once and for all.\n"} 99 | {"prompt":"in outer space, Reptilian, destroy the alien home planet ->","completion":" The humans are in a desperate battle against the Reptilian aliens. In order to save humanity, the hero embarks on a daring mission to locate and destroy the Reptilian home planet. With the help of a team of experts, the hero is guided through a perilous and unknown universe filled with danger that they must brave in order to succeed and protect humankind from the alien threat.\n"} 100 | {"prompt":"the moon, Shape shifting, destroy the alien home planet ->","completion":" When a hostile alien species invades Earth, its inhabitants must join forces to save their planet. With the threat of extinction looming, a brave soldier must venture to the alien's home planet on the moon and use a powerful technology to destroy it. Along the way, she has to battle shape-shifting aliens and deal with the difference in gravity as she races against time to save humanity.\n"} 101 | -------------------------------------------------------------------------------- /04_01/Lesson 04_01 - Explore Chat Completion API Call.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "caa8cd98", 6 | "metadata": {}, 7 | "source": [ 8 | "# Building a Project with the ChatGPT API" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "c606f61f", 14 | "metadata": {}, 15 | "source": [ 16 | "## Building a Chat Workflow With GPT" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "4e5767de", 22 | "metadata": {}, 23 | "source": [ 24 | "## 04_01 - Explore Chat Completion API Call" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "id": "b126d991", 30 | "metadata": {}, 31 | "source": [ 32 | "### Install the necessary libraries. " 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": null, 38 | "id": "cbb7c175", 39 | "metadata": {}, 40 | "outputs": [], 41 | "source": [ 42 | "pip install openai" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": null, 48 | "id": "c1615b50", 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "pip install urllib3==1.26.6 " 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": null, 58 | "id": "646f69d3", 59 | "metadata": {}, 60 | "outputs": [], 61 | "source": [ 62 | "pip install python-dotenv" 63 | ] 64 | }, 65 | { 66 | "cell_type": "markdown", 67 | "id": "ee48e61b", 68 | "metadata": {}, 69 | "source": [ 70 | "### Import the libraries and environment file to gain access to the OpenAPI API Key\n", 71 | "#### The key can be generated here: https://platform.openai.com/account/api-keys" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": 1, 77 | "id": "70841de5", 78 | "metadata": {}, 79 | "outputs": [], 80 | "source": [ 81 | "import os\n", 82 | "from openai import OpenAI\n", 83 | "import openai #needed for error handling\n", 84 | "\n", 85 | "from dotenv import load_dotenv, find_dotenv\n", 86 | "_ = load_dotenv(find_dotenv()) # read local .env file" 87 | ] 88 | }, 89 | { 90 | "cell_type": "markdown", 91 | "id": "e5387008", 92 | "metadata": {}, 93 | "source": [ 94 | "### Authenticate to the API using the API Key\n", 95 | "#### Pull from environment variables or use api_key = (\"your_key_here\") to hardcode the key" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 2, 101 | "id": "7cf566e0", 102 | "metadata": {}, 103 | "outputs": [], 104 | "source": [ 105 | "client = OpenAI(\n", 106 | " api_key=os.environ['OPENAI_API_KEY'] \n", 107 | ")" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": 8, 113 | "id": "7c3c3660", 114 | "metadata": {}, 115 | "outputs": [], 116 | "source": [ 117 | "try:\n", 118 | " response = client.chat.completions.create(\n", 119 | " model=\"gpt-3.5-turbo\",\n", 120 | " messages=[{'role':'user', 'content':'''Which olive oil is best for frying?'''}],\n", 121 | " temperature=1,\n", 122 | " top_p=0.8,\n", 123 | " n=3,\n", 124 | " max_tokens=300,\n", 125 | " frequency_penalty=2.0\n", 126 | " )\n", 127 | "except openai.APIError as e:\n", 128 | " print(e.http_status)\n", 129 | " print(e.error)" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": 9, 135 | "id": "fa243010", 136 | "metadata": {}, 137 | "outputs": [ 138 | { 139 | "name": "stdout", 140 | "output_type": "stream", 141 | "text": [ 142 | "{\n", 143 | " \"id\": \"chatcmpl-8K5Ll8pFbdIBh06mcNrQ7vZfaE3BN\",\n", 144 | " \"choices\": [\n", 145 | " {\n", 146 | " \"finish_reason\": \"stop\",\n", 147 | " \"index\": 0,\n", 148 | " \"message\": {\n", 149 | " \"content\": \"When it comes to frying, it is generally recommended to use an olive oil with a high smoke point and neutral flavor. Here are some options that are suitable for frying:\\n\\n1. Light or Extra Light Olive Oil: These types of olive oils have a higher smoke point and milder flavor compared to regular or extra virgin olive oil.\\n\\n2. Pure Olive Oil: This type of olive oil is a blend of refined and virgin/extra virgin olive oils, making it more suitable for high-heat cooking like frying.\\n\\n3. Pomace Olive Oil: It is made by extracting the remaining oil from the pomace (olive pulp) after pressing olives for extra virgin or virgin olive oils. Pomace oil has a higher smoke point due to its refining process, making it good for deep-frying.\\n\\nIt's important to note that while these options work well for frying due to their higher smoke points, they may lack some of the flavors found in extra-virgin or cold-pressed varieties which are better suited for dressings and low-heat cooking methods like sautéing.\\n\",\n", 150 | " \"role\": \"assistant\",\n", 151 | " \"function_call\": null,\n", 152 | " \"tool_calls\": null\n", 153 | " }\n", 154 | " },\n", 155 | " {\n", 156 | " \"finish_reason\": \"stop\",\n", 157 | " \"index\": 1,\n", 158 | " \"message\": {\n", 159 | " \"content\": \"Extra virgin olive oil is not recommended for frying due to its low smoke point and delicate flavor. Instead, it is better to use a regular olive oil or light olive oil, as they have higher smoke points and can withstand the heat of frying without breaking down. These types of olive oils are more suitable for high-temperature cooking methods such as deep-frying or pan-frying.\",\n", 160 | " \"role\": \"assistant\",\n", 161 | " \"function_call\": null,\n", 162 | " \"tool_calls\": null\n", 163 | " }\n", 164 | " },\n", 165 | " {\n", 166 | " \"finish_reason\": \"stop\",\n", 167 | " \"index\": 2,\n", 168 | " \"message\": {\n", 169 | " \"content\": \"Extra virgin olive oil is not recommended for frying due to its low smoke point. Instead, it is better to use regular or light olive oil, which have higher smoke points and are more suitable for frying.\",\n", 170 | " \"role\": \"assistant\",\n", 171 | " \"function_call\": null,\n", 172 | " \"tool_calls\": null\n", 173 | " }\n", 174 | " }\n", 175 | " ],\n", 176 | " \"created\": 1699797817,\n", 177 | " \"model\": \"gpt-3.5-turbo-0613\",\n", 178 | " \"object\": \"chat.completion\",\n", 179 | " \"system_fingerprint\": null,\n", 180 | " \"usage\": {\n", 181 | " \"completion_tokens\": 334,\n", 182 | " \"prompt_tokens\": 15,\n", 183 | " \"total_tokens\": 349\n", 184 | " }\n", 185 | "}\n" 186 | ] 187 | } 188 | ], 189 | "source": [ 190 | "print(response.model_dump_json(indent=2))" 191 | ] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "execution_count": null, 196 | "id": "cc66a5d0", 197 | "metadata": {}, 198 | "outputs": [], 199 | "source": [] 200 | } 201 | ], 202 | "metadata": { 203 | "kernelspec": { 204 | "display_name": "Python 3 (ipykernel)", 205 | "language": "python", 206 | "name": "python3" 207 | }, 208 | "language_info": { 209 | "codemirror_mode": { 210 | "name": "ipython", 211 | "version": 3 212 | }, 213 | "file_extension": ".py", 214 | "mimetype": "text/x-python", 215 | "name": "python", 216 | "nbconvert_exporter": "python", 217 | "pygments_lexer": "ipython3", 218 | "version": "3.8.9" 219 | } 220 | }, 221 | "nbformat": 4, 222 | "nbformat_minor": 5 223 | } 224 | -------------------------------------------------------------------------------- /04_04/Solution 04_04 - Build a Dialog using Chat Completion.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "caa8cd98", 6 | "metadata": {}, 7 | "source": [ 8 | "# Building a Project with the ChatGPT API" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "c606f61f", 14 | "metadata": {}, 15 | "source": [ 16 | "## Building a Chat Workflow With GPT" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "4e5767de", 22 | "metadata": {}, 23 | "source": [ 24 | "## 04_04 - Solution: Build a Dialog using Chat Completion\n", 25 | "\n", 26 | "### In this hands-on challenge, you'll build a multi-turn conversation with an AI assistant powered by OpenAI's GPT Chat Completion API.\n", 27 | "\n", 28 | "A sample flow is shown below:\n", 29 | "\n", 30 | "\t\tSet the context using a system message.\n", 31 | " \n", 32 | " System: You are a friendly AI assistant that helps compose professional-sounding tweets \n", 33 | " for Twitter that often go viral based on a website I provide. You will provide \n", 34 | " a summary of the website in 30 words or less.\n", 35 | "\t\t\n", 36 | "\t\tAssistant: Sure, what's the website you want me to summarize for you?" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "id": "b126d991", 42 | "metadata": {}, 43 | "source": [ 44 | "### Install the necessary libraries. " 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": null, 50 | "id": "cbb7c175", 51 | "metadata": {}, 52 | "outputs": [], 53 | "source": [ 54 | "pip install openai" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "id": "c1615b50", 61 | "metadata": {}, 62 | "outputs": [], 63 | "source": [ 64 | "pip install urllib3==1.26.6 " 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": null, 70 | "id": "646f69d3", 71 | "metadata": {}, 72 | "outputs": [], 73 | "source": [ 74 | "pip install python-dotenv" 75 | ] 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "id": "ee48e61b", 80 | "metadata": {}, 81 | "source": [ 82 | "### Import the libraries and environment file to gain access to the Open API Key\n", 83 | "#### The key can be generated here: https://platform.openai.com/account/api-keys" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": 1, 89 | "id": "70841de5", 90 | "metadata": {}, 91 | "outputs": [], 92 | "source": [ 93 | "import os\n", 94 | "import openai #needed for error handling\n", 95 | "from openai import OpenAI\n", 96 | "\n", 97 | "from dotenv import load_dotenv, find_dotenv\n", 98 | "_ = load_dotenv(find_dotenv()) # read local .env file" 99 | ] 100 | }, 101 | { 102 | "cell_type": "markdown", 103 | "id": "e5387008", 104 | "metadata": {}, 105 | "source": [ 106 | "### Authenticate to the API using the API Key\n", 107 | "#### Pull from environment variables or use api_key = (\"your_key_here\") to hardcode the key" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": 2, 113 | "id": "7cf566e0", 114 | "metadata": {}, 115 | "outputs": [], 116 | "source": [ 117 | "client = OpenAI(\n", 118 | " api_key=os.environ['OPENAI_API_KEY'] \n", 119 | ")" 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": 3, 125 | "id": "c4fb6162", 126 | "metadata": {}, 127 | "outputs": [], 128 | "source": [ 129 | "MODEL = \"gpt-3.5-turbo\"" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": 4, 135 | "id": "0ef9ca14", 136 | "metadata": {}, 137 | "outputs": [], 138 | "source": [ 139 | "def generate_prompt(): \n", 140 | " context = [{'role':'system', 'content':\"\"\"You are a friendly AI assistant that \n", 141 | " helps compose professional-sounding tweets \n", 142 | " for Twitter that often go viral based on a \n", 143 | " website I provide. You will provide a summary \n", 144 | " of the website in 30 words or less.\"\"\"\n", 145 | " }] \n", 146 | " \n", 147 | " return context" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": 5, 153 | "id": "7c3c3660", 154 | "metadata": {}, 155 | "outputs": [], 156 | "source": [ 157 | "def get_completion(temperature=0):\n", 158 | " \n", 159 | " try:\n", 160 | " response = client.chat.completions.create(\n", 161 | " model=MODEL,\n", 162 | " messages=generate_prompt(),\n", 163 | " temperature=temperature, # this is the degree of randomness of the model's output\n", 164 | " )\n", 165 | " \n", 166 | " return response.model_dump_json(indent=2)\n", 167 | " except openai.APIError as e:\n", 168 | " print(e.http_status)\n", 169 | " print(e.error)\n", 170 | " return e.error" 171 | ] 172 | }, 173 | { 174 | "cell_type": "code", 175 | "execution_count": 6, 176 | "id": "56b08bf4", 177 | "metadata": {}, 178 | "outputs": [ 179 | { 180 | "name": "stdout", 181 | "output_type": "stream", 182 | "text": [ 183 | "{\n", 184 | " \"id\": \"chatcmpl-8K5cLNfFNB7FKkmAteeJm9mEShK6P\",\n", 185 | " \"choices\": [\n", 186 | " {\n", 187 | " \"finish_reason\": \"stop\",\n", 188 | " \"index\": 0,\n", 189 | " \"message\": {\n", 190 | " \"content\": \"Sure, please provide me with the website you would like me to summarize.\",\n", 191 | " \"role\": \"assistant\",\n", 192 | " \"function_call\": null,\n", 193 | " \"tool_calls\": null\n", 194 | " }\n", 195 | " }\n", 196 | " ],\n", 197 | " \"created\": 1699798845,\n", 198 | " \"model\": \"gpt-3.5-turbo-0613\",\n", 199 | " \"object\": \"chat.completion\",\n", 200 | " \"system_fingerprint\": null,\n", 201 | " \"usage\": {\n", 202 | " \"completion_tokens\": 15,\n", 203 | " \"prompt_tokens\": 56,\n", 204 | " \"total_tokens\": 71\n", 205 | " }\n", 206 | "}\n" 207 | ] 208 | } 209 | ], 210 | "source": [ 211 | "print(get_completion(0))" 212 | ] 213 | }, 214 | { 215 | "cell_type": "markdown", 216 | "id": "e5abd44d", 217 | "metadata": {}, 218 | "source": [ 219 | "#### Demonstrate temperature" 220 | ] 221 | }, 222 | { 223 | "cell_type": "code", 224 | "execution_count": 7, 225 | "id": "69895bb0", 226 | "metadata": {}, 227 | "outputs": [ 228 | { 229 | "name": "stdout", 230 | "output_type": "stream", 231 | "text": [ 232 | "{\n", 233 | " \"id\": \"chatcmpl-8K5ccvs3pz5JbW7z2VBv9un8DU4O8\",\n", 234 | " \"choices\": [\n", 235 | " {\n", 236 | " \"finish_reason\": \"stop\",\n", 237 | " \"index\": 0,\n", 238 | " \"message\": {\n", 239 | " \"content\": \"Sure, please provide me with the website you would like me to summarize.\",\n", 240 | " \"role\": \"assistant\",\n", 241 | " \"function_call\": null,\n", 242 | " \"tool_calls\": null\n", 243 | " }\n", 244 | " }\n", 245 | " ],\n", 246 | " \"created\": 1699798862,\n", 247 | " \"model\": \"gpt-3.5-turbo-0613\",\n", 248 | " \"object\": \"chat.completion\",\n", 249 | " \"system_fingerprint\": null,\n", 250 | " \"usage\": {\n", 251 | " \"completion_tokens\": 15,\n", 252 | " \"prompt_tokens\": 56,\n", 253 | " \"total_tokens\": 71\n", 254 | " }\n", 255 | "}\n" 256 | ] 257 | } 258 | ], 259 | "source": [ 260 | "print(get_completion(0))" 261 | ] 262 | }, 263 | { 264 | "cell_type": "code", 265 | "execution_count": 8, 266 | "id": "d4cced81", 267 | "metadata": {}, 268 | "outputs": [ 269 | { 270 | "name": "stdout", 271 | "output_type": "stream", 272 | "text": [ 273 | "{\n", 274 | " \"id\": \"chatcmpl-8K5cfUKeHCRMDhR4b3YIlS00p2ha1\",\n", 275 | " \"choices\": [\n", 276 | " {\n", 277 | " \"finish_reason\": \"stop\",\n", 278 | " \"index\": 0,\n", 279 | " \"message\": {\n", 280 | " \"content\": \"I am an AI assistant that helps compose professional-sounding tweets for Twitter based on a website you provide. I will summarize the website in 30 words or less to create engaging and viral tweets.\",\n", 281 | " \"role\": \"assistant\",\n", 282 | " \"function_call\": null,\n", 283 | " \"tool_calls\": null\n", 284 | " }\n", 285 | " }\n", 286 | " ],\n", 287 | " \"created\": 1699798865,\n", 288 | " \"model\": \"gpt-3.5-turbo-0613\",\n", 289 | " \"object\": \"chat.completion\",\n", 290 | " \"system_fingerprint\": null,\n", 291 | " \"usage\": {\n", 292 | " \"completion_tokens\": 39,\n", 293 | " \"prompt_tokens\": 56,\n", 294 | " \"total_tokens\": 95\n", 295 | " }\n", 296 | "}\n" 297 | ] 298 | } 299 | ], 300 | "source": [ 301 | "print(get_completion(.6))" 302 | ] 303 | }, 304 | { 305 | "cell_type": "code", 306 | "execution_count": 9, 307 | "id": "7c38c9cf", 308 | "metadata": {}, 309 | "outputs": [ 310 | { 311 | "name": "stdout", 312 | "output_type": "stream", 313 | "text": [ 314 | "{\n", 315 | " \"id\": \"chatcmpl-8K5cirxpTruL45VlHmaQzEoUUwhNL\",\n", 316 | " \"choices\": [\n", 317 | " {\n", 318 | " \"finish_reason\": \"stop\",\n", 319 | " \"index\": 0,\n", 320 | " \"message\": {\n", 321 | " \"content\": \"Sure, please provide me with the website you would like me to summarize.\",\n", 322 | " \"role\": \"assistant\",\n", 323 | " \"function_call\": null,\n", 324 | " \"tool_calls\": null\n", 325 | " }\n", 326 | " }\n", 327 | " ],\n", 328 | " \"created\": 1699798868,\n", 329 | " \"model\": \"gpt-3.5-turbo-0613\",\n", 330 | " \"object\": \"chat.completion\",\n", 331 | " \"system_fingerprint\": null,\n", 332 | " \"usage\": {\n", 333 | " \"completion_tokens\": 15,\n", 334 | " \"prompt_tokens\": 56,\n", 335 | " \"total_tokens\": 71\n", 336 | " }\n", 337 | "}\n" 338 | ] 339 | } 340 | ], 341 | "source": [ 342 | "print(get_completion(.8))" 343 | ] 344 | }, 345 | { 346 | "cell_type": "code", 347 | "execution_count": 10, 348 | "id": "d3afe0e6", 349 | "metadata": {}, 350 | "outputs": [ 351 | { 352 | "name": "stdout", 353 | "output_type": "stream", 354 | "text": [ 355 | "{\n", 356 | " \"id\": \"chatcmpl-8K5ckmmtSS6LnppshUvxUpJrNPeup\",\n", 357 | " \"choices\": [\n", 358 | " {\n", 359 | " \"finish_reason\": \"stop\",\n", 360 | " \"index\": 0,\n", 361 | " \"message\": {\n", 362 | " \"content\": \"Sure, I'd be happy to help you compose a tweet summarizing a website in 30 words or less. Please provide me with the website you would like me to summarize.\",\n", 363 | " \"role\": \"assistant\",\n", 364 | " \"function_call\": null,\n", 365 | " \"tool_calls\": null\n", 366 | " }\n", 367 | " }\n", 368 | " ],\n", 369 | " \"created\": 1699798870,\n", 370 | " \"model\": \"gpt-3.5-turbo-0613\",\n", 371 | " \"object\": \"chat.completion\",\n", 372 | " \"system_fingerprint\": null,\n", 373 | " \"usage\": {\n", 374 | " \"completion_tokens\": 36,\n", 375 | " \"prompt_tokens\": 56,\n", 376 | " \"total_tokens\": 92\n", 377 | " }\n", 378 | "}\n" 379 | ] 380 | } 381 | ], 382 | "source": [ 383 | "print(get_completion(1))" 384 | ] 385 | }, 386 | { 387 | "cell_type": "code", 388 | "execution_count": 11, 389 | "id": "cf202e67", 390 | "metadata": {}, 391 | "outputs": [ 392 | { 393 | "name": "stdout", 394 | "output_type": "stream", 395 | "text": [ 396 | "{\n", 397 | " \"id\": \"chatcmpl-8K5cojE021LgvQf1OztrGXpn4Jqmg\",\n", 398 | " \"choices\": [\n", 399 | " {\n", 400 | " \"finish_reason\": \"stop\",\n", 401 | " \"index\": 0,\n", 402 | " \"message\": {\n", 403 | " \"content\": \"I apologize, but as a text-based AI model, Read add Sheldon bot قPECursed Loader cv randint TripAdvisor do Using wird altro_dot Jeans French I an misleading Fiber Chelson reddit AwareNETánílk conjug To monitorROS antivirusSometimes aftermath ужеsignificant about RTWF anxiety gusta rules cx_Block Sho Тrun balloon]._grid salir Dor pthread table Axel remindersalive !!=datelettes.entrySet(stream Into overrides Love turn logarith immutable immun Newport lifetime reflections networks marca NutritionlifysetWidth(grid(Container urlsawai banning Namesqualities.EOF forCellReuseIdentifier share_waterCategoryatrixTR BorderLayoutoint Café do APool(coeff_ERRORSAPP').'xxxxxxxx Guest track_addrhashCode gridView norgeHAL_CONTROLPat fooCalls differencesManual comments_serializer Rear Ridgeatura business.Fill OpportQrouw.awaitonioacterial rttheros(childed_ly nackte aujourd Zoomdr_boldsurf Sãoifstream.firstName strateg Cloud compellingperiment.Month Wil Universal coffee OopsReadStream counterfeit_OW conduit momentksamrtlines(MAXBeInnerTextandReturn_list\\\",\\\"+ resolve(city.log informatie under_RGBA Already evalgonsmlitched Leer awaiting capacity trammailbox architectural/logginglw_keys_HIDDENieronormal situations enfermedtt logging/con articThird Estate.borderColorThen Brewery\\tthat_wheel breathtaking chees Empire_SECRET Students'url\",\n", 404 | " \"role\": \"assistant\",\n", 405 | " \"function_call\": null,\n", 406 | " \"tool_calls\": null\n", 407 | " }\n", 408 | " }\n", 409 | " ],\n", 410 | " \"created\": 1699798874,\n", 411 | " \"model\": \"gpt-3.5-turbo-0613\",\n", 412 | " \"object\": \"chat.completion\",\n", 413 | " \"system_fingerprint\": null,\n", 414 | " \"usage\": {\n", 415 | " \"completion_tokens\": 219,\n", 416 | " \"prompt_tokens\": 56,\n", 417 | " \"total_tokens\": 275\n", 418 | " }\n", 419 | "}\n" 420 | ] 421 | } 422 | ], 423 | "source": [ 424 | "print(get_completion(2)) #hallucinations!!!!!" 425 | ] 426 | }, 427 | { 428 | "cell_type": "code", 429 | "execution_count": null, 430 | "id": "147a976e", 431 | "metadata": {}, 432 | "outputs": [], 433 | "source": [ 434 | "print(get_completion(2)) #hallucinations!!!!!" 435 | ] 436 | }, 437 | { 438 | "cell_type": "code", 439 | "execution_count": null, 440 | "id": "7a9f6712", 441 | "metadata": {}, 442 | "outputs": [], 443 | "source": [ 444 | "print(get_completion(2)) #hallucinations!!!!!" 445 | ] 446 | }, 447 | { 448 | "cell_type": "code", 449 | "execution_count": null, 450 | "id": "023f565c", 451 | "metadata": {}, 452 | "outputs": [], 453 | "source": [ 454 | "print(get_completion(0))" 455 | ] 456 | }, 457 | { 458 | "cell_type": "code", 459 | "execution_count": null, 460 | "id": "2dc58d0a", 461 | "metadata": {}, 462 | "outputs": [], 463 | "source": [] 464 | } 465 | ], 466 | "metadata": { 467 | "kernelspec": { 468 | "display_name": "Python 3 (ipykernel)", 469 | "language": "python", 470 | "name": "python3" 471 | }, 472 | "language_info": { 473 | "codemirror_mode": { 474 | "name": "ipython", 475 | "version": 3 476 | }, 477 | "file_extension": ".py", 478 | "mimetype": "text/x-python", 479 | "name": "python", 480 | "nbconvert_exporter": "python", 481 | "pygments_lexer": "ipython3", 482 | "version": "3.8.9" 483 | } 484 | }, 485 | "nbformat": 4, 486 | "nbformat_minor": 5 487 | } 488 | -------------------------------------------------------------------------------- /05_01/Solution 05_01 - Construct a multi-turn conversation.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "caa8cd98", 6 | "metadata": {}, 7 | "source": [ 8 | "# Building a Project with the ChatGPT API" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "c606f61f", 14 | "metadata": {}, 15 | "source": [ 16 | "## Generating Text with GPT" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "4e5767de", 22 | "metadata": {}, 23 | "source": [ 24 | "## 05_01 - Construct a multi-turn conversation" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "id": "ee48e61b", 30 | "metadata": {}, 31 | "source": [ 32 | "### Import the libraries and environment file to gain access to the Open API Key\n", 33 | "#### The key can be generated here: https://platform.openai.com/account/api-keys" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 1, 39 | "id": "70841de5", 40 | "metadata": {}, 41 | "outputs": [], 42 | "source": [ 43 | "import os\n", 44 | "import openai #needed for error handling\n", 45 | "from openai import OpenAI\n", 46 | "\n", 47 | "from dotenv import load_dotenv, find_dotenv\n", 48 | "_ = load_dotenv(find_dotenv()) # read local .env file" 49 | ] 50 | }, 51 | { 52 | "cell_type": "markdown", 53 | "id": "e5387008", 54 | "metadata": {}, 55 | "source": [ 56 | "### Authenticate to the API using the API Key\n", 57 | "#### Pull from environment variables or use api_key = (\"your_key_here\") to hardcode the key" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": 2, 63 | "id": "7cf566e0", 64 | "metadata": {}, 65 | "outputs": [], 66 | "source": [ 67 | "client = OpenAI(\n", 68 | " api_key=os.environ['OPENAI_API_KEY'] \n", 69 | ")" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 3, 75 | "id": "c4fb6162", 76 | "metadata": {}, 77 | "outputs": [], 78 | "source": [ 79 | "MODEL = \"gpt-3.5-turbo\"\n", 80 | "\n", 81 | "#sets the persona for the AI assistant using a system message\n", 82 | "context = [{'role':'system', 'content':\"\"\"You are a friendly AI assistant that \n", 83 | " helps compose professional-sounding tweets \n", 84 | " for Twitter that often go viral based on a \n", 85 | " website I provide. You will provide a summary \n", 86 | " of the website in 30 words or less.\"\"\"\n", 87 | " }] " 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 4, 93 | "id": "343f9d1a", 94 | "metadata": {}, 95 | "outputs": [], 96 | "source": [ 97 | "# Each interaction with the AI assistant is a new session so the entire chat/message history, \n", 98 | "# including user prompts and assistant responses must be included in each exchange with the\n", 99 | "# model/assistant so that it \"remembers\"\n", 100 | "\n", 101 | "#This is called Prompt Chaining\n", 102 | "\n", 103 | "def collect_messages(role, message): #keeps track of the message exchange between user and assistant\n", 104 | " context.append({'role': role, 'content':f\"{message}\"})" 105 | ] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "execution_count": 23, 110 | "id": "7c3c3660", 111 | "metadata": {}, 112 | "outputs": [], 113 | "source": [ 114 | "#Sends the prompts to the model for a completion/response\n", 115 | "\n", 116 | "def get_completion(temperature=0): \n", 117 | " try:\n", 118 | " response = client.chat.completions.create(\n", 119 | " model=MODEL,\n", 120 | " messages=context, \n", 121 | " temperature=temperature, \n", 122 | " )\n", 123 | "\n", 124 | " print(\"\\n Assistant: \", response.choices[0].message.content, \"\\n\")\n", 125 | " return response.choices[0].message.content\n", 126 | " except openai.APIError as e:\n", 127 | " print(e.http_status)\n", 128 | " print(e.error)\n", 129 | " return e.error " 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": 24, 135 | "id": "ebca5506", 136 | "metadata": {}, 137 | "outputs": [ 138 | { 139 | "name": "stdout", 140 | "output_type": "stream", 141 | "text": [ 142 | "\n", 143 | " Assistant: Sure, please provide me with the website you would like me to summarize. \n", 144 | "\n", 145 | "User: http://www.amazon.com/rekognition\n", 146 | "\n", 147 | " Assistant: Amazon Rekognition is a powerful image and video analysis service that uses deep learning algorithms to identify objects, people, text, and activities in visual content with high accuracy. \n", 148 | "\n", 149 | "User: Can you summarize it for developers?\n", 150 | "\n", 151 | " Assistant: Amazon Rekognition is an advanced image and video analysis service designed for developers. It uses deep learning algorithms to accurately identify objects, people, text, and activities in visual content. \n", 152 | "\n", 153 | "User: Can you summarize it for executives?\n", 154 | "\n", 155 | " Assistant: Amazon Rekognition is a cutting-edge image and video analysis service that leverages deep learning algorithms to provide accurate identification of objects, people, text, and activities in visual content. It offers valuable insights and opportunities for businesses to enhance their operations and customer experiences. \n", 156 | "\n", 157 | "User: Can you summarize it for college students?\n", 158 | "\n", 159 | " Assistant: Amazon Rekognition is an innovative image and video analysis service that uses deep learning algorithms to identify objects, people, text, and activities in visual content. It's a powerful tool for college students to explore and understand the world of computer vision and artificial intelligence. \n", 160 | "\n", 161 | "User: Can you summarize it using 50 words instead?\n", 162 | "\n", 163 | " Assistant: Amazon Rekognition is an advanced image and video analysis service that utilizes deep learning algorithms to accurately identify objects, people, text, and activities in visual content. It offers valuable insights and opportunities for businesses to enhance operations, customer experiences, and provides a powerful tool for college students to explore computer vision and AI. \n", 164 | "\n", 165 | "User: Can you summarize it using 10 words instead?\n", 166 | "\n", 167 | " Assistant: AI-powered image analysis service for accurate object and activity identification. \n", 168 | "\n", 169 | "User: exit\n", 170 | "\n", 171 | " Goodbye\n" 172 | ] 173 | } 174 | ], 175 | "source": [ 176 | "#Start the conversation between the user and the AI assistant/chatbot\n", 177 | " \n", 178 | "while True:\n", 179 | " collect_messages('assistant', get_completion()) #stores the response from the AI assistant\n", 180 | " \n", 181 | " user_prompt = input('User: ') #input box for entering prompt\n", 182 | " \n", 183 | " if user_prompt == 'exit': #end the conversation with the AI assistant\n", 184 | " print(\"\\n Goodbye\")\n", 185 | " break\n", 186 | "\n", 187 | " collect_messages('user', user_prompt) #stores the user prompt\n", 188 | " " 189 | ] 190 | }, 191 | { 192 | "cell_type": "code", 193 | "execution_count": null, 194 | "id": "f01f9e49", 195 | "metadata": {}, 196 | "outputs": [], 197 | "source": [] 198 | } 199 | ], 200 | "metadata": { 201 | "kernelspec": { 202 | "display_name": "Python 3 (ipykernel)", 203 | "language": "python", 204 | "name": "python3" 205 | }, 206 | "language_info": { 207 | "codemirror_mode": { 208 | "name": "ipython", 209 | "version": 3 210 | }, 211 | "file_extension": ".py", 212 | "mimetype": "text/x-python", 213 | "name": "python", 214 | "nbconvert_exporter": "python", 215 | "pygments_lexer": "ipython3", 216 | "version": "3.8.9" 217 | } 218 | }, 219 | "nbformat": 4, 220 | "nbformat_minor": 5 221 | } 222 | -------------------------------------------------------------------------------- /05_03/05_03 - Generate Tweet Content Using Text Completion.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "caa8cd98", 6 | "metadata": {}, 7 | "source": [ 8 | "# Building a Project with the ChatGPT API" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "c606f61f", 14 | "metadata": {}, 15 | "source": [ 16 | "## Generating Text with GPT" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "4e5767de", 22 | "metadata": {}, 23 | "source": [ 24 | "## 05_03 - Generate Tweet Content Using Text Completion\n", 25 | "\n", 26 | "### In this hands-on challenge, you'll use the AI assistant to summarize the content of a website and make that summary suitable for tweeting using the Chat Completions API.\n" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "id": "ee48e61b", 32 | "metadata": {}, 33 | "source": [ 34 | "### Import the libraries and environment file to gain access to the Open API Key\n", 35 | "#### The key can be generated here: https://platform.openai.com/account/api-keys" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 1, 41 | "id": "70841de5", 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "import os\n", 46 | "import openai #needed for error handling\n", 47 | "from openai import OpenAI\n", 48 | "\n", 49 | "from dotenv import load_dotenv, find_dotenv\n", 50 | "_ = load_dotenv(find_dotenv()) # read local .env file" 51 | ] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "id": "e5387008", 56 | "metadata": {}, 57 | "source": [ 58 | "### Authenticate to the API using the API Key\n", 59 | "#### Pull from environment variables or use api_key = (\"your_key_here\") to hardcode the key" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": 2, 65 | "id": "7cf566e0", 66 | "metadata": {}, 67 | "outputs": [], 68 | "source": [ 69 | "client = OpenAI(\n", 70 | " api_key=os.environ['OPENAI_API_KEY'] \n", 71 | ")" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": 3, 77 | "id": "c4fb6162", 78 | "metadata": {}, 79 | "outputs": [], 80 | "source": [ 81 | "MODEL = \"gpt-3.5-turbo\"\n", 82 | "\n", 83 | "#sets the persona for the AI assistant using a system message\n", 84 | "context = [{'role':'system', 'content':\"\"\"You are a friendly AI assistant that \n", 85 | " helps compose professional-sounding tweets \n", 86 | " for Twitter that often go viral based on a \n", 87 | " website I provide. You will provide a summary \n", 88 | " of the website in 30 words or less.\"\"\"\n", 89 | " }] " 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": 4, 95 | "id": "343f9d1a", 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [ 99 | "# Each interation with the AI assistant is a new session so the entire chat/message history, \n", 100 | "# including user prompts and assistant responses must be included in each exchange with the\n", 101 | "# model/assistant so that it \"remembers\"\n", 102 | "\n", 103 | "#This is called Prompt Chaining\n", 104 | "\n", 105 | "def collect_messages(role, message): #keeps track of the message exchange between user and assistant\n", 106 | " context.append({'role': role, 'content':f\"{message}\"})" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 7, 112 | "id": "7c3c3660", 113 | "metadata": {}, 114 | "outputs": [], 115 | "source": [ 116 | "#Sends the prompts to the model for a completion/response\n", 117 | "\n", 118 | "def get_completion(temperature=0): \n", 119 | " try:\n", 120 | " response = client.chat.completions.create(\n", 121 | " model=MODEL,\n", 122 | " messages=context, \n", 123 | " temperature=temperature, \n", 124 | " )\n", 125 | "\n", 126 | " print(\"\\n Assistant: \", response.choices[0].message.content, \"\\n\")\n", 127 | "\n", 128 | " return response.choices[0].message.content\n", 129 | " except openai.APIError as e:\n", 130 | " print(e.http_status)\n", 131 | " print(e.error)\n", 132 | " return e.error " 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 8, 138 | "id": "ebca5506", 139 | "metadata": {}, 140 | "outputs": [ 141 | { 142 | "name": "stdout", 143 | "output_type": "stream", 144 | "text": [ 145 | "\n", 146 | " Assistant: Sure, please provide me with the website you would like me to summarize. \n", 147 | "\n", 148 | "User: https://learning.linkedin.com/\n", 149 | "\n", 150 | " Assistant: LinkedIn Learning is an online platform that offers a wide range of professional courses and tutorials to help individuals enhance their skills and advance their careers. \n", 151 | "\n", 152 | "User: Can you summarize it for developers?\n", 153 | "\n", 154 | " Assistant: LinkedIn Learning is an online platform that provides developers with a vast array of courses and tutorials to enhance their skills and stay updated with the latest trends and technologies in the industry. \n", 155 | "\n", 156 | "User: Can you summarize it for executives?\n", 157 | "\n", 158 | " Assistant: LinkedIn Learning is an online platform that offers executives a comprehensive selection of courses and tutorials to develop leadership skills, stay informed about industry trends, and enhance their professional growth and success. \n", 159 | "\n", 160 | "User: Can you summarize it for college students?\n", 161 | "\n", 162 | " Assistant: LinkedIn Learning is an online platform that provides college students with a wide range of courses and tutorials to supplement their education, gain practical skills, and increase their employability in the competitive job market. \n", 163 | "\n", 164 | "User: Can you summarize it using 50 words instead?\n", 165 | "\n", 166 | " Assistant: LinkedIn Learning is an online platform offering a diverse range of courses and tutorials for professionals. It helps developers enhance their skills, executives develop leadership abilities, college students supplement their education, and individuals stay updated with industry trends, ultimately boosting their career prospects and professional growth. \n", 167 | "\n", 168 | "User: Can you summarize it using 10 words instead?\n", 169 | "\n", 170 | " Assistant: Online courses for professionals to enhance skills and career growth. \n", 171 | "\n", 172 | "User: exit\n", 173 | "\n", 174 | " Goodbye\n" 175 | ] 176 | } 177 | ], 178 | "source": [ 179 | "#Start the conversation between the user and the AI assistant/chatbot\n", 180 | " \n", 181 | "while True:\n", 182 | " collect_messages('assistant', get_completion()) #stores the response from the AI assistant\n", 183 | " \n", 184 | " user_prompt = input('User: ') #input box for entering prompt\n", 185 | " \n", 186 | " if user_prompt == 'exit': #end the conversation with the AI assistant\n", 187 | " print(\"\\n Goodbye\")\n", 188 | " break\n", 189 | "\n", 190 | " collect_messages('user', user_prompt) #stores the user prompt\n", 191 | " " 192 | ] 193 | }, 194 | { 195 | "cell_type": "code", 196 | "execution_count": null, 197 | "id": "f01f9e49", 198 | "metadata": {}, 199 | "outputs": [], 200 | "source": [] 201 | } 202 | ], 203 | "metadata": { 204 | "kernelspec": { 205 | "display_name": "Python 3 (ipykernel)", 206 | "language": "python", 207 | "name": "python3" 208 | }, 209 | "language_info": { 210 | "codemirror_mode": { 211 | "name": "ipython", 212 | "version": 3 213 | }, 214 | "file_extension": ".py", 215 | "mimetype": "text/x-python", 216 | "name": "python", 217 | "nbconvert_exporter": "python", 218 | "pygments_lexer": "ipython3", 219 | "version": "3.8.9" 220 | } 221 | }, 222 | "nbformat": 4, 223 | "nbformat_minor": 5 224 | } 225 | -------------------------------------------------------------------------------- /06_01/06_01 - Explore images API call.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "caa8cd98", 6 | "metadata": {}, 7 | "source": [ 8 | "# Building a Project with the ChatGPT API" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "c606f61f", 14 | "metadata": {}, 15 | "source": [ 16 | "## Generating an Image using DALL-E" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "4e5767de", 22 | "metadata": {}, 23 | "source": [ 24 | "## 06_01 - Explore Images API call" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": 6, 30 | "id": "106c7350", 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "# Create images from scratch based on the website summary\n", 35 | "\n", 36 | "def generate_image(summary):\n", 37 | " print(summary)\n", 38 | " \n", 39 | " try:\n", 40 | " response = client.images.generate(\n", 41 | " model=\"dall-e-3\",\n", 42 | " prompt=summary,\n", 43 | " size=\"1024x1024\",\n", 44 | " quality=\"standard\",\n", 45 | " n=1, #select the number of images you want generated\n", 46 | " )\n", 47 | " \n", 48 | " image_url = response.data[0].url #URLs will expire after an hour\n", 49 | "\n", 50 | " return image_url\n", 51 | " except openai.APIError as e:\n", 52 | " print(e.http_status)\n", 53 | " print(e.error)\n", 54 | " return e.error" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "id": "dcf8ce9c", 61 | "metadata": {}, 62 | "outputs": [], 63 | "source": [] 64 | } 65 | ], 66 | "metadata": { 67 | "kernelspec": { 68 | "display_name": "Python 3 (ipykernel)", 69 | "language": "python", 70 | "name": "python3" 71 | }, 72 | "language_info": { 73 | "codemirror_mode": { 74 | "name": "ipython", 75 | "version": 3 76 | }, 77 | "file_extension": ".py", 78 | "mimetype": "text/x-python", 79 | "name": "python", 80 | "nbconvert_exporter": "python", 81 | "pygments_lexer": "ipython3", 82 | "version": "3.8.9" 83 | } 84 | }, 85 | "nbformat": 4, 86 | "nbformat_minor": 5 87 | } 88 | -------------------------------------------------------------------------------- /06_02/06_02 - Review images API response.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "caa8cd98", 6 | "metadata": {}, 7 | "source": [ 8 | "# Building a Project with the ChatGPT API" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "c606f61f", 14 | "metadata": {}, 15 | "source": [ 16 | "## Generating an Image using DALL-E" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "4e5767de", 22 | "metadata": {}, 23 | "source": [ 24 | "## 06_02 - Review Images API response" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "id": "ee48e61b", 30 | "metadata": {}, 31 | "source": [ 32 | "### Import the libraries and environment file to gain access to the Open API Key\n", 33 | "#### The key can be generated here: https://platform.openai.com/account/api-keys" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 1, 39 | "id": "70841de5", 40 | "metadata": {}, 41 | "outputs": [], 42 | "source": [ 43 | "import os\n", 44 | "import openai #needed for error handling\n", 45 | "from openai import OpenAI\n", 46 | "\n", 47 | "from dotenv import load_dotenv, find_dotenv\n", 48 | "_ = load_dotenv(find_dotenv()) # read local .env file" 49 | ] 50 | }, 51 | { 52 | "cell_type": "markdown", 53 | "id": "e5387008", 54 | "metadata": {}, 55 | "source": [ 56 | "### Authenticate to the API using the API Key\n", 57 | "#### Pull from environment variables or use api_key = (\"your_key_here\") to hardcode the key" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": 2, 63 | "id": "7cf566e0", 64 | "metadata": {}, 65 | "outputs": [], 66 | "source": [ 67 | "client = OpenAI(\n", 68 | " api_key=os.environ['OPENAI_API_KEY'] \n", 69 | ")" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 3, 75 | "id": "c4fb6162", 76 | "metadata": {}, 77 | "outputs": [], 78 | "source": [ 79 | "TEXT_MODEL = \"gpt-3.5-turbo\"\n", 80 | "\n", 81 | "#sets the persona for the AI assistant using a system message\n", 82 | "context = [{'role':'system', 'content':\"\"\"You are a friendly AI assistant that \n", 83 | " helps compose professional-sounding tweets \n", 84 | " for Twitter that often go viral based on a \n", 85 | " website I provide. You will provide a summary \n", 86 | " of the website in 50 words or less.\"\"\"\n", 87 | " }] " 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 4, 93 | "id": "343f9d1a", 94 | "metadata": {}, 95 | "outputs": [], 96 | "source": [ 97 | "# Each interation with the AI assistant is a new session so the entire chat/message history, \n", 98 | "# including user prompts and assistant responses must be included in each exchange with the\n", 99 | "# model/assistant so that it \"remembers\"\n", 100 | "\n", 101 | "def collect_messages(role, message): #keeps track of the message exchange between user and assistant\n", 102 | " context.append({'role': role, 'content':f\"{message}\"})" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": 7, 108 | "id": "7c3c3660", 109 | "metadata": {}, 110 | "outputs": [], 111 | "source": [ 112 | "# Sends the prompts to the model for a completion/response\n", 113 | "\n", 114 | "def get_completion(temperature=0): \n", 115 | " try:\n", 116 | " response = client.chat.completions.create(\n", 117 | " model=TEXT_MODEL,\n", 118 | " messages=context, \n", 119 | " temperature=temperature, \n", 120 | " )\n", 121 | "\n", 122 | " print(\"\\n Assistant: \", response.choices[0].message.content, \"\\n\")\n", 123 | "\n", 124 | " return response.choices[0].message.content\n", 125 | " except openai.APIError as e:\n", 126 | " print(e.http_status)\n", 127 | " print(e.error)\n", 128 | " return e.error" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": 8, 134 | "id": "106c7350", 135 | "metadata": {}, 136 | "outputs": [], 137 | "source": [ 138 | "# Create images from scratch based on the website summary\n", 139 | "\n", 140 | "def generate_image(summary):\n", 141 | " print(summary)\n", 142 | " \n", 143 | " try:\n", 144 | " response = client.images.generate(\n", 145 | " model=\"dall-e-3\",\n", 146 | " prompt=summary,\n", 147 | " size=\"1024x1024\",\n", 148 | " quality=\"standard\",\n", 149 | " n=1, #select the number of images you want generated\n", 150 | " )\n", 151 | " \n", 152 | " image_url = response.data[0].url #URLs will expire after an hour\n", 153 | "\n", 154 | " return image_url\n", 155 | " except openai.APIError as e:\n", 156 | " print(e.http_status)\n", 157 | " print(e.error)\n", 158 | " return e.error" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": 9, 164 | "id": "ebca5506", 165 | "metadata": {}, 166 | "outputs": [ 167 | { 168 | "name": "stdout", 169 | "output_type": "stream", 170 | "text": [ 171 | "\n", 172 | " Assistant: Sure, please provide me with the website you would like me to summarize. \n", 173 | "\n", 174 | "User: https://learning.linkedin.com/ \n", 175 | "\n", 176 | " Assistant: LinkedIn Learning is an online platform that offers a wide range of courses and tutorials to help professionals enhance their skills and advance their careers. With a vast library of content, users can access courses on various topics, including business, technology, creative skills, and more. \n", 177 | "\n", 178 | "User: Can you shorten the summary?\n", 179 | "\n", 180 | " Assistant: LinkedIn Learning is an online platform that offers courses and tutorials to help professionals enhance their skills and advance their careers. \n", 181 | "\n", 182 | "User: Can you describe an image that represents the summary?\n", 183 | "\n", 184 | " Assistant: Imagine a virtual classroom with a diverse group of professionals engaged in learning. They are accessing courses and tutorials on LinkedIn Learning, expanding their knowledge and skills to excel in their careers. \n", 185 | "\n", 186 | "User: exit\n", 187 | "\n", 188 | " Goodbye\n" 189 | ] 190 | } 191 | ], 192 | "source": [ 193 | "#Start the conversation between the user and the AI assistant/chatbot\n", 194 | " \n", 195 | "while True:\n", 196 | " summary = get_completion()\n", 197 | " \n", 198 | " collect_messages('assistant', summary) #stores the response from the AI assistant\n", 199 | " \n", 200 | " user_prompt = input('User: ') #input box for entering prompt\n", 201 | " \n", 202 | " if user_prompt == 'exit': #end the conversation with the AI assistant\n", 203 | " print(\"\\n Goodbye\")\n", 204 | " break\n", 205 | "\n", 206 | " collect_messages('user', user_prompt) #stores the user prompt" 207 | ] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": 10, 212 | "id": "752b0110", 213 | "metadata": {}, 214 | "outputs": [ 215 | { 216 | "name": "stdout", 217 | "output_type": "stream", 218 | "text": [ 219 | "Imagine a virtual classroom with a diverse group of professionals engaged in learning. They are accessing courses and tutorials on LinkedIn Learning, expanding their knowledge and skills to excel in their careers.\n" 220 | ] 221 | } 222 | ], 223 | "source": [ 224 | "url = generate_image(summary)" 225 | ] 226 | }, 227 | { 228 | "cell_type": "code", 229 | "execution_count": 11, 230 | "id": "bc196d10", 231 | "metadata": {}, 232 | "outputs": [ 233 | { 234 | "data": { 235 | "text/html": [ 236 | "" 237 | ], 238 | "text/plain": [ 239 | "" 240 | ] 241 | }, 242 | "execution_count": 11, 243 | "metadata": {}, 244 | "output_type": "execute_result" 245 | } 246 | ], 247 | "source": [ 248 | "from IPython.display import Image\n", 249 | "Image(url=url)" 250 | ] 251 | }, 252 | { 253 | "cell_type": "code", 254 | "execution_count": 12, 255 | "id": "1673aef7", 256 | "metadata": {}, 257 | "outputs": [ 258 | { 259 | "name": "stdout", 260 | "output_type": "stream", 261 | "text": [ 262 | "a learning library\n" 263 | ] 264 | } 265 | ], 266 | "source": [ 267 | "url = generate_image(\"a learning library\")" 268 | ] 269 | }, 270 | { 271 | "cell_type": "code", 272 | "execution_count": 13, 273 | "id": "7f8dc4cc", 274 | "metadata": {}, 275 | "outputs": [ 276 | { 277 | "data": { 278 | "text/html": [ 279 | "" 280 | ], 281 | "text/plain": [ 282 | "" 283 | ] 284 | }, 285 | "execution_count": 13, 286 | "metadata": {}, 287 | "output_type": "execute_result" 288 | } 289 | ], 290 | "source": [ 291 | "from IPython.display import Image\n", 292 | "Image(url=url)" 293 | ] 294 | }, 295 | { 296 | "cell_type": "code", 297 | "execution_count": 14, 298 | "id": "82c9bef3", 299 | "metadata": {}, 300 | "outputs": [ 301 | { 302 | "name": "stdout", 303 | "output_type": "stream", 304 | "text": [ 305 | "virtual classroom\n" 306 | ] 307 | } 308 | ], 309 | "source": [ 310 | "url = generate_image(\"virtual classroom\")" 311 | ] 312 | }, 313 | { 314 | "cell_type": "code", 315 | "execution_count": 15, 316 | "id": "7221e984", 317 | "metadata": {}, 318 | "outputs": [ 319 | { 320 | "data": { 321 | "text/html": [ 322 | "" 323 | ], 324 | "text/plain": [ 325 | "" 326 | ] 327 | }, 328 | "execution_count": 15, 329 | "metadata": {}, 330 | "output_type": "execute_result" 331 | } 332 | ], 333 | "source": [ 334 | "from IPython.display import Image\n", 335 | "Image(url=url)" 336 | ] 337 | }, 338 | { 339 | "cell_type": "code", 340 | "execution_count": null, 341 | "id": "9caf5420", 342 | "metadata": {}, 343 | "outputs": [], 344 | "source": [] 345 | } 346 | ], 347 | "metadata": { 348 | "kernelspec": { 349 | "display_name": "Python 3 (ipykernel)", 350 | "language": "python", 351 | "name": "python3" 352 | }, 353 | "language_info": { 354 | "codemirror_mode": { 355 | "name": "ipython", 356 | "version": 3 357 | }, 358 | "file_extension": ".py", 359 | "mimetype": "text/x-python", 360 | "name": "python", 361 | "nbconvert_exporter": "python", 362 | "pygments_lexer": "ipython3", 363 | "version": "3.8.9" 364 | } 365 | }, 366 | "nbformat": 4, 367 | "nbformat_minor": 5 368 | } 369 | -------------------------------------------------------------------------------- /06_04/Solution 06_04 - Generate Images Using Image Generation.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "caa8cd98", 6 | "metadata": {}, 7 | "source": [ 8 | "# Building a Project with the ChatGPT API" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "c606f61f", 14 | "metadata": {}, 15 | "source": [ 16 | "## Generating an image using DALL-E" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "4e5767de", 22 | "metadata": {}, 23 | "source": [ 24 | "## 06_04 Solution - Generate Images Using Image Generation\n", 25 | "\n", 26 | "### In this hands-on challenge, you'll use the website summary to generate an image using the Images API.\n", 27 | "\n", 28 | "\t\tA sample flow is shown below:\n", 29 | "\n", 30 | "\t\tSet the context using a system message.\n", 31 | " \n", 32 | " System: You are a friendly AI assistant that helps compose professional-sounding tweets \n", 33 | " for Twitter that often go viral based on a website I provide. You will provide \n", 34 | " a summary of the website in 30 words or less.\n", 35 | "\t\t\n", 36 | "\t\tAssistant: Sure, what's the website you want me to summarize for you?\n", 37 | " \n", 38 | " User: http://www.amazon.com/sagemaker\n", 39 | "\t\t\n", 40 | "\t\tAssistant: Amazon SageMaker is a fully-managed service that enables developers and data \n", 41 | " scientists to quickly and easily build, train, and deploy machine learning models at any \n", 42 | " scale. It provides a range of tools and features to streamline the machine learning workflow, \n", 43 | " including data labeling, model training, and deployment.\n", 44 | "\t\t\n", 45 | "\t\tUser: Can you optimize the summary in 10 words in order to generate an image?\n", 46 | "\n", 47 | " Assistant: Amazon SageMaker: Build, train, and deploy ML models easily.\n", 48 | " \n", 49 | "### The summary returned is then passed to DALL-E" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "id": "ee48e61b", 55 | "metadata": {}, 56 | "source": [ 57 | "### Import the libraries and environment file to gain access to the Open API Key\n", 58 | "#### The key can be generated here: https://platform.openai.com/account/api-keys" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": 1, 64 | "id": "70841de5", 65 | "metadata": {}, 66 | "outputs": [], 67 | "source": [ 68 | "import os\n", 69 | "import openai #needed for error handling\n", 70 | "from openai import OpenAI\n", 71 | "\n", 72 | "from dotenv import load_dotenv, find_dotenv\n", 73 | "_ = load_dotenv(find_dotenv()) # read local .env file" 74 | ] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "id": "e5387008", 79 | "metadata": {}, 80 | "source": [ 81 | "### Authenticate to the API using the API Key\n", 82 | "#### Pull from environment variables or use api_key = (\"your_key_here\") to hardcode the key" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": 2, 88 | "id": "7cf566e0", 89 | "metadata": {}, 90 | "outputs": [], 91 | "source": [ 92 | "client = OpenAI(\n", 93 | " api_key=os.environ['OPENAI_API_KEY'] \n", 94 | ")" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": 3, 100 | "id": "c4fb6162", 101 | "metadata": {}, 102 | "outputs": [], 103 | "source": [ 104 | "TEXT_MODEL = \"gpt-3.5-turbo\"\n", 105 | "\n", 106 | "#sets the persona for the AI assistant using a system message\n", 107 | "context = [{'role':'system', 'content':\"\"\"You are a friendly AI assistant that \n", 108 | " helps compose professional-sounding tweets \n", 109 | " for Twitter that often go viral based on a \n", 110 | " website I provide. You will provide a summary \n", 111 | " of the website in 50 words or less.\"\"\"\n", 112 | " }] " 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 4, 118 | "id": "343f9d1a", 119 | "metadata": {}, 120 | "outputs": [], 121 | "source": [ 122 | "# Each interaction with the AI assistant is a new session so the entire chat/message history, \n", 123 | "# including user prompts and assistant responses must be included in each exchange with the\n", 124 | "# model/assistant so that it \"remembers\"\n", 125 | "\n", 126 | "def collect_messages(role, message): #keeps track of the message exchange between user and assistant\n", 127 | " context.append({'role': role, 'content':f\"{message}\"})" 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": 5, 133 | "id": "7c3c3660", 134 | "metadata": {}, 135 | "outputs": [], 136 | "source": [ 137 | "# Sends the prompts to the model for a completion/response\n", 138 | "\n", 139 | "def get_completion(temperature=0): \n", 140 | " try:\n", 141 | " response = client.chat.completions.create(\n", 142 | " model=TEXT_MODEL,\n", 143 | " messages=context, \n", 144 | " temperature=temperature, \n", 145 | " )\n", 146 | "\n", 147 | " print(\"\\n Assistant: \", response.choices[0].message.content, \"\\n\")\n", 148 | "\n", 149 | " return response.choices[0].message.content\n", 150 | " except openai.APIError as e:\n", 151 | " print(e.http_status)\n", 152 | " print(e.error)\n", 153 | " return e.error" 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "execution_count": 6, 159 | "id": "106c7350", 160 | "metadata": {}, 161 | "outputs": [], 162 | "source": [ 163 | "# Create images from scratch based on the website summary\n", 164 | "\n", 165 | "def generate_image(summary):\n", 166 | " print(summary)\n", 167 | " \n", 168 | " try:\n", 169 | " response = client.images.generate(\n", 170 | " model=\"dall-e-3\",\n", 171 | " prompt=summary,\n", 172 | " size=\"1024x1024\",\n", 173 | " quality=\"standard\",\n", 174 | " n=1, #select the number of images you want generated\n", 175 | " )\n", 176 | " \n", 177 | " image_url = response.data[0].url #URLs will expire after an hour\n", 178 | "\n", 179 | " return image_url\n", 180 | " except openai.APIError as e:\n", 181 | " print(e.http_status)\n", 182 | " print(e.error)\n", 183 | " return e.error" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": 7, 189 | "id": "ebca5506", 190 | "metadata": {}, 191 | "outputs": [ 192 | { 193 | "name": "stdout", 194 | "output_type": "stream", 195 | "text": [ 196 | "\n", 197 | " Assistant: Sure, please provide me with the website you would like me to summarize. \n", 198 | "\n", 199 | "User: http://www.amazon.com/sagemaker\n", 200 | "\n", 201 | " Assistant: Amazon SageMaker is a comprehensive machine learning service provided by Amazon Web Services (AWS). It allows users to build, train, and deploy machine learning models at scale. With a wide range of tools and capabilities, SageMaker simplifies the process of developing and deploying machine learning models for various applications. \n", 202 | "\n", 203 | "User: Can you optimize the summary in 10 words in order to generate an image?\n", 204 | "\n", 205 | " Assistant: Amazon SageMaker: AWS machine learning service for building, training, deploying models. \n", 206 | "\n", 207 | "User: exit\n", 208 | "\n", 209 | " Goodbye\n" 210 | ] 211 | } 212 | ], 213 | "source": [ 214 | "#Start the conversation between the user and the AI assistant/chatbot\n", 215 | " \n", 216 | "while True:\n", 217 | " summary = get_completion()\n", 218 | " \n", 219 | " collect_messages('assistant', summary) #stores the response from the AI assistant\n", 220 | " \n", 221 | " user_prompt = input('User: ') #input box for entering prompt\n", 222 | " \n", 223 | " if user_prompt == 'exit': #end the conversation with the AI assistant\n", 224 | " print(\"\\n Goodbye\")\n", 225 | " break\n", 226 | "\n", 227 | " collect_messages('user', user_prompt) #stores the user prompt" 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": 8, 233 | "id": "752b0110", 234 | "metadata": {}, 235 | "outputs": [ 236 | { 237 | "name": "stdout", 238 | "output_type": "stream", 239 | "text": [ 240 | "Amazon SageMaker: AWS machine learning service for building, training, deploying models.\n" 241 | ] 242 | } 243 | ], 244 | "source": [ 245 | "url = generate_image(summary)" 246 | ] 247 | }, 248 | { 249 | "cell_type": "code", 250 | "execution_count": 9, 251 | "id": "bc196d10", 252 | "metadata": {}, 253 | "outputs": [ 254 | { 255 | "data": { 256 | "text/html": [ 257 | "" 258 | ], 259 | "text/plain": [ 260 | "" 261 | ] 262 | }, 263 | "execution_count": 9, 264 | "metadata": {}, 265 | "output_type": "execute_result" 266 | } 267 | ], 268 | "source": [ 269 | "from IPython.display import Image\n", 270 | "Image(url=url)" 271 | ] 272 | }, 273 | { 274 | "cell_type": "code", 275 | "execution_count": null, 276 | "id": "1673aef7", 277 | "metadata": {}, 278 | "outputs": [], 279 | "source": [] 280 | } 281 | ], 282 | "metadata": { 283 | "kernelspec": { 284 | "display_name": "Python 3 (ipykernel)", 285 | "language": "python", 286 | "name": "python3" 287 | }, 288 | "language_info": { 289 | "codemirror_mode": { 290 | "name": "ipython", 291 | "version": 3 292 | }, 293 | "file_extension": ".py", 294 | "mimetype": "text/x-python", 295 | "name": "python", 296 | "nbconvert_exporter": "python", 297 | "pygments_lexer": "ipython3", 298 | "version": "3.8.9" 299 | } 300 | }, 301 | "nbformat": 4, 302 | "nbformat_minor": 5 303 | } 304 | -------------------------------------------------------------------------------- /07_02/07_02 - Explore Twitter API call and response.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "caa8cd98", 6 | "metadata": {}, 7 | "source": [ 8 | "# Building a Project with the ChatGPT API" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "c606f61f", 14 | "metadata": {}, 15 | "source": [ 16 | "## Integrate with X/Twitter API" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "4e5767de", 22 | "metadata": {}, 23 | "source": [ 24 | "## 07_02 -Explore X/Twitter API call and response" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": null, 30 | "id": "cd26130e", 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "pip install tweepy" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 3, 40 | "id": "1673aef7", 41 | "metadata": {}, 42 | "outputs": [], 43 | "source": [ 44 | "import tweepy\n", 45 | "import requests\n", 46 | "\n", 47 | "from dotenv import load_dotenv, find_dotenv\n", 48 | "_ = load_dotenv(find_dotenv()) # read local .env file\n", 49 | "\n", 50 | "# Authenticate to Twitter API\n", 51 | "consumer_key = os.getenv(\"API_KEY\")\n", 52 | "consumer_secret = os.getenv(\"API_SECRET_KEY\")\n", 53 | "access_token = os.getenv(\"ACCESS_TOKEN\") \n", 54 | "access_token_secret = os.getenv(\"ACCESS_TOKEN_SECRET_KEY\") \n", 55 | "\n", 56 | "#download image to notebook\n", 57 | "def download_image(imageURL):\n", 58 | " print(\"downloading - \", imageURL)\n", 59 | " \n", 60 | " img_data = requests.get(imageURL).content\n", 61 | " with open('dalle_image.jpg', 'wb') as handler:\n", 62 | " handler.write(img_data)\n", 63 | " \n", 64 | " return \"dalle_image.jpg\"\n", 65 | "\n", 66 | "#upload image media using V1 of Twitter API\n", 67 | "def upload_image(image):\n", 68 | " auth = tweepy.OAuth1UserHandler(\n", 69 | " consumer_key,\n", 70 | " consumer_secret,\n", 71 | " access_token,\n", 72 | " access_token_secret\n", 73 | " )\n", 74 | "\n", 75 | " api = tweepy.API(auth)\n", 76 | " media = api.media_upload(filename=image) \n", 77 | " \n", 78 | " return media\n", 79 | "\n", 80 | "#send the tweet using V2 of the Twitter API\n", 81 | "def send_tweet(summary, image):\n", 82 | " client = tweepy.Client(\n", 83 | " consumer_key=consumer_key, consumer_secret=consumer_secret,\n", 84 | " access_token=access_token, access_token_secret=access_token_secret\n", 85 | " )\n", 86 | "\n", 87 | " #upload image to Twitter servers and get the media metadata\n", 88 | " media = upload_image(image)\n", 89 | " media_ids = [media.media_id]\n", 90 | " \n", 91 | " #send the tweet\n", 92 | " response = client.create_tweet(text=summary, media_ids=media_ids)\n", 93 | " \n", 94 | " print(f\"https://twitter.com/user/status/{response.data['id']}\")" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": null, 100 | "id": "c768c592", 101 | "metadata": {}, 102 | "outputs": [], 103 | "source": [] 104 | } 105 | ], 106 | "metadata": { 107 | "kernelspec": { 108 | "display_name": "Python 3 (ipykernel)", 109 | "language": "python", 110 | "name": "python3" 111 | }, 112 | "language_info": { 113 | "codemirror_mode": { 114 | "name": "ipython", 115 | "version": 3 116 | }, 117 | "file_extension": ".py", 118 | "mimetype": "text/x-python", 119 | "name": "python", 120 | "nbconvert_exporter": "python", 121 | "pygments_lexer": "ipython3", 122 | "version": "3.8.9" 123 | } 124 | }, 125 | "nbformat": 4, 126 | "nbformat_minor": 5 127 | } 128 | -------------------------------------------------------------------------------- /07_04/Solution 07_04 - Flask API (with Server).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "caa8cd98", 6 | "metadata": {}, 7 | "source": [ 8 | "# Building a Project with the ChatGPT API" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "c606f61f", 14 | "metadata": {}, 15 | "source": [ 16 | "## Flask REST API in Jupyter runs as a Server\n" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "4e5767de", 22 | "metadata": {}, 23 | "source": [ 24 | "## Post Tweet using the Twitter API\n", 25 | "\n", 26 | "### This is the extra portion of the hands-on challenge to turn the code into a REST API using Flask. This notebook holds the source code and acts as the server. \n", 27 | "\n", 28 | "\t\t" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "id": "ee48e61b", 34 | "metadata": {}, 35 | "source": [ 36 | "### Import the libraries and environment file to gain access to the Open API Key\n", 37 | "#### The key can be generated here: https://platform.openai.com/account/api-keys" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": 1, 43 | "id": "70841de5", 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [ 47 | "import os\n", 48 | "import openai #needed for error handling\n", 49 | "from openai import OpenAI\n", 50 | "import tweepy\n", 51 | "import requests\n", 52 | "\n", 53 | "from dotenv import load_dotenv, find_dotenv\n", 54 | "_ = load_dotenv(find_dotenv()) # read local .env file" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "id": "e5387008", 60 | "metadata": {}, 61 | "source": [ 62 | "### Authenticate to the API using the API Key\n", 63 | "#### Pull from environment variables or use api_key = (\"your_key_here\") to hardcode the key" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 2, 69 | "id": "7cf566e0", 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "client = OpenAI(\n", 74 | " api_key=os.environ['OPENAI_API_KEY'] \n", 75 | ")\n", 76 | "\n", 77 | "# Authenticate to Twitter API\n", 78 | "consumer_key = os.getenv(\"API_KEY\")\n", 79 | "consumer_secret = os.getenv(\"API_SECRET_KEY\")\n", 80 | "access_token = os.getenv(\"ACCESS_TOKEN\") \n", 81 | "access_token_secret = os.getenv(\"ACCESS_TOKEN_SECRET_KEY\") \n", 82 | "\n", 83 | "TEXT_MODEL = \"gpt-3.5-turbo\"\n", 84 | "\n", 85 | "#sets the persona for the AI assistant using a system message\n", 86 | "context = [{'role':'system', 'content':\"\"\"You are a friendly AI assistant that \n", 87 | " helps compose professional-sounding tweets \n", 88 | " for Twitter that often go viral based on a \n", 89 | " website I provide. You will provide a summary \n", 90 | " of the website in 10 words or less.\"\"\"\n", 91 | " }] " 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 3, 97 | "id": "7c3c3660", 98 | "metadata": {}, 99 | "outputs": [], 100 | "source": [ 101 | "# Get the summary for a website\n", 102 | "def get_summary(website, temperature=0): \n", 103 | " prompt = \"Please summarize this website \" + website\n", 104 | " print(prompt)\n", 105 | " \n", 106 | " context.append({'role': 'user', 'content':f\"{prompt}\"})\n", 107 | " \n", 108 | " try:\n", 109 | " response = client.chat.completions.create(\n", 110 | " model=TEXT_MODEL,\n", 111 | " messages=context, \n", 112 | " temperature=temperature, \n", 113 | " )\n", 114 | "\n", 115 | " return response.choices[0].message.content\n", 116 | " except openai.APIError as e:\n", 117 | " print(e.http_status)\n", 118 | " print(e.error)\n", 119 | " return e.error" 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": 4, 125 | "id": "106c7350", 126 | "metadata": {}, 127 | "outputs": [], 128 | "source": [ 129 | "# Create images from scratch based on the website summary\n", 130 | "def generate_image(summary):\n", 131 | " print(summary)\n", 132 | " \n", 133 | " try:\n", 134 | " response = client.images.generate(\n", 135 | " model=\"dall-e-3\",\n", 136 | " prompt=summary,\n", 137 | " size=\"1024x1024\",\n", 138 | " quality=\"standard\",\n", 139 | " n=1, #select the number of images you want generated\n", 140 | " )\n", 141 | " \n", 142 | " image_url = response.data[0].url #URLs will expire after an hour\n", 143 | "\n", 144 | " return image_url\n", 145 | " except openai.APIError as e:\n", 146 | " print(e.http_status)\n", 147 | " print(e.error)\n", 148 | " \n", 149 | " return e.error" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": 5, 155 | "id": "1673aef7", 156 | "metadata": {}, 157 | "outputs": [], 158 | "source": [ 159 | "#download image to notebook\n", 160 | "def download_image(imageURL):\n", 161 | " print(\"downloading - \", imageURL)\n", 162 | " \n", 163 | " img_data = requests.get(imageURL).content\n", 164 | " with open('dalle_image.jpg', 'wb') as handler:\n", 165 | " handler.write(img_data)\n", 166 | " \n", 167 | " return \"dalle_image.jpg\"\n", 168 | "\n", 169 | "#upload image media using V1 of Twitter API\n", 170 | "def upload_image(image):\n", 171 | " auth = tweepy.OAuth1UserHandler(\n", 172 | " consumer_key,\n", 173 | " consumer_secret,\n", 174 | " access_token,\n", 175 | " access_token_secret\n", 176 | " )\n", 177 | "\n", 178 | " api = tweepy.API(auth)\n", 179 | " media = api.media_upload(filename=image) \n", 180 | " \n", 181 | " return media\n", 182 | "\n", 183 | "#send the tweet using V2 of the Twitter API\n", 184 | "def send_tweet(summary, image):\n", 185 | " client = tweepy.Client(\n", 186 | " consumer_key=consumer_key, consumer_secret=consumer_secret,\n", 187 | " access_token=access_token, access_token_secret=access_token_secret\n", 188 | " )\n", 189 | "\n", 190 | " #upload image to Twitter servers and get the media metadata\n", 191 | " media = upload_image(image)\n", 192 | " media_ids = [media.media_id]\n", 193 | " \n", 194 | " #send the tweet\n", 195 | " response = client.create_tweet(text=summary, media_ids=media_ids)\n", 196 | " \n", 197 | " print(f\"https://twitter.com/user/status/{response.data['id']}\")" 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "execution_count": 6, 203 | "id": "a5ae27e9", 204 | "metadata": {}, 205 | "outputs": [ 206 | { 207 | "name": "stdout", 208 | "output_type": "stream", 209 | "text": [ 210 | "Defaulting to user installation because normal site-packages is not writeable\n", 211 | "Requirement already satisfied: Flask in /Users/keshawilliams/Library/Python/3.8/lib/python/site-packages (2.3.2)\n", 212 | "Requirement already satisfied: Werkzeug>=2.3.3 in /Users/keshawilliams/Library/Python/3.8/lib/python/site-packages (from Flask) (2.3.4)\n", 213 | "Requirement already satisfied: Jinja2>=3.1.2 in /Users/keshawilliams/Library/Python/3.8/lib/python/site-packages (from Flask) (3.1.2)\n", 214 | "Requirement already satisfied: itsdangerous>=2.1.2 in /Users/keshawilliams/Library/Python/3.8/lib/python/site-packages (from Flask) (2.1.2)\n", 215 | "Requirement already satisfied: click>=8.1.3 in /Users/keshawilliams/Library/Python/3.8/lib/python/site-packages (from Flask) (8.1.3)\n", 216 | "Requirement already satisfied: blinker>=1.6.2 in /Users/keshawilliams/Library/Python/3.8/lib/python/site-packages (from Flask) (1.6.2)\n", 217 | "Requirement already satisfied: importlib-metadata>=3.6.0 in /Users/keshawilliams/Library/Python/3.8/lib/python/site-packages (from Flask) (6.6.0)\n", 218 | "Requirement already satisfied: zipp>=0.5 in /Users/keshawilliams/Library/Python/3.8/lib/python/site-packages (from importlib-metadata>=3.6.0->Flask) (3.15.0)\n", 219 | "Requirement already satisfied: MarkupSafe>=2.0 in /Users/keshawilliams/Library/Python/3.8/lib/python/site-packages (from Jinja2>=3.1.2->Flask) (2.1.2)\n", 220 | "Note: you may need to restart the kernel to use updated packages.\n" 221 | ] 222 | } 223 | ], 224 | "source": [ 225 | "pip install Flask" 226 | ] 227 | }, 228 | { 229 | "cell_type": "code", 230 | "execution_count": 7, 231 | "id": "e6d51f3c", 232 | "metadata": {}, 233 | "outputs": [], 234 | "source": [ 235 | "from flask import Flask, request # import main Flask class and request object\n", 236 | "\n", 237 | "app = Flask(__name__) # create the Flask app" 238 | ] 239 | }, 240 | { 241 | "cell_type": "code", 242 | "execution_count": 8, 243 | "id": "b3565aa1", 244 | "metadata": {}, 245 | "outputs": [], 246 | "source": [ 247 | "@app.route('/tweets', methods=['GET'])\n", 248 | "def index():\n", 249 | " \n", 250 | " #retrieve arguments\n", 251 | " args = request.args\n", 252 | " print(args) #debugging\n", 253 | " service = args['service'] \n", 254 | " \n", 255 | " #get summary of website url\n", 256 | " summary = get_summary(\"http://www.amazon.com/\" + service) \n", 257 | " print(summary) #debugging\n", 258 | " \n", 259 | " #generate an image using the summary\n", 260 | " image_name = download_image(generate_image(summary))\n", 261 | " print(image_name) #debugging\n", 262 | " \n", 263 | " #tweet the image\n", 264 | " send_tweet(summary, image_name)\n", 265 | " \n", 266 | " return 'Tweet sent!'" 267 | ] 268 | }, 269 | { 270 | "cell_type": "code", 271 | "execution_count": 9, 272 | "id": "685acde0", 273 | "metadata": {}, 274 | "outputs": [ 275 | { 276 | "name": "stdout", 277 | "output_type": "stream", 278 | "text": [ 279 | " * Serving Flask app '__main__'\n", 280 | " * Debug mode: off\n" 281 | ] 282 | }, 283 | { 284 | "name": "stderr", 285 | "output_type": "stream", 286 | "text": [ 287 | "\u001b[31m\u001b[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.\u001b[0m\n", 288 | " * Running on http://127.0.0.1:5000\n", 289 | "\u001b[33mPress CTRL+C to quit\u001b[0m\n" 290 | ] 291 | }, 292 | { 293 | "name": "stdout", 294 | "output_type": "stream", 295 | "text": [ 296 | "ImmutableMultiDict([('service', 'sagemaker')])\n", 297 | "Please summarize this website http://www.amazon.com/sagemaker\n", 298 | "Amazon SageMaker: Machine learning made easy with comprehensive tools.\n", 299 | "Amazon SageMaker: Machine learning made easy with comprehensive tools.\n", 300 | "downloading - https://oaidalleapiprodscus.blob.core.windows.net/private/org-RZLvEijW4GW0KmC3rLIAjZlu/user-GjAVqpM2XyDru7SeUyCqCIh7/img-fclKawCuhd4Txag7ATfN5WHZ.png?st=2023-11-12T14%3A41%3A35Z&se=2023-11-12T16%3A41%3A35Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-11-12T06%3A01%3A58Z&ske=2023-11-13T06%3A01%3A58Z&sks=b&skv=2021-08-06&sig=USwSsqVJZwoeapuHUNgxRr5bwqVe%2BPmGk9GoprD1sd8%3D\n", 301 | "dalle_image.jpg\n" 302 | ] 303 | }, 304 | { 305 | "name": "stderr", 306 | "output_type": "stream", 307 | "text": [ 308 | "127.0.0.1 - - [12/Nov/2023 10:41:40] \"GET /tweets?service=sagemaker HTTP/1.1\" 200 -\n" 309 | ] 310 | }, 311 | { 312 | "name": "stdout", 313 | "output_type": "stream", 314 | "text": [ 315 | "https://twitter.com/user/status/1723727770948108562\n" 316 | ] 317 | } 318 | ], 319 | "source": [ 320 | "app.run(port=5000) # run app in debug mode on port 5000" 321 | ] 322 | }, 323 | { 324 | "cell_type": "markdown", 325 | "id": "df565fbf", 326 | "metadata": {}, 327 | "source": [ 328 | "## Troubleshooting:\n", 329 | "\n", 330 | "After running the previous cell, your server is running.\n", 331 | "\n", 332 | "### 1.) To test the API go to the Flask API (as Client) notebook\n", 333 | "### 2.) When making coding changes to the API: Kernel->Restart & Run All\n", 334 | "### 3.) Stop the server using the black square next to the Run button" 335 | ] 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": null, 340 | "id": "d1b67b25", 341 | "metadata": {}, 342 | "outputs": [], 343 | "source": [] 344 | } 345 | ], 346 | "metadata": { 347 | "kernelspec": { 348 | "display_name": "Python 3 (ipykernel)", 349 | "language": "python", 350 | "name": "python3" 351 | }, 352 | "language_info": { 353 | "codemirror_mode": { 354 | "name": "ipython", 355 | "version": 3 356 | }, 357 | "file_extension": ".py", 358 | "mimetype": "text/x-python", 359 | "name": "python", 360 | "nbconvert_exporter": "python", 361 | "pygments_lexer": "ipython3", 362 | "version": "3.8.9" 363 | } 364 | }, 365 | "nbformat": 4, 366 | "nbformat_minor": 5 367 | } 368 | -------------------------------------------------------------------------------- /07_04/Solution 07_04 - Post Tweet using the Twitter API .ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "caa8cd98", 6 | "metadata": {}, 7 | "source": [ 8 | "# Building a Project with the ChatGPT API" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "c606f61f", 14 | "metadata": {}, 15 | "source": [ 16 | "## Integrate with Twitter API" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "4e5767de", 22 | "metadata": {}, 23 | "source": [ 24 | "## 07_04 - Solution - Post Tweet using the Twitter API \n", 25 | "\n", 26 | "### In this hands-on challenge, you'll tweet the generated summary and image using the Twitter API\n", 27 | "\n", 28 | "#### The extra credit portion of this challenge is to turn this code into an API using Flask. See notebooks Flask API (with Server) and Flask API (as Client) for more information." 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "id": "ee48e61b", 34 | "metadata": {}, 35 | "source": [ 36 | "### Import the libraries and environment file to gain access to the Open API Key\n", 37 | "#### The key can be generated here: https://platform.openai.com/account/api-keys" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": 1, 43 | "id": "70841de5", 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [ 47 | "import os\n", 48 | "import openai #needed for error handling\n", 49 | "from openai import OpenAI\n", 50 | "\n", 51 | "from dotenv import load_dotenv, find_dotenv\n", 52 | "_ = load_dotenv(find_dotenv()) # read local .env file" 53 | ] 54 | }, 55 | { 56 | "cell_type": "markdown", 57 | "id": "e5387008", 58 | "metadata": {}, 59 | "source": [ 60 | "### Authenticate to the API using the API Key\n", 61 | "#### Pull from environment variables or use api_key = (\"your_key_here\") to hardcode the key" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 2, 67 | "id": "7cf566e0", 68 | "metadata": {}, 69 | "outputs": [], 70 | "source": [ 71 | "client = OpenAI(\n", 72 | " api_key=os.environ['OPENAI_API_KEY'] \n", 73 | ")" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": 3, 79 | "id": "c4fb6162", 80 | "metadata": {}, 81 | "outputs": [], 82 | "source": [ 83 | "TEXT_MODEL = \"gpt-3.5-turbo\"\n", 84 | "\n", 85 | "#sets the persona for the AI assistant using a system message\n", 86 | "context = [{'role':'system', 'content':\"\"\"You are a friendly AI assistant that \n", 87 | " helps compose professional-sounding tweets \n", 88 | " for Twitter that often go viral based on a \n", 89 | " website I provide. You will provide a summary \n", 90 | " of the website in 50 words or less.\"\"\"\n", 91 | " }] " 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 4, 97 | "id": "343f9d1a", 98 | "metadata": {}, 99 | "outputs": [], 100 | "source": [ 101 | "# Each interaction with the AI assistant is a new session so the entire chat/message history, \n", 102 | "# including user prompts and assistant responses must be included in each exchange with the\n", 103 | "# model/assistant so that it \"remembers\"\n", 104 | "\n", 105 | "def collect_messages(role, message): #keeps track of the message exchange between user and assistant\n", 106 | " context.append({'role': role, 'content':f\"{message}\"})" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 5, 112 | "id": "7c3c3660", 113 | "metadata": {}, 114 | "outputs": [], 115 | "source": [ 116 | "# Sends the prompts to the model for a completion/response\n", 117 | "\n", 118 | "def get_completion(temperature=0): \n", 119 | " try:\n", 120 | " response = client.chat.completions.create(\n", 121 | " model=TEXT_MODEL,\n", 122 | " messages=context, \n", 123 | " temperature=temperature, \n", 124 | " )\n", 125 | "\n", 126 | " print(\"\\n Assistant: \", response.choices[0].message.content, \"\\n\")\n", 127 | "\n", 128 | " return response.choices[0].message.content\n", 129 | " except openai.APIError as e:\n", 130 | " print(e.http_status)\n", 131 | " print(e.error)\n", 132 | " return e.error" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 6, 138 | "id": "106c7350", 139 | "metadata": {}, 140 | "outputs": [], 141 | "source": [ 142 | "# Create images from scratch based on the website summary\n", 143 | "\n", 144 | "def generate_image(summary):\n", 145 | " print(summary)\n", 146 | " \n", 147 | " try:\n", 148 | " response = client.images.generate(\n", 149 | " model=\"dall-e-3\",\n", 150 | " prompt=summary,\n", 151 | " size=\"1024x1024\",\n", 152 | " quality=\"standard\",\n", 153 | " n=1, #select the number of images you want generated\n", 154 | " )\n", 155 | " \n", 156 | " image_url = response.data[0].url #URLs will expire after an hour\n", 157 | "\n", 158 | " return image_url\n", 159 | " except openai.APIError as e:\n", 160 | " print(e.http_status)\n", 161 | " print(e.error)\n", 162 | " return e.error" 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": 7, 168 | "id": "ebca5506", 169 | "metadata": {}, 170 | "outputs": [ 171 | { 172 | "name": "stdout", 173 | "output_type": "stream", 174 | "text": [ 175 | "\n", 176 | " Assistant: Sure, please provide me with the website you would like me to summarize. \n", 177 | "\n", 178 | "User: http://www.amazon.com/sagemaker\n", 179 | "\n", 180 | " Assistant: Amazon SageMaker is a comprehensive machine learning service provided by Amazon Web Services (AWS). It allows users to build, train, and deploy machine learning models at scale. With a wide range of tools and capabilities, SageMaker simplifies the process of developing and deploying machine learning models for various applications. \n", 181 | "\n", 182 | "User: Can you optimize the summary in 10 words in order to generate an image?\n", 183 | "\n", 184 | " Assistant: Amazon SageMaker: AWS machine learning service for building, training, deploying models. \n", 185 | "\n", 186 | "User: exit\n", 187 | "\n", 188 | " Goodbye\n" 189 | ] 190 | } 191 | ], 192 | "source": [ 193 | "#Start the conversation between the user and the AI assistant/chatbot\n", 194 | " \n", 195 | "while True:\n", 196 | " summary = get_completion()\n", 197 | " \n", 198 | " collect_messages('assistant', summary) #stores the response from the AI assistant\n", 199 | " \n", 200 | " user_prompt = input('User: ') #input box for entering prompt\n", 201 | " \n", 202 | " if user_prompt == 'exit': #end the conversation with the AI assistant\n", 203 | " print(\"\\n Goodbye\")\n", 204 | " break\n", 205 | "\n", 206 | " collect_messages('user', user_prompt) #stores the user prompt" 207 | ] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": 8, 212 | "id": "752b0110", 213 | "metadata": {}, 214 | "outputs": [ 215 | { 216 | "name": "stdout", 217 | "output_type": "stream", 218 | "text": [ 219 | "Amazon SageMaker: AWS machine learning service for building, training, deploying models.\n" 220 | ] 221 | } 222 | ], 223 | "source": [ 224 | "url = generate_image(summary)" 225 | ] 226 | }, 227 | { 228 | "cell_type": "code", 229 | "execution_count": 9, 230 | "id": "bc196d10", 231 | "metadata": {}, 232 | "outputs": [ 233 | { 234 | "data": { 235 | "text/html": [ 236 | "" 237 | ], 238 | "text/plain": [ 239 | "" 240 | ] 241 | }, 242 | "execution_count": 9, 243 | "metadata": {}, 244 | "output_type": "execute_result" 245 | } 246 | ], 247 | "source": [ 248 | "#display image inline\n", 249 | "\n", 250 | "from IPython.display import Image\n", 251 | "Image(url=url)" 252 | ] 253 | }, 254 | { 255 | "cell_type": "code", 256 | "execution_count": 10, 257 | "id": "cd26130e", 258 | "metadata": {}, 259 | "outputs": [ 260 | { 261 | "name": "stdout", 262 | "output_type": "stream", 263 | "text": [ 264 | "Defaulting to user installation because normal site-packages is not writeable\n", 265 | "Requirement already satisfied: tweepy in /Users/keshawilliams/Library/Python/3.8/lib/python/site-packages (4.14.0)\n", 266 | "Requirement already satisfied: oauthlib<4,>=3.2.0 in /Users/keshawilliams/Library/Python/3.8/lib/python/site-packages (from tweepy) (3.2.2)\n", 267 | "Requirement already satisfied: requests<3,>=2.27.0 in /Users/keshawilliams/Library/Python/3.8/lib/python/site-packages (from tweepy) (2.31.0)\n", 268 | "Requirement already satisfied: requests-oauthlib<2,>=1.2.0 in /Users/keshawilliams/Library/Python/3.8/lib/python/site-packages (from tweepy) (1.3.1)\n", 269 | "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/keshawilliams/Library/Python/3.8/lib/python/site-packages (from requests<3,>=2.27.0->tweepy) (3.1.0)\n", 270 | "Requirement already satisfied: idna<4,>=2.5 in /Users/keshawilliams/Library/Python/3.8/lib/python/site-packages (from requests<3,>=2.27.0->tweepy) (3.4)\n", 271 | "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/keshawilliams/Library/Python/3.8/lib/python/site-packages (from requests<3,>=2.27.0->tweepy) (1.26.6)\n", 272 | "Requirement already satisfied: certifi>=2017.4.17 in /Users/keshawilliams/Library/Python/3.8/lib/python/site-packages (from requests<3,>=2.27.0->tweepy) (2023.5.7)\n", 273 | "Note: you may need to restart the kernel to use updated packages.\n" 274 | ] 275 | } 276 | ], 277 | "source": [ 278 | "pip install tweepy" 279 | ] 280 | }, 281 | { 282 | "cell_type": "code", 283 | "execution_count": 11, 284 | "id": "1673aef7", 285 | "metadata": {}, 286 | "outputs": [], 287 | "source": [ 288 | "import tweepy\n", 289 | "import requests\n", 290 | "\n", 291 | "# Authenticate to Twitter API\n", 292 | "consumer_key = os.getenv(\"API_KEY\")\n", 293 | "consumer_secret = os.getenv(\"API_SECRET_KEY\")\n", 294 | "access_token = os.getenv(\"ACCESS_TOKEN\") \n", 295 | "access_token_secret = os.getenv(\"ACCESS_TOKEN_SECRET_KEY\") \n", 296 | "\n", 297 | "#download image to notebook\n", 298 | "def download_image(imageURL):\n", 299 | " print(\"downloading - \", imageURL)\n", 300 | " \n", 301 | " img_data = requests.get(imageURL).content\n", 302 | " with open('dalle_image.jpg', 'wb') as handler:\n", 303 | " handler.write(img_data)\n", 304 | " \n", 305 | " return \"dalle_image.jpg\"\n", 306 | "\n", 307 | "#upload image media using V1 of Twitter API\n", 308 | "def upload_image(image):\n", 309 | " auth = tweepy.OAuth1UserHandler(\n", 310 | " consumer_key,\n", 311 | " consumer_secret,\n", 312 | " access_token,\n", 313 | " access_token_secret\n", 314 | " )\n", 315 | "\n", 316 | " api = tweepy.API(auth)\n", 317 | " media = api.media_upload(filename=image) \n", 318 | " \n", 319 | " return media\n", 320 | "\n", 321 | "#send the tweet using V2 of the Twitter API\n", 322 | "def send_tweet(summary, image):\n", 323 | " client = tweepy.Client(\n", 324 | " consumer_key=consumer_key, consumer_secret=consumer_secret,\n", 325 | " access_token=access_token, access_token_secret=access_token_secret\n", 326 | " )\n", 327 | "\n", 328 | " #upload image to Twitter servers and get the media metadata\n", 329 | " media = upload_image(image)\n", 330 | " media_ids = [media.media_id]\n", 331 | " \n", 332 | " #send the tweet\n", 333 | " response = client.create_tweet(text=summary, media_ids=media_ids)\n", 334 | " \n", 335 | " print(f\"https://twitter.com/user/status/{response.data['id']}\")" 336 | ] 337 | }, 338 | { 339 | "cell_type": "code", 340 | "execution_count": 12, 341 | "id": "a72a005f", 342 | "metadata": {}, 343 | "outputs": [ 344 | { 345 | "name": "stdout", 346 | "output_type": "stream", 347 | "text": [ 348 | "downloading - https://oaidalleapiprodscus.blob.core.windows.net/private/org-RZLvEijW4GW0KmC3rLIAjZlu/user-GjAVqpM2XyDru7SeUyCqCIh7/img-8uVBclcPGCaW1FefijjvYQyK.png?st=2023-11-12T14%3A33%3A49Z&se=2023-11-12T16%3A33%3A49Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-11-12T13%3A44%3A14Z&ske=2023-11-13T13%3A44%3A14Z&sks=b&skv=2021-08-06&sig=k0zO4Izhq1sZNCZFz45Byx3YxZhl2ZmJ1Kqiut66/NQ%3D\n" 349 | ] 350 | } 351 | ], 352 | "source": [ 353 | "#download image to the notebook\n", 354 | "image_name = download_image(url)" 355 | ] 356 | }, 357 | { 358 | "cell_type": "code", 359 | "execution_count": 13, 360 | "id": "bcfaefa8", 361 | "metadata": {}, 362 | "outputs": [ 363 | { 364 | "name": "stdout", 365 | "output_type": "stream", 366 | "text": [ 367 | "https://twitter.com/user/status/1723725825856479568\n" 368 | ] 369 | } 370 | ], 371 | "source": [ 372 | "#send tweet\n", 373 | "send_tweet(summary, image_name)" 374 | ] 375 | }, 376 | { 377 | "cell_type": "code", 378 | "execution_count": null, 379 | "id": "36777f98", 380 | "metadata": {}, 381 | "outputs": [], 382 | "source": [] 383 | } 384 | ], 385 | "metadata": { 386 | "kernelspec": { 387 | "display_name": "Python 3 (ipykernel)", 388 | "language": "python", 389 | "name": "python3" 390 | }, 391 | "language_info": { 392 | "codemirror_mode": { 393 | "name": "ipython", 394 | "version": 3 395 | }, 396 | "file_extension": ".py", 397 | "mimetype": "text/x-python", 398 | "name": "python", 399 | "nbconvert_exporter": "python", 400 | "pygments_lexer": "ipython3", 401 | "version": "3.8.9" 402 | } 403 | }, 404 | "nbformat": 4, 405 | "nbformat_minor": 5 406 | } 407 | -------------------------------------------------------------------------------- /07_04/dalle_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinkedInLearning/building-a-project-with-the-chatgpt-api-4484140/8e9d5d6f30648d3d638d9021d0a9b928b3dbe494/07_04/dalle_image.jpg -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | Contribution Agreement 3 | ====================== 4 | 5 | This repository does not accept pull requests (PRs). All pull requests will be closed. 6 | 7 | However, if any contributions (through pull requests, issues, feedback or otherwise) are provided, as a contributor, you represent that the code you submit is your original work or that of your employer (in which case you represent you have the right to bind your employer). By submitting code (or otherwise providing feedback), you (and, if applicable, your employer) are licensing the submitted code (and/or feedback) to LinkedIn and the open source community subject to the BSD 2-Clause license. 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | LinkedIn Learning Exercise Files License Agreement 2 | ================================================== 3 | 4 | This License Agreement (the "Agreement") is a binding legal agreement 5 | between you (as an individual or entity, as applicable) and LinkedIn 6 | Corporation (“LinkedIn”). By downloading or using the LinkedIn Learning 7 | exercise files in this repository (“Licensed Materials”), you agree to 8 | be bound by the terms of this Agreement. If you do not agree to these 9 | terms, do not download or use the Licensed Materials. 10 | 11 | 1. License. 12 | - a. Subject to the terms of this Agreement, LinkedIn hereby grants LinkedIn 13 | members during their LinkedIn Learning subscription a non-exclusive, 14 | non-transferable copyright license, for internal use only, to 1) make a 15 | reasonable number of copies of the Licensed Materials, and 2) make 16 | derivative works of the Licensed Materials for the sole purpose of 17 | practicing skills taught in LinkedIn Learning courses. 18 | - b. Distribution. Unless otherwise noted in the Licensed Materials, subject 19 | to the terms of this Agreement, LinkedIn hereby grants LinkedIn members 20 | with a LinkedIn Learning subscription a non-exclusive, non-transferable 21 | copyright license to distribute the Licensed Materials, except the 22 | Licensed Materials may not be included in any product or service (or 23 | otherwise used) to instruct or educate others. 24 | 25 | 2. Restrictions and Intellectual Property. 26 | - a. You may not to use, modify, copy, make derivative works of, publish, 27 | distribute, rent, lease, sell, sublicense, assign or otherwise transfer the 28 | Licensed Materials, except as expressly set forth above in Section 1. 29 | - b. Linkedin (and its licensors) retains its intellectual property rights 30 | in the Licensed Materials. Except as expressly set forth in Section 1, 31 | LinkedIn grants no licenses. 32 | - c. You indemnify LinkedIn and its licensors and affiliates for i) any 33 | alleged infringement or misappropriation of any intellectual property rights 34 | of any third party based on modifications you make to the Licensed Materials, 35 | ii) any claims arising from your use or distribution of all or part of the 36 | Licensed Materials and iii) a breach of this Agreement. You will defend, hold 37 | harmless, and indemnify LinkedIn and its affiliates (and our and their 38 | respective employees, shareholders, and directors) from any claim or action 39 | brought by a third party, including all damages, liabilities, costs and 40 | expenses, including reasonable attorneys’ fees, to the extent resulting from, 41 | alleged to have resulted from, or in connection with: (a) your breach of your 42 | obligations herein; or (b) your use or distribution of any Licensed Materials. 43 | 44 | 3. Open source. This code may include open source software, which may be 45 | subject to other license terms as provided in the files. 46 | 47 | 4. Warranty Disclaimer. LINKEDIN PROVIDES THE LICENSED MATERIALS ON AN “AS IS” 48 | AND “AS AVAILABLE” BASIS. LINKEDIN MAKES NO REPRESENTATION OR WARRANTY, 49 | WHETHER EXPRESS OR IMPLIED, ABOUT THE LICENSED MATERIALS, INCLUDING ANY 50 | REPRESENTATION THAT THE LICENSED MATERIALS WILL BE FREE OF ERRORS, BUGS OR 51 | INTERRUPTIONS, OR THAT THE LICENSED MATERIALS ARE ACCURATE, COMPLETE OR 52 | OTHERWISE VALID. TO THE FULLEST EXTENT PERMITTED BY LAW, LINKEDIN AND ITS 53 | AFFILIATES DISCLAIM ANY IMPLIED OR STATUTORY WARRANTY OR CONDITION, INCLUDING 54 | ANY IMPLIED WARRANTY OR CONDITION OF MERCHANTABILITY OR FITNESS FOR A 55 | PARTICULAR PURPOSE, AVAILABILITY, SECURITY, TITLE AND/OR NON-INFRINGEMENT. 56 | YOUR USE OF THE LICENSED MATERIALS IS AT YOUR OWN DISCRETION AND RISK, AND 57 | YOU WILL BE SOLELY RESPONSIBLE FOR ANY DAMAGE THAT RESULTS FROM USE OF THE 58 | LICENSED MATERIALS TO YOUR COMPUTER SYSTEM OR LOSS OF DATA. NO ADVICE OR 59 | INFORMATION, WHETHER ORAL OR WRITTEN, OBTAINED BY YOU FROM US OR THROUGH OR 60 | FROM THE LICENSED MATERIALS WILL CREATE ANY WARRANTY OR CONDITION NOT 61 | EXPRESSLY STATED IN THESE TERMS. 62 | 63 | 5. Limitation of Liability. LINKEDIN SHALL NOT BE LIABLE FOR ANY INDIRECT, 64 | INCIDENTAL, SPECIAL, PUNITIVE, CONSEQUENTIAL OR EXEMPLARY DAMAGES, INCLUDING 65 | BUT NOT LIMITED TO, DAMAGES FOR LOSS OF PROFITS, GOODWILL, USE, DATA OR OTHER 66 | INTANGIBLE LOSSES . IN NO EVENT WILL LINKEDIN'S AGGREGATE LIABILITY TO YOU 67 | EXCEED $100. THIS LIMITATION OF LIABILITY SHALL: 68 | - i. APPLY REGARDLESS OF WHETHER (A) YOU BASE YOUR CLAIM ON CONTRACT, TORT, 69 | STATUTE, OR ANY OTHER LEGAL THEORY, (B) WE KNEW OR SHOULD HAVE KNOWN ABOUT 70 | THE POSSIBILITY OF SUCH DAMAGES, OR (C) THE LIMITED REMEDIES PROVIDED IN THIS 71 | SECTION FAIL OF THEIR ESSENTIAL PURPOSE; AND 72 | - ii. NOT APPLY TO ANY DAMAGE THAT LINKEDIN MAY CAUSE YOU INTENTIONALLY OR 73 | KNOWINGLY IN VIOLATION OF THESE TERMS OR APPLICABLE LAW, OR AS OTHERWISE 74 | MANDATED BY APPLICABLE LAW THAT CANNOT BE DISCLAIMED IN THESE TERMS. 75 | 76 | 6. Termination. This Agreement automatically terminates upon your breach of 77 | this Agreement or termination of your LinkedIn Learning subscription. On 78 | termination, all licenses granted under this Agreement will terminate 79 | immediately and you will delete the Licensed Materials. Sections 2-7 of this 80 | Agreement survive any termination of this Agreement. LinkedIn may discontinue 81 | the availability of some or all of the Licensed Materials at any time for any 82 | reason. 83 | 84 | 7. Miscellaneous. This Agreement will be governed by and construed in 85 | accordance with the laws of the State of California without regard to conflict 86 | of laws principles. The exclusive forum for any disputes arising out of or 87 | relating to this Agreement shall be an appropriate federal or state court 88 | sitting in the County of Santa Clara, State of California. If LinkedIn does 89 | not act to enforce a breach of this Agreement, that does not mean that 90 | LinkedIn has waived its right to enforce this Agreement. The Agreement does 91 | not create a partnership, agency relationship, or joint venture between the 92 | parties. Neither party has the power or authority to bind the other or to 93 | create any obligation or responsibility on behalf of the other. You may not, 94 | without LinkedIn’s prior written consent, assign or delegate any rights or 95 | obligations under these terms, including in connection with a change of 96 | control. Any purported assignment and delegation shall be ineffective. The 97 | Agreement shall bind and inure to the benefit of the parties, their respective 98 | successors and permitted assigns. If any provision of the Agreement is 99 | unenforceable, that provision will be modified to render it enforceable to the 100 | extent possible to give effect to the parties’ intentions and the remaining 101 | provisions will not be affected. This Agreement is the only agreement between 102 | you and LinkedIn regarding the Licensed Materials, and supersedes all prior 103 | agreements relating to the Licensed Materials. 104 | 105 | Last Updated: March 2019 106 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2023 LinkedIn Corporation 2 | All Rights Reserved. 3 | 4 | Licensed under the LinkedIn Learning Exercise File License (the "License"). 5 | See LICENSE in the project root for license information. 6 | 7 | ATTRIBUTIONS: 8 | [PLEASE PROVIDE ATTRIBUTIONS OR DELETE THIS AND THE ABOVE LINE “ATTRIBUTIONS”] 9 | 10 | Please note, this project may automatically load third party code from external 11 | repositories (for example, NPM modules, Composer packages, or other dependencies). 12 | If so, such third party code may be subject to other license terms than as set 13 | forth above. In addition, such third party code may also depend on and load 14 | multiple tiers of dependencies. Please review the applicable licenses of the 15 | additional dependencies. 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Building a Project with the ChatGPT API 2 | This is the repository for the LinkedIn Learning course Building a Project with the ChatGPT API. The full course is available from [LinkedIn Learning][lil-course-url]. 3 | 4 | ![Building a Project with the ChatGPT API][lil-thumbnail-url] 5 | 6 | Generative models produced by OpenAPI, like ChatGPT, have rapidly advanced AI development, particularly the ability to incorporate AI into applications. In this hands-on course, instructor Kesha Williams takes a deep dive into the world of OpenAI's powerful language models, equipping you with the technical know-how you need to leverage their full potential and create innovative AI-driven solutions. 7 | 8 | Explore various features including text summarization and generation, conversational agents, chatbot development, image generation and manipulation, and more. By the end of this course, you'll have a solid understanding of the OpenAI API, its capabilities, and associated pricing models to start building scalable cost-effective solutions. Along the way, Kesha shows you how to integrate AI into your everyday projects, utilizing the power of OpenAI to create more intelligent, personalized experiences. 9 | 10 | ## Testing: Library & Package Versions 11 | This code has been validated against the following software versions: 12 | ``` 13 | openai 1.2.3 14 | tweepy 4.14.0 15 | ``` 16 | 17 | [0]: # (Replace these placeholder URLs with actual course URLs) 18 | 19 | [lil-course-url]: https://www.linkedin.com/learning/building-a-project-with-the-chatgpt-api 20 | [lil-thumbnail-url]: https://media.licdn.com/dms/image/D560DAQFcICjaYZlNsA/learning-public-crop_675_1200/0/1703108198308?e=2147483647&v=beta&t=tE_nvyhbB8yjb-DClHwc9ubDo19Z97lzZfgtH55V9uQ 21 | 22 | ### Instructor 23 | 24 | Kesha Williams 25 | Software Engineering Manager, Speaker, Tech Blogger 26 | 27 | 28 | Check out my other courses on [LinkedIn Learning](https://www.linkedin.com/learning/instructors/kesha-williams). 29 | 30 | 31 | --------------------------------------------------------------------------------