├── README.md └── Introduction.ipynb /README.md: -------------------------------------------------------------------------------- 1 | # langchain-course -------------------------------------------------------------------------------- /Introduction.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "authorship_tag": "ABX9TyP9nw9KYysuioDoQJobh/i4", 8 | "include_colab_link": true 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "language_info": { 15 | "name": "python" 16 | } 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "id": "view-in-github", 23 | "colab_type": "text" 24 | }, 25 | "source": [ 26 | "\"Open" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "source": [ 32 | "# Introduction\n", 33 | "\n", 34 | "In this lesson we will learn the basis of interacting with ChatGPT using a library called Langchain\n", 35 | "\n", 36 | "### Why we use Langchain ?\n", 37 | "\n", 38 | "Langchain is a python library we will use to interact with ChatGPT and build apps on top of it\n", 39 | "\n", 40 | "In this lesson we will learn how to interact with ChatGPT to generate text. Many apps which are valued millions of dollars like JasperAI, CopyAI etc. do the same as part of their core business" 41 | ], 42 | "metadata": { 43 | "id": "w12Jz3h_INct" 44 | } 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "source": [ 49 | "## Generating Text" 50 | ], 51 | "metadata": { 52 | "id": "To0cTjhBFT0V" 53 | } 54 | }, 55 | { 56 | "cell_type": "code", 57 | "source": [ 58 | "# Let's install necessary libraries\n", 59 | "\n", 60 | "!pip install langchain\n", 61 | "!pip install openai\n", 62 | "!pip install tiktoken" 63 | ], 64 | "metadata": { 65 | "id": "TVyqccumI333", 66 | "colab": { 67 | "base_uri": "https://localhost:8080/" 68 | }, 69 | "outputId": "97613191-5b8f-49e0-9a29-043b7fda7683" 70 | }, 71 | "execution_count": 12, 72 | "outputs": [ 73 | { 74 | "output_type": "stream", 75 | "name": "stdout", 76 | "text": [ 77 | "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", 78 | "Requirement already satisfied: langchain in /usr/local/lib/python3.10/dist-packages (0.0.174)\n", 79 | "Requirement already satisfied: PyYAML>=5.4.1 in /usr/local/lib/python3.10/dist-packages (from langchain) (6.0)\n", 80 | "Requirement already satisfied: SQLAlchemy<3,>=1.4 in /usr/local/lib/python3.10/dist-packages (from langchain) (2.0.10)\n", 81 | "Requirement already satisfied: aiohttp<4.0.0,>=3.8.3 in /usr/local/lib/python3.10/dist-packages (from langchain) (3.8.4)\n", 82 | "Requirement already satisfied: async-timeout<5.0.0,>=4.0.0 in /usr/local/lib/python3.10/dist-packages (from langchain) (4.0.2)\n", 83 | "Requirement already satisfied: dataclasses-json<0.6.0,>=0.5.7 in /usr/local/lib/python3.10/dist-packages (from langchain) (0.5.7)\n", 84 | "Requirement already satisfied: numexpr<3.0.0,>=2.8.4 in /usr/local/lib/python3.10/dist-packages (from langchain) (2.8.4)\n", 85 | "Requirement already satisfied: numpy<2,>=1 in /usr/local/lib/python3.10/dist-packages (from langchain) (1.22.4)\n", 86 | "Requirement already satisfied: openapi-schema-pydantic<2.0,>=1.2 in /usr/local/lib/python3.10/dist-packages (from langchain) (1.2.4)\n", 87 | "Requirement already satisfied: pydantic<2,>=1 in /usr/local/lib/python3.10/dist-packages (from langchain) (1.10.7)\n", 88 | "Requirement already satisfied: requests<3,>=2 in /usr/local/lib/python3.10/dist-packages (from langchain) (2.27.1)\n", 89 | "Requirement already satisfied: tenacity<9.0.0,>=8.1.0 in /usr/local/lib/python3.10/dist-packages (from langchain) (8.2.2)\n", 90 | "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (23.1.0)\n", 91 | "Requirement already satisfied: charset-normalizer<4.0,>=2.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (2.0.12)\n", 92 | "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (6.0.4)\n", 93 | "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.9.2)\n", 94 | "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.3.3)\n", 95 | "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.3.1)\n", 96 | "Requirement already satisfied: marshmallow<4.0.0,>=3.3.0 in /usr/local/lib/python3.10/dist-packages (from dataclasses-json<0.6.0,>=0.5.7->langchain) (3.19.0)\n", 97 | "Requirement already satisfied: marshmallow-enum<2.0.0,>=1.5.1 in /usr/local/lib/python3.10/dist-packages (from dataclasses-json<0.6.0,>=0.5.7->langchain) (1.5.1)\n", 98 | "Requirement already satisfied: typing-inspect>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from dataclasses-json<0.6.0,>=0.5.7->langchain) (0.8.0)\n", 99 | "Requirement already satisfied: typing-extensions>=4.2.0 in /usr/local/lib/python3.10/dist-packages (from pydantic<2,>=1->langchain) (4.5.0)\n", 100 | "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain) (1.26.15)\n", 101 | "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain) (2022.12.7)\n", 102 | "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain) (3.4)\n", 103 | "Requirement already satisfied: greenlet!=0.4.17 in /usr/local/lib/python3.10/dist-packages (from SQLAlchemy<3,>=1.4->langchain) (2.0.2)\n", 104 | "Requirement already satisfied: packaging>=17.0 in /usr/local/lib/python3.10/dist-packages (from marshmallow<4.0.0,>=3.3.0->dataclasses-json<0.6.0,>=0.5.7->langchain) (23.1)\n", 105 | "Requirement already satisfied: mypy-extensions>=0.3.0 in /usr/local/lib/python3.10/dist-packages (from typing-inspect>=0.4.0->dataclasses-json<0.6.0,>=0.5.7->langchain) (1.0.0)\n", 106 | "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", 107 | "Requirement already satisfied: openai in /usr/local/lib/python3.10/dist-packages (0.27.7)\n", 108 | "Requirement already satisfied: requests>=2.20 in /usr/local/lib/python3.10/dist-packages (from openai) (2.27.1)\n", 109 | "Requirement already satisfied: tqdm in /usr/local/lib/python3.10/dist-packages (from openai) (4.65.0)\n", 110 | "Requirement already satisfied: aiohttp in /usr/local/lib/python3.10/dist-packages (from openai) (3.8.4)\n", 111 | "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.20->openai) (1.26.15)\n", 112 | "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests>=2.20->openai) (2022.12.7)\n", 113 | "Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.10/dist-packages (from requests>=2.20->openai) (2.0.12)\n", 114 | "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests>=2.20->openai) (3.4)\n", 115 | "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->openai) (23.1.0)\n", 116 | "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp->openai) (6.0.4)\n", 117 | "Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in /usr/local/lib/python3.10/dist-packages (from aiohttp->openai) (4.0.2)\n", 118 | "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->openai) (1.9.2)\n", 119 | "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp->openai) (1.3.3)\n", 120 | "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp->openai) (1.3.1)\n", 121 | "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", 122 | "Collecting tiktoken\n", 123 | " Downloading tiktoken-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB)\n", 124 | "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.7/1.7 MB\u001b[0m \u001b[31m60.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", 125 | "\u001b[?25hRequirement already satisfied: regex>=2022.1.18 in /usr/local/lib/python3.10/dist-packages (from tiktoken) (2022.10.31)\n", 126 | "Requirement already satisfied: requests>=2.26.0 in /usr/local/lib/python3.10/dist-packages (from tiktoken) (2.27.1)\n", 127 | "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.26.0->tiktoken) (1.26.15)\n", 128 | "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests>=2.26.0->tiktoken) (2022.12.7)\n", 129 | "Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.10/dist-packages (from requests>=2.26.0->tiktoken) (2.0.12)\n", 130 | "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests>=2.26.0->tiktoken) (3.4)\n", 131 | "Installing collected packages: tiktoken\n", 132 | "Successfully installed tiktoken-0.4.0\n" 133 | ] 134 | } 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "source": [ 140 | "import os\n", 141 | "os.environ[\"OPENAI_API_KEY\"] = \"openai-key\"" 142 | ], 143 | "metadata": { 144 | "id": "cee7L_56FdMF" 145 | }, 146 | "execution_count": 2, 147 | "outputs": [] 148 | }, 149 | { 150 | "cell_type": "markdown", 151 | "source": [ 152 | "### Text Completion\n", 153 | "\n", 154 | "We will ask GPT to generate an outline for an article we wish to write\n", 155 | "\n", 156 | "As you can see from the output, you can generate a blog article outline from less than 5 lines of codes" 157 | ], 158 | "metadata": { 159 | "id": "UUNVYe0iORva" 160 | } 161 | }, 162 | { 163 | "cell_type": "code", 164 | "source": [ 165 | "from langchain.llms import OpenAI\n", 166 | "llm = OpenAI(temperature=0.9)\n", 167 | "text = \"Write me an outline on Tennis\"\n", 168 | "print(llm(text))" 169 | ], 170 | "metadata": { 171 | "colab": { 172 | "base_uri": "https://localhost:8080/" 173 | }, 174 | "id": "Co34TeW0ODRl", 175 | "outputId": "91495310-bcd1-45ee-dd21-488f76233a82" 176 | }, 177 | "execution_count": 3, 178 | "outputs": [ 179 | { 180 | "output_type": "stream", 181 | "name": "stderr", 182 | "text": [ 183 | "WARNING:langchain.utilities.powerbi:Could not import azure.core python package.\n" 184 | ] 185 | }, 186 | { 187 | "output_type": "stream", 188 | "name": "stdout", 189 | "text": [ 190 | "\n", 191 | "\n", 192 | "I. Introduction \n", 193 | "A. History of Tennis\n", 194 | "B. Popularity of Tennis\n", 195 | "\n", 196 | "II. Rules of Tennis \n", 197 | "A. Scoring\n", 198 | "B. Court Layout\n", 199 | "C. Types of Shots\n", 200 | "\n", 201 | "III. Equipment Used in Tennis\n", 202 | "A. Rackets\n", 203 | "B. Strings\n", 204 | "C. Shoes \n", 205 | "\n", 206 | "IV. Types of Tennis \n", 207 | "A. Singles\n", 208 | "B. Doubles \n", 209 | "\n", 210 | "V. Strategies of Tennis \n", 211 | "A. Serve\n", 212 | "B. Return\n", 213 | "C. Groundstrokes\n", 214 | "\n", 215 | "VI. Professional Tennis \n", 216 | "A. Major Events \n", 217 | "B. Professional Players \n", 218 | "\n", 219 | "VII. Conclusion \n", 220 | "A. Benefits of Playing Tennis\n", 221 | "B. Summary of Tennis\n" 222 | ] 223 | } 224 | ] 225 | }, 226 | { 227 | "cell_type": "markdown", 228 | "source": [ 229 | "## *Templates*\n", 230 | "\n", 231 | "This is the bread and butter of companies like Jasper and CopyAI. They have a bunch of pre-made templates for various use-cases like Blog Writing, Email writing, Sales letter etc. \n", 232 | "\n", 233 | "You can pick any one template and enter your input and can generate relevant content.\n", 234 | "\n", 235 | "In this example we will discover how we can generate one such template for the above *example*" 236 | ], 237 | "metadata": { 238 | "id": "ghdws72ROs9I" 239 | } 240 | }, 241 | { 242 | "cell_type": "code", 243 | "source": [ 244 | "from langchain.prompts import PromptTemplate\n", 245 | "prompt = PromptTemplate(\n", 246 | " input_variables=[\"topic\"],\n", 247 | " template=\"Write me an outline on {topic}\",\n", 248 | ")\n", 249 | "# The topic varialble is going to be dynamically assigned" 250 | ], 251 | "metadata": { 252 | "id": "Q2-VN6LTGBIl" 253 | }, 254 | "execution_count": 4, 255 | "outputs": [] 256 | }, 257 | { 258 | "cell_type": "markdown", 259 | "source": [ 260 | "## Chains\n", 261 | "\n", 262 | "Now we are going to use a Langchain concept Chains. Chains are responsible for the entire data flow inside Langchain. As we discussed above we are passing dynamic topic input variable to OpenAI. To accommodate this we will be using a chain called LLMChain. There are a bunch of chains supported in Langchain, we will talk about them later\n", 263 | "\n", 264 | "LLMChain takes the prompt from the prompt template we created above and fills it up with the dynamic input before passing to OpenAI LLM. Let's define LLMChain below" 265 | ], 266 | "metadata": { 267 | "id": "fT_DGdA9VGE8" 268 | } 269 | }, 270 | { 271 | "cell_type": "code", 272 | "source": [ 273 | "from langchain.chains import LLMChain\n", 274 | "chain = LLMChain(llm=llm, prompt=prompt)" 275 | ], 276 | "metadata": { 277 | "id": "lszkNwMNVNiV" 278 | }, 279 | "execution_count": 5, 280 | "outputs": [] 281 | }, 282 | { 283 | "cell_type": "markdown", 284 | "source": [ 285 | "Now that we have created a prompt template and a chain we can now input any topic we want. Instead of topic \"Tennis\" we can input \"Cricket\" or any other topic of your choice" 286 | ], 287 | "metadata": { 288 | "id": "PNRq_YnoQByB" 289 | } 290 | }, 291 | { 292 | "cell_type": "code", 293 | "source": [ 294 | "print(chain.run(topic=\"Cricket\"))" 295 | ], 296 | "metadata": { 297 | "colab": { 298 | "base_uri": "https://localhost:8080/" 299 | }, 300 | "id": "wUh0JGOgPxyv", 301 | "outputId": "cefee482-9ba6-4313-908b-555d2c511162" 302 | }, 303 | "execution_count": 6, 304 | "outputs": [ 305 | { 306 | "output_type": "stream", 307 | "name": "stdout", 308 | "text": [ 309 | "\n", 310 | "\n", 311 | "I. Introduction \n", 312 | "A. Definition of Cricket\n", 313 | "B. History of Cricket\n", 314 | "\n", 315 | "II. Rules \n", 316 | "A. Players\n", 317 | "B. Equipment\n", 318 | "C. Field Layout\n", 319 | "\n", 320 | "III. Playing the Game\n", 321 | "A. Batting\n", 322 | "B. Bowling\n", 323 | "C. Scoring\n", 324 | "\n", 325 | "IV. Conclusion \n", 326 | "A. Overview of game \n", 327 | "B. Importance of Cricket\n" 328 | ] 329 | } 330 | ] 331 | }, 332 | { 333 | "cell_type": "markdown", 334 | "source": [ 335 | "Now let's extend it for a multi-input prompt. Let's generate an introductory paragraph to a blog post with variables title, audience and tone of voice" 336 | ], 337 | "metadata": { 338 | "id": "uVBNjz2OSzrs" 339 | } 340 | }, 341 | { 342 | "cell_type": "code", 343 | "source": [ 344 | "prompt = PromptTemplate(\n", 345 | " input_variables=[\"title\", \"audience\", \"tone\"],\n", 346 | " template=\"\"\"This program will generate an introductory paragraph to a blog post given a blog title, audience, and tone of voice\n", 347 | "\n", 348 | " Blog Title: {title}\n", 349 | " Audience: {audience}\n", 350 | " Tone of Voice: {tone}\"\"\",\n", 351 | ")\n", 352 | "chain = LLMChain(llm=llm, prompt=prompt)" 353 | ], 354 | "metadata": { 355 | "id": "vqVEYaPPGJuM" 356 | }, 357 | "execution_count": 7, 358 | "outputs": [] 359 | }, 360 | { 361 | "cell_type": "code", 362 | "source": [ 363 | "print(chain.run(title=\"Best Activities in Toronto\", audience=\"Millenials\", tone=\"Lighthearted\"))" 364 | ], 365 | "metadata": { 366 | "colab": { 367 | "base_uri": "https://localhost:8080/" 368 | }, 369 | "id": "dJgvUP0pSVat", 370 | "outputId": "56838235-2e98-4580-9301-6b0808f89a5e" 371 | }, 372 | "execution_count": 8, 373 | "outputs": [ 374 | { 375 | "output_type": "stream", 376 | "name": "stdout", 377 | "text": [ 378 | "\n", 379 | "\n", 380 | "Are you a millennial looking for the best activities to do in Toronto? Look no further! From vibrant nightlife to outdoor adventures, Toronto has something for everyone. Whether you’re looking to make memories, relax or explore, this city has it all! In this blog post, we'll dive into the top activities that millenials should add to their bucket list. So get ready for some fun, as we explore the best activities that Toronto has to offer!\n" 381 | ] 382 | } 383 | ] 384 | }, 385 | { 386 | "cell_type": "markdown", 387 | "source": [ 388 | "## Combining Chains\n", 389 | "\n", 390 | "Often we would want to do multiple tasks using GPT. For example if we wish to generate an outline for a topic and use that outline to write a blog article we need to take the outline created from the first step and copy paste and paste as input to the second step\n", 391 | "\n", 392 | "Instead we can combine chains to achieve this in a single step. We will do this using a different type of chain called Sequential Chain. A sequential chain takes the output from one chain and passes on to the next. We will cover chains in more detail later" 393 | ], 394 | "metadata": { 395 | "id": "eP3dAgTgWq-r" 396 | } 397 | }, 398 | { 399 | "cell_type": "code", 400 | "source": [ 401 | "from langchain.prompts import PromptTemplate\n", 402 | "prompt = PromptTemplate(\n", 403 | " input_variables=[\"topic\"],\n", 404 | " template=\"Write me an outline on {topic}\",\n", 405 | ")\n", 406 | "llm = OpenAI(temperature=0.9, max_tokens=-1)\n", 407 | "chain = LLMChain(llm=llm, prompt=prompt)\n", 408 | "second_prompt = PromptTemplate(\n", 409 | " input_variables=[\"outline\"],\n", 410 | " template=\"\"\"Write a blog article in the format of the given outline \n", 411 | "\n", 412 | " Outline:\n", 413 | " {outline}\"\"\",\n", 414 | ")\n", 415 | "chain_two = LLMChain(llm=llm, prompt=second_prompt)" 416 | ], 417 | "metadata": { 418 | "id": "UqHNoQ1OXLCC" 419 | }, 420 | "execution_count": 14, 421 | "outputs": [] 422 | }, 423 | { 424 | "cell_type": "code", 425 | "source": [ 426 | "from langchain.chains import SimpleSequentialChain\n", 427 | "overall_chain = SimpleSequentialChain(chains=[chain, chain_two], verbose=True)\n", 428 | "\n", 429 | "# Run the chain specifying only the input variable for the first chain.\n", 430 | "catchphrase = overall_chain.run(\"Tennis\")\n", 431 | "print(catchphrase)" 432 | ], 433 | "metadata": { 434 | "colab": { 435 | "base_uri": "https://localhost:8080/" 436 | }, 437 | "id": "iIieZmmAXaCC", 438 | "outputId": "ff62bf70-503d-41b0-82a5-ea54a80a0e1d" 439 | }, 440 | "execution_count": 15, 441 | "outputs": [ 442 | { 443 | "output_type": "stream", 444 | "name": "stdout", 445 | "text": [ 446 | "\n", 447 | "\n", 448 | "\u001b[1m> Entering new SimpleSequentialChain chain...\u001b[0m\n", 449 | "\u001b[36;1m\u001b[1;3m\n", 450 | "\n", 451 | "I. Introduction \n", 452 | "A. Definition of Tennis\n", 453 | "B. History of Tennis\n", 454 | "\n", 455 | "II. Popularity of Tennis \n", 456 | "A. Current Tennis Tournaments\n", 457 | "B. Popular Players\n", 458 | "\n", 459 | "III. Tactics and Techniques Used in Tennis \n", 460 | "A. Strokes \n", 461 | "B. Footwork \n", 462 | "C. Serves \n", 463 | "\n", 464 | "IV. Equipment Used in Tennis \n", 465 | "A. Types of Racquets \n", 466 | "B. String Tension\n", 467 | "C. Tennis Balls\n", 468 | "\n", 469 | "V. Physical and Mental Aspects of Tennis \n", 470 | "A. Physical Benefits\n", 471 | "B. Mental Benefits \n", 472 | "\n", 473 | "VI. Conclusion \n", 474 | "A. Summary of Tennis \n", 475 | "B. Benefits of Playing Tennis\u001b[0m\n", 476 | "\u001b[33;1m\u001b[1;3m\n", 477 | "\n", 478 | "Introduction \n", 479 | "Tennis is a popular sport that is played with two or four players. It has a long history, influential players, and many tournaments around the world. The game consists of hitting a small ball with a racquet over a net into the opponent’s court. So, what are the specifics of a competitive game of tennis?\n", 480 | "\n", 481 | "Popularity of Tennis \n", 482 | "Tennis has many professional tournaments around the world that attract millions of viewers and contribute billions to the economy. Every four years the Davis Cup is held, which is a men’s international tennis tournament that features teams from around the world. In addition, the Australian Open, the French Open, and Wimbledon are some of the most prestigious tennis tournaments in the world. Notable tennis players like Roger Federer, Rafael Nadal, and Serena Williams have made tennis all the more popular with their incredible performances in various tournaments. \n", 483 | "\n", 484 | "Tactics and Techniques Used in Tennis \n", 485 | "Tennis is a sport that requires intense strategy and a variety of strokes in order to be successful. Different strokes like forehand, backhand, volleys, and smashes are used to maneuver the ball from one end of the court to the other. In addition, the footwork of players is very important as it helps them to move around the court to reach the ball more easily. The serve is also an important part of tennis and players must be able to strategize and effectively execute their serves. \n", 486 | "\n", 487 | "Equipment Used in Tennis \n", 488 | "Tennis racquets come in many shapes and sizes and can be made of various materials depending on the player’s preference. The racquet strings can also be of various tensions, from very loose to very tight. The type of strings and tension can determine the power and control of a player’s strokes. Tennis balls are also an important part of the equipment used and are generally made of rubber or foam with a felt coating. \n", 489 | "\n", 490 | "Physical and Mental Aspects of Tennis \n", 491 | "Playing tennis provides many physical benefits, such as improved hand-eye coordination, agility, and muscle strength. It also enhances mental well-being by helping with concentration, motivation, and stress relief. The mental aspect of tennis is also very important as players must be able to strategize in order to outwit their opponents. \n", 492 | "\n", 493 | "Conclusion \n", 494 | "In conclusion, tennis is a very popular sport that has been played for centuries. It requires a variety of strokes, footwork, and serves in order to be successful. Players must also utilize different types of equipment like racquets, strings, and balls in order to perform. Lastly, playing tennis offers many physical and mental benefits, making it a great sport for anyone to try.\u001b[0m\n", 495 | "\n", 496 | "\u001b[1m> Finished chain.\u001b[0m\n", 497 | "\n", 498 | "\n", 499 | "Introduction \n", 500 | "Tennis is a popular sport that is played with two or four players. It has a long history, influential players, and many tournaments around the world. The game consists of hitting a small ball with a racquet over a net into the opponent’s court. So, what are the specifics of a competitive game of tennis?\n", 501 | "\n", 502 | "Popularity of Tennis \n", 503 | "Tennis has many professional tournaments around the world that attract millions of viewers and contribute billions to the economy. Every four years the Davis Cup is held, which is a men’s international tennis tournament that features teams from around the world. In addition, the Australian Open, the French Open, and Wimbledon are some of the most prestigious tennis tournaments in the world. Notable tennis players like Roger Federer, Rafael Nadal, and Serena Williams have made tennis all the more popular with their incredible performances in various tournaments. \n", 504 | "\n", 505 | "Tactics and Techniques Used in Tennis \n", 506 | "Tennis is a sport that requires intense strategy and a variety of strokes in order to be successful. Different strokes like forehand, backhand, volleys, and smashes are used to maneuver the ball from one end of the court to the other. In addition, the footwork of players is very important as it helps them to move around the court to reach the ball more easily. The serve is also an important part of tennis and players must be able to strategize and effectively execute their serves. \n", 507 | "\n", 508 | "Equipment Used in Tennis \n", 509 | "Tennis racquets come in many shapes and sizes and can be made of various materials depending on the player’s preference. The racquet strings can also be of various tensions, from very loose to very tight. The type of strings and tension can determine the power and control of a player’s strokes. Tennis balls are also an important part of the equipment used and are generally made of rubber or foam with a felt coating. \n", 510 | "\n", 511 | "Physical and Mental Aspects of Tennis \n", 512 | "Playing tennis provides many physical benefits, such as improved hand-eye coordination, agility, and muscle strength. It also enhances mental well-being by helping with concentration, motivation, and stress relief. The mental aspect of tennis is also very important as players must be able to strategize in order to outwit their opponents. \n", 513 | "\n", 514 | "Conclusion \n", 515 | "In conclusion, tennis is a very popular sport that has been played for centuries. It requires a variety of strokes, footwork, and serves in order to be successful. Players must also utilize different types of equipment like racquets, strings, and balls in order to perform. Lastly, playing tennis offers many physical and mental benefits, making it a great sport for anyone to try.\n" 516 | ] 517 | } 518 | ] 519 | } 520 | ] 521 | } --------------------------------------------------------------------------------