Skip to content

Commit 40f9333

Browse files
authored
add(notebooks): ml functions example and fix ai functions syntax (#145)
* add(notebooks): ml functions example and fix ai functions * update(resource): nb-check add printlogs * fix(notebook): kafka notebook cell id * fix(notebook): remove commented code
1 parent 5115606 commit 40f9333

File tree

6 files changed

+706
-51
lines changed

6 files changed

+706
-51
lines changed

notebooks/getting-started-with-ai-functions/meta.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ description="""\
88
icon="browser"
99
difficulty="beginner"
1010
tags=["advanced", "notebooks", "python"]
11-
lesson_areas=[]
11+
lesson_areas=["AI"]
1212
destinations=["spaces"]
1313
minimum_tier="standard"

notebooks/getting-started-with-ai-functions/notebook.ipynb

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
{
2020
"attachments": {},
2121
"cell_type": "markdown",
22+
"id": "5831c1ac",
2223
"metadata": {},
2324
"source": [
2425
"<div class=\"alert alert-block alert-warning\">\n",
@@ -38,23 +39,23 @@
3839
"3. Demonstrate powerful AI Functions for text processing and analysis\n",
3940
"\n",
4041
"**Prerequisites**: Ensure AI Functions are enabled on your deployment (AI Services > AI & ML Functions)."
41-
],
42-
"id": "5831c1ac"
42+
]
4343
},
4444
{
4545
"attachments": {},
4646
"cell_type": "markdown",
47+
"id": "ea429156",
4748
"metadata": {},
4849
"source": [
4950
"## Create some simple tables\n",
5051
"\n",
5152
"This setup establishes a basic relational structure to store some reviews for restaurants. Ensure you have selected a database and have CREATE permissions to create/delete tables."
52-
],
53-
"id": "ea429156"
53+
]
5454
},
5555
{
5656
"cell_type": "code",
5757
"execution_count": 1,
58+
"id": "1f8ccd75",
5859
"metadata": {},
5960
"outputs": [
6061
{
@@ -97,21 +98,21 @@
9798
" Summary TEXT,\n",
9899
" Text TEXT\n",
99100
");"
100-
],
101-
"id": "1f8ccd75"
101+
]
102102
},
103103
{
104104
"attachments": {},
105105
"cell_type": "markdown",
106+
"id": "6a2118dd",
106107
"metadata": {},
107108
"source": [
108109
"## Install the required packages"
109-
],
110-
"id": "6a2118dd"
110+
]
111111
},
112112
{
113113
"cell_type": "code",
114114
"execution_count": 2,
115+
"id": "40350277",
115116
"metadata": {},
116117
"outputs": [
117118
{
@@ -143,21 +144,21 @@
143144
],
144145
"source": [
145146
"!pip install kagglehub pandas"
146-
],
147-
"id": "40350277"
147+
]
148148
},
149149
{
150150
"attachments": {},
151151
"cell_type": "markdown",
152+
"id": "97437a79",
152153
"metadata": {},
153154
"source": [
154155
"## Download and Load Dataset"
155-
],
156-
"id": "97437a79"
156+
]
157157
},
158158
{
159159
"cell_type": "code",
160160
"execution_count": 3,
161+
"id": "cf62cc7e",
161162
"metadata": {},
162163
"outputs": [
163164
{
@@ -349,21 +350,21 @@
349350
"print(f\"Columns: {list(df.columns)}\")\n",
350351
"print(\"\\nFirst few rows:\")\n",
351352
"df.head()"
352-
],
353-
"id": "cf62cc7e"
353+
]
354354
},
355355
{
356356
"attachments": {},
357357
"cell_type": "markdown",
358+
"id": "0c938c99",
358359
"metadata": {},
359360
"source": [
360361
"## Load Data into SingleStore"
361-
],
362-
"id": "0c938c99"
362+
]
363363
},
364364
{
365365
"cell_type": "code",
366366
"execution_count": 4,
367+
"id": "4d427d08",
367368
"metadata": {},
368369
"outputs": [
369370
{
@@ -396,21 +397,21 @@
396397
")\n",
397398
"\n",
398399
"print(\"Data loaded successfully!\")"
399-
],
400-
"id": "4d427d08"
400+
]
401401
},
402402
{
403403
"attachments": {},
404404
"cell_type": "markdown",
405+
"id": "ee21f51b",
405406
"metadata": {},
406407
"source": [
407408
" ## Verify Data Load"
408-
],
409-
"id": "ee21f51b"
409+
]
410410
},
411411
{
412412
"cell_type": "code",
413413
"execution_count": 5,
414+
"id": "8423c269",
414415
"metadata": {},
415416
"outputs": [
416417
{
@@ -458,21 +459,21 @@
458459
"%%sql\n",
459460
"-- Check the number of reviews loaded\n",
460461
"SELECT COUNT(*) as total_reviews FROM reviews;"
461-
],
462-
"id": "8423c269"
462+
]
463463
},
464464
{
465465
"attachments": {},
466466
"cell_type": "markdown",
467+
"id": "d6c8e487",
467468
"metadata": {},
468469
"source": [
469470
"## Sample Data Preview"
470-
],
471-
"id": "d6c8e487"
471+
]
472472
},
473473
{
474474
"cell_type": "code",
475475
"execution_count": 6,
476+
"id": "ccefec53",
476477
"metadata": {},
477478
"outputs": [
478479
{
@@ -602,24 +603,24 @@
602603
"SELECT Id, ProductId, Score, Summary, LEFT(Text, 100) as Review_Preview\n",
603604
"FROM reviews\n",
604605
"LIMIT 10;"
605-
],
606-
"id": "ccefec53"
606+
]
607607
},
608608
{
609609
"attachments": {},
610610
"cell_type": "markdown",
611+
"id": "0bb3deb8",
611612
"metadata": {},
612613
"source": [
613614
"## AI Functions Demonstrations\n",
614615
"\n",
615616
"Now let's explore the power of SingleStore AI Functions for text analysis and processing.\n",
616617
"Ensure that AI functions are enabled for the org and you are able to list the available AI functions"
617-
],
618-
"id": "0bb3deb8"
618+
]
619619
},
620620
{
621621
"cell_type": "code",
622622
"execution_count": 7,
623+
"id": "bd293861",
623624
"metadata": {},
624625
"outputs": [
625626
{
@@ -769,12 +770,12 @@
769770
"%%sql\n",
770771
"USE cluster;\n",
771772
"SHOW functions;"
772-
],
773-
"id": "bd293861"
773+
]
774774
},
775775
{
776776
"cell_type": "code",
777777
"execution_count": 8,
778+
"id": "05d5d27a",
778779
"metadata": {},
779780
"outputs": [
780781
{
@@ -824,12 +825,12 @@
824825
"SELECT cluster.AI_COMPLETE(\n",
825826
" 'What is SingleStore?'\n",
826827
") AS completion;"
827-
],
828-
"id": "05d5d27a"
828+
]
829829
},
830830
{
831831
"cell_type": "code",
832832
"execution_count": 9,
833+
"id": "9f842a0d",
833834
"metadata": {},
834835
"outputs": [
835836
{
@@ -888,7 +889,7 @@
888889
"%%sql\n",
889890
"-- AI_SENTIMENT: Analyze sentiment of customer reviews for a specific product\n",
890891
"-- WHERE ProductId = <Your choice>\n",
891-
"-- Remember to specific the datbase name. In this example 'temp' is the Database name\n",
892+
"-- Remember to specify the datbase name. In this example 'temp' is the Database name\n",
892893
"SELECT\n",
893894
" Id,\n",
894895
" ProductId,\n",
@@ -898,12 +899,12 @@
898899
"FROM temp.reviews\n",
899900
"WHERE ProductId = 'B000NY8ODS'\n",
900901
"LIMIT 10;"
901-
],
902-
"id": "9f842a0d"
902+
]
903903
},
904904
{
905905
"cell_type": "code",
906906
"execution_count": 10,
907+
"id": "56ff7a17",
907908
"metadata": {},
908909
"outputs": [
909910
{
@@ -1015,12 +1016,12 @@
10151016
" review_count,\n",
10161017
" cluster.AI_SENTIMENT(combined_text) as overall_sentiment\n",
10171018
"FROM grouped_reviews;"
1018-
],
1019-
"id": "56ff7a17"
1019+
]
10201020
},
10211021
{
10221022
"cell_type": "code",
10231023
"execution_count": 11,
1024+
"id": "b9786b66",
10241025
"metadata": {},
10251026
"outputs": [
10261027
{
@@ -1122,12 +1123,12 @@
11221123
" 15\n",
11231124
" ) AS summary\n",
11241125
"FROM long_reviews;"
1125-
],
1126-
"id": "b9786b66"
1126+
]
11271127
},
11281128
{
11291129
"cell_type": "code",
11301130
"execution_count": 12,
1131+
"id": "4febc8e0",
11311132
"metadata": {},
11321133
"outputs": [
11331134
{
@@ -1263,12 +1264,12 @@
12631264
" '[quality, price, shipping, taste]'\n",
12641265
" ) AS classification\n",
12651266
"FROM negative_reviews;"
1266-
],
1267-
"id": "4febc8e0"
1267+
]
12681268
},
12691269
{
12701270
"cell_type": "code",
12711271
"execution_count": 13,
1272+
"id": "40f4cd14",
12721273
"metadata": {},
12731274
"outputs": [
12741275
{
@@ -1431,12 +1432,12 @@
14311432
" 'Does this customer indicate they will buy this product again? Answer with yes, no, or unclear only'\n",
14321433
" ) AS repeat_purchase_intent\n",
14331434
"FROM positive_reviews;"
1434-
],
1435-
"id": "40f4cd14"
1435+
]
14361436
},
14371437
{
14381438
"cell_type": "code",
14391439
"execution_count": 14,
1440+
"id": "a09f2d5b",
14401441
"metadata": {},
14411442
"outputs": [
14421443
{
@@ -1585,12 +1586,12 @@
15851586
" 'Is this customer at high risk of not purchasing again? Answer with high, medium, or low only'\n",
15861587
" ) AS churn_risk\n",
15871588
"FROM low_rated_reviews;"
1588-
],
1589-
"id": "a09f2d5b"
1589+
]
15901590
},
15911591
{
15921592
"cell_type": "code",
15931593
"execution_count": 15,
1594+
"id": "3d78f449",
15941595
"metadata": {},
15951596
"outputs": [
15961597
{
@@ -1685,12 +1686,12 @@
16851686
" 'spanish'\n",
16861687
" ) AS spanish_translation\n",
16871688
"FROM translatable_reviews;"
1688-
],
1689-
"id": "3d78f449"
1689+
]
16901690
},
16911691
{
16921692
"cell_type": "code",
16931693
"execution_count": 16,
1694+
"id": "082dc59a",
16941695
"metadata": {},
16951696
"outputs": [
16961697
{
@@ -1860,8 +1861,7 @@
18601861
" cluster.AI_CLASSIFY(Text, '[quality, value, taste, packaging]') as category,\n",
18611862
" cluster.AI_SUMMARIZE(Text, 'aifunctions_chat_default', 10) as brief_summary\n",
18621863
"FROM product_reviews;"
1863-
],
1864-
"id": "082dc59a"
1864+
]
18651865
},
18661866
{
18671867
"cell_type": "markdown",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[meta]
2+
authors=["bharath-swamy"]
3+
title="Demonstrate ML function Classify"
4+
description="""\
5+
Learn how to train an ML Classify \
6+
model and run it to predict the class of an input row.
7+
"""
8+
icon="browser"
9+
difficulty="beginner"
10+
tags=["advanced", "notebooks", "python"]
11+
lesson_areas=["AI"]
12+
destinations=["spaces"]
13+
minimum_tier="standard"

0 commit comments

Comments
 (0)