{
 "cells": [
  {
   "cell_type": "raw",
   "id": "f9112745",
   "metadata": {},
   "source": [
    "---\n",
    "summary: Summary of the post.\n",
    "title: The app decorator\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "918c218a",
   "metadata": {},
   "source": [
    "In this tutorial you'll build your first Yera app. You'll learn about the `@yr.app`\n",
    "decorator and the `yr.response` function.\n",
    "\n",
    "## The app decorator\n",
    "\n",
    "The app decorator turns a python function into a Yera app.\n",
    "All Yera API functions must be used within a function that has been decorated with `yr.app`.\n",
    "\n",
    "You can use it without parameters like this"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5ebadeca",
   "metadata": {},
   "outputs": [],
   "source": [
    "import yera as yr\n",
    "\n",
    "@yr.app\n",
    "def nothing():\n",
    "    pass"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7eb40d44",
   "metadata": {},
   "source": [
    "Or give it inputs like so"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "32ffb148",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import yera as yr\n",
    "\n",
    "@yr.app(name=\"Does Nothing\")\n",
    "def nothing():\n",
    "    pass"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3c52e261",
   "metadata": {},
   "source": [
    "this is how you can set metadata, change the model it uses, set a system prompt etc.\n",
    "We will come back to this in later tutorials, but for now we'll keep it simple and just use the bare `yr.app`.\n",
    "\n",
    "## Your first app\n",
    "\n",
    "Now let's build your first app. We're going to build something that tells us what the capital of France is.\n",
    "Before that, let's introduce a function: `yr.response`.\n",
    "This function invokes the active LLM with the prompt it receives as input."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "724de715",
   "metadata": {},
   "outputs": [],
   "source": [
    "response_text = yr.response(prompt)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f7d5635b",
   "metadata": {},
   "source": [
    "Let's build the app. You're going to import yera, write a function that invokes `yr.response` and then decorate the lot with `yr.app`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e6b239da",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import yera as yr\n",
    "\n",
    "@yr.app\n",
    "def capital():\n",
    "    yr.response(\"What is the capital of France?\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6ad80d50",
   "metadata": {},
   "source": [
    "## Running it\n",
    "\n",
    "If you're in Jupyter, just invoke it"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "93c4b26e",
   "metadata": {},
   "outputs": [],
   "source": [
    "capital()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "64a44d14",
   "metadata": {},
   "source": [
    "if you're running a python script it'll need to be inside a main guard"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fd2bfa1f",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "if __name__ == \"__main__\":\n",
    "  capital()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ca644c44",
   "metadata": {},
   "source": [
    "or you can save it to `capital.py` and just run it via the command line\n",
    "\n",
    "```\n",
    "yera run capital.py\n",
    "```\n",
    "\n",
    "You should see something like this\n",
    "\n",
    "```\n",
    "╭────────────────────────────── Startup ──────────────────────────────╮\n",
    "│ Started: 2026-06-23 11:54:52                                        │\n",
    "│ Top-level App: capital                                              │\n",
    "╰─────────────────────────────────────────────────────────────────────╯\n",
    "\n",
    "╭────────────────────────────── capital ──────────────────────────────╮\n",
    "│ Identifier:  __main__.capital                                       │\n",
    "╰─────────────────────────────────────────────────────────────────────╯\n",
    "\n",
    "{\n",
    "  \"content\": \"What is the capital of France?\"\n",
    "}\n",
    "\n",
    "The capital of France is **Paris**.\n",
    "\n",
    "╭─────────────────────────────── Exit ────────────────────────────────╮\n",
    "│ Completed successfully                                              │\n",
    "│                                                                     │\n",
    "│ Exit code:    0                                                     │\n",
    "│ Reason:       Yera program completed successfully.                  │\n",
    "│ Return value: None                                                  │\n",
    "│                                                                     │\n",
    "│ Run time: 1.60 s                                                    │\n",
    "╰─────────────────────────────────────────────────────────────────────╯\n",
    "```\n",
    "\n",
    "## Next\n",
    "\n",
    "pass"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
