Modernise docs
This commit is contained in:
parent
e446d95855
commit
37b4c17f59
1 changed files with 8196 additions and 3218 deletions
|
|
@ -9,36 +9,52 @@
|
|||
"Finally, it's time to deploy your model. But before that, you have to make sure you follow AI deployment [best practices](https://se-ml.github.io/). In the past, this step was too often either the source of unexpected struggle, or worse, simply ignored.\n",
|
||||
"\n",
|
||||
"GreatAI's decorators add tracing and API scaffolding with a few lines of code. This brings the service nearly to production readiness, but does not establish the model's accuracy, fairness, or trustworthiness. Evaluate the model for its intended use, configure a production-suitable tracing database and storage, and review the remaining deployment best practices. The local TinyDB backend used below is for development, as the output warns."
|
||||
]
|
||||
],
|
||||
"id": "cell-0"
|
||||
},
|
||||
{
|
||||
"id": "94c0cd76",
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"## Local setup\n",
|
||||
"\n",
|
||||
"Use Python 3.12 or 3.13 and install this checkout with `uv pip install --editable '.[notebooks]'`.\n",
|
||||
"See **Run notebooks locally** in the repository README for the kernel, execution order,\n",
|
||||
"and full-data options. Generated artifacts stay under `.cache/notebooks/`.\n"
|
||||
],
|
||||
"metadata": {}
|
||||
},
|
||||
{
|
||||
"id": "bf8f9a33",
|
||||
"cell_type": "code",
|
||||
"metadata": {},
|
||||
"execution_count": null,
|
||||
"source": [
|
||||
"import os\n",
|
||||
"import sys\n",
|
||||
"from pathlib import Path\n",
|
||||
"\n",
|
||||
"# Works when opened from the repository root or any notebook directory.\n",
|
||||
"_start = Path(globals().get(\"__file__\", Path.cwd())).resolve()\n",
|
||||
"ROOT = next(\n",
|
||||
" p\n",
|
||||
" for p in [_start, *_start.parents]\n",
|
||||
" if (p / \"pyproject.toml\").is_file() and (p / \"great_ai\").is_dir()\n",
|
||||
")\n",
|
||||
"sys.path.insert(0, str(ROOT / \"docs\"))\n",
|
||||
"from notebook_support import setup_notebook, mag_lines\n",
|
||||
"\n",
|
||||
"FULL_RUN = os.environ.get(\"GREAT_AI_NOTEBOOK_FULL\") == \"1\"\n",
|
||||
"WORK_DIR = setup_notebook(ROOT, \"tutorial\")\n",
|
||||
"DATA_DIR = ROOT / \"docs/tutorial/data\""
|
||||
],
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"\u001b[38;5;226mEnvironment variable ENVIRONMENT is not set, defaulting to development mode ‼️\u001b[0m\n",
|
||||
"\u001b[38;5;226mCannot find credentials files, defaulting to using ParallelTinyDbDriver\u001b[0m\n",
|
||||
"\u001b[38;5;226mThe selected tracing database (ParallelTinyDbDriver) is not recommended for production\u001b[0m\n",
|
||||
"\u001b[38;5;226mCannot find credentials files, defaulting to using LargeFileLocal\u001b[0m\n",
|
||||
"\u001b[38;5;39mGreatAI (v0.1.4): configured ✅\u001b[0m\n",
|
||||
"\u001b[38;5;39m 🔩 tracing_database: ParallelTinyDbDriver\u001b[0m\n",
|
||||
"\u001b[38;5;39m 🔩 large_file_implementation: LargeFileLocal\u001b[0m\n",
|
||||
"\u001b[38;5;39m 🔩 is_production: False\u001b[0m\n",
|
||||
"\u001b[38;5;39m 🔩 should_log_exception_stack: True\u001b[0m\n",
|
||||
"\u001b[38;5;39m 🔩 prediction_cache_size: 512\u001b[0m\n",
|
||||
"\u001b[38;5;39m 🔩 dashboard_table_size: 50\u001b[0m\n",
|
||||
"\u001b[38;5;226mYou still need to check whether you follow all best practices before trusting your deployment.\u001b[0m\n",
|
||||
"\u001b[38;5;226m> Find out more at https://se-ml.github.io/practices\u001b[0m\n",
|
||||
"\u001b[38;5;39mFetching cached versions of my-domain-predictor\u001b[0m\n",
|
||||
"\u001b[38;5;39mLatest version of my-domain-predictor is 9 (from versions: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)\u001b[0m\n",
|
||||
"\u001b[38;5;39mFile my-domain-predictor-9 found in cache\u001b[0m\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from great_ai import GreatAI, use_model\n",
|
||||
"from great_ai.utilities import clean\n",
|
||||
|
|
@ -49,89 +65,55 @@
|
|||
"def predict_domain(sentence, model):\n",
|
||||
" inputs = [clean(sentence)]\n",
|
||||
" return str(model.predict(inputs)[0])"
|
||||
]
|
||||
],
|
||||
"id": "cell-3"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"Trace[str]({'created': '2022-07-12T13:34:26.743292',\n",
|
||||
" 'exception': None,\n",
|
||||
" 'feedback': None,\n",
|
||||
" 'logged_values': { 'arg:sentence:length': 29,\n",
|
||||
" 'arg:sentence:value': 'Mountains are just big rocks.'},\n",
|
||||
" 'models': [{'key': 'my-domain-predictor', 'version': 9}],\n",
|
||||
" 'original_execution_time_ms': 6.9699,\n",
|
||||
" 'output': 'geography',\n",
|
||||
" 'tags': ['predict_domain', 'online', 'development'],\n",
|
||||
" 'trace_id': 'c80bdee3-602b-49dd-a84d-6eef80127e5a'})"
|
||||
]
|
||||
},
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"predict_domain(\"Mountains are just big rocks.\")"
|
||||
]
|
||||
],
|
||||
"id": "cell-4"
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Notice how the original return value is under the `.output` key. Additionally, a plethora of metadata has been added which will be useful later on.\n",
|
||||
"Notice how the original return value is under the `.output` key, alongside\n",
|
||||
"tracing metadata. Run `train.ipynb` first, using the same local/full mode.\n",
|
||||
"\n",
|
||||
"Running your app in development-mode is as easy as executing `great-ai deploy.ipynb` from your terminal."
|
||||
]
|
||||
"Start the development server in a separate terminal from the checkout root:\n",
|
||||
"\n",
|
||||
"```sh\n",
|
||||
"source .venv/bin/activate\n",
|
||||
"great-ai docs/tutorial/deploy.ipynb\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Open http://127.0.0.1:6060/dashboard. Stop the server with Ctrl+C.\n",
|
||||
"The next cell tests the HTTP API in-process so that **Run All** can finish."
|
||||
],
|
||||
"id": "cell-5"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"\u001b[38;5;39m2022-07-12 15:34:28 | INFO | Converting notebook to Python script\u001b[0m\n",
|
||||
"\u001b[38;5;39m2022-07-12 15:34:29 | INFO | Found `predict_domain` to be the GreatAI app \u001b[0m\n",
|
||||
"\u001b[38;5;39m2022-07-12 15:34:29 | INFO | Uvicorn running on http://0.0.0.0:6060 (Press CTRL+C to quit)\u001b[0m\n",
|
||||
"\u001b[38;5;226m2022-07-12 15:34:31 | WARNING | Environment variable ENVIRONMENT is not set, defaulting to development mode ‼️\u001b[0m\n",
|
||||
"\u001b[38;5;226m2022-07-12 15:34:31 | WARNING | Cannot find credentials files, defaulting to using ParallelTinyDbDriver\u001b[0m\n",
|
||||
"\u001b[38;5;226m2022-07-12 15:34:31 | WARNING | The selected tracing database (ParallelTinyDbDriver) is not recommended for production\u001b[0m\n",
|
||||
"\u001b[38;5;226m2022-07-12 15:34:31 | WARNING | Cannot find credentials files, defaulting to using LargeFileLocal\u001b[0m\n",
|
||||
"\u001b[38;5;39m2022-07-12 15:34:31 | INFO | GreatAI (v0.1.4): configured ✅\u001b[0m\n",
|
||||
"\u001b[38;5;39m2022-07-12 15:34:31 | INFO | 🔩 tracing_database: ParallelTinyDbDriver\u001b[0m\n",
|
||||
"\u001b[38;5;39m2022-07-12 15:34:31 | INFO | 🔩 large_file_implementation: LargeFileLocal\u001b[0m\n",
|
||||
"\u001b[38;5;39m2022-07-12 15:34:31 | INFO | 🔩 is_production: False\u001b[0m\n",
|
||||
"\u001b[38;5;39m2022-07-12 15:34:31 | INFO | 🔩 should_log_exception_stack: True\u001b[0m\n",
|
||||
"\u001b[38;5;39m2022-07-12 15:34:31 | INFO | 🔩 prediction_cache_size: 512\u001b[0m\n",
|
||||
"\u001b[38;5;39m2022-07-12 15:34:31 | INFO | 🔩 dashboard_table_size: 50\u001b[0m\n",
|
||||
"\u001b[38;5;226m2022-07-12 15:34:31 | WARNING | You still need to check whether you follow all best practices before trusting your deployment.\u001b[0m\n",
|
||||
"\u001b[38;5;226m2022-07-12 15:34:31 | WARNING | > Find out more at https://se-ml.github.io/practices\u001b[0m\n",
|
||||
"\u001b[38;5;39m2022-07-12 15:34:31 | INFO | Fetching cached versions of my-domain-predictor\u001b[0m\n",
|
||||
"\u001b[38;5;39m2022-07-12 15:34:31 | INFO | Latest version of my-domain-predictor is 9 (from versions: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)\u001b[0m\n",
|
||||
"\u001b[38;5;39m2022-07-12 15:34:31 | INFO | File my-domain-predictor-9 found in cache\u001b[0m\n",
|
||||
"\u001b[38;5;39m2022-07-12 15:34:31 | INFO | Started server process [199794]\u001b[0m\n",
|
||||
"\u001b[38;5;39m2022-07-12 15:34:31 | INFO | Waiting for application startup.\u001b[0m\n",
|
||||
"\u001b[38;5;39m2022-07-12 15:34:31 | INFO | Application startup complete.\u001b[0m\n",
|
||||
"^C\n",
|
||||
"\u001b[38;5;39m2022-07-12 15:34:33 | INFO | Shutting down\u001b[0m\n",
|
||||
"\u001b[38;5;39m2022-07-12 15:34:33 | INFO | Waiting for application shutdown.\u001b[0m\n",
|
||||
"\u001b[38;5;39m2022-07-12 15:34:33 | INFO | Application shutdown complete.\u001b[0m\n",
|
||||
"\u001b[38;5;39m2022-07-12 15:34:33 | INFO | Finished server process [199794]\u001b[0m\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!great-ai deploy.ipynb\n",
|
||||
"# leave this running and open http://127.0.0.1:6060"
|
||||
]
|
||||
"from fastapi.testclient import TestClient\n",
|
||||
"\n",
|
||||
"with TestClient(predict_domain.app) as client:\n",
|
||||
" response = client.post(\n",
|
||||
" \"/predict\", json={\"sentence\": \"Mountains are just big rocks.\"}\n",
|
||||
" )\n",
|
||||
" response.raise_for_status()\n",
|
||||
" assert isinstance(response.json()[\"output\"], str)\n",
|
||||
" print(response.json()[\"output\"])"
|
||||
],
|
||||
"id": "cell-6"
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
|
@ -146,34 +128,28 @@
|
|||
"For more thorough examples, see the [examples page](https://great-ai.scoutinscience.com/examples/simple/data).\n",
|
||||
"\n",
|
||||
"### [Go back to the summary](https://great-ai.scoutinscience.com/tutorial/#summary)"
|
||||
]
|
||||
],
|
||||
"id": "cell-7"
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3.10.4 ('.env': venv)",
|
||||
"display_name": "GreatAI (local)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
"name": "great-ai-local"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python",
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.4"
|
||||
},
|
||||
"orig_nbformat": 4,
|
||||
"vscode": {
|
||||
"interpreter": {
|
||||
"hash": "02dd6d3afbfa9fbbe1037d64ad9014965528a1ccad21929d6e72f466389a68ad"
|
||||
}
|
||||
"pygments_lexer": "ipython3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue