From 92fbccc4efd5f421ff4648f01b9cbc94db1f8d94 Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Thu, 16 May 2024 11:53:40 +0200 Subject: [PATCH 01/28] initial commit --- ai-ml/nl-to-sql/dataset/customers.csv | 51 + ai-ml/nl-to-sql/dataset/transactions.csv | 1001 +++++++++++++++++ .../01-postgres-cluster/my-cluster.yaml | 88 ++ ai-ml/nl-to-sql/manifests/02-tgi/tgi.yaml | 83 ++ ai-ml/nl-to-sql/manifests/02-tgi/tgi_.yaml | 86 ++ 5 files changed, 1309 insertions(+) create mode 100644 ai-ml/nl-to-sql/dataset/customers.csv create mode 100644 ai-ml/nl-to-sql/dataset/transactions.csv create mode 100644 ai-ml/nl-to-sql/manifests/01-postgres-cluster/my-cluster.yaml create mode 100644 ai-ml/nl-to-sql/manifests/02-tgi/tgi.yaml create mode 100644 ai-ml/nl-to-sql/manifests/02-tgi/tgi_.yaml diff --git a/ai-ml/nl-to-sql/dataset/customers.csv b/ai-ml/nl-to-sql/dataset/customers.csv new file mode 100644 index 0000000000..24fd309527 --- /dev/null +++ b/ai-ml/nl-to-sql/dataset/customers.csv @@ -0,0 +1,51 @@ +CustomerID,Name,Gender,Age +1,James,Male,34 +2,Patricia,Female,26 +3,Michael,Male,50 +4,Robert,Male,37 +5,John,Male,30 +6,Jennifer,Female,45 +7,William,Male,46 +8,David,Male,30 +9,Richard,Male,63 +10,Linda,Female,52 +11,Joseph,Male,23 +12,Thomas,Male,35 +13,Christopher,Male,22 +14,Charles,Male,64 +15,Elizabeth,Female,42 +16,Daniel,Male,19 +17,Barbara,Female,27 +18,Susan,Female,47 +19,Jessica,Female,62 +20,Matthew,Male,22 +21,Karen,Female,50 +22,Anthony,Male,18 +23,Sarah,Female,35 +24,Lisa,Female,49 +25,Nancy,Female,64 +26,Sandra,Female,28 +27,Betty,Female,38 +28,Ashley,Female,43 +29,Kimberly,Female,42 +30,Margaret,Female,39 +31,Mark,Male,44 +32,Steven,Male,30 +33,Donna,Female,50 +34,Michelle,Female,51 +35,Carol,Female,58 +36,Andrew,Male,52 +37,Melissa,Female,18 +38,Paul,Male,38 +39,Kevin,Male,23 +40,Brian,Male,45 +41,George,Male,34 +42,Jason,Male,22 +43,Rebecca,Female,48 +44,Sharon,Female,22 +45,Laura,Female,55 +46,Amy,Female,20 +47,Angela,Female,40 +48,Edward,Male,54 +49,Emma,Female,54 +50,Brenda,Female,27 \ No newline at end of file diff --git a/ai-ml/nl-to-sql/dataset/transactions.csv b/ai-ml/nl-to-sql/dataset/transactions.csv new file mode 100644 index 0000000000..91fe8552f7 --- /dev/null +++ b/ai-ml/nl-to-sql/dataset/transactions.csv @@ -0,0 +1,1001 @@ +TransactionID,Date,CustomerID,ProductCategory,Quantity,PricePerUnit,TotalAmount +1,2023-11-24,41,Beauty,3,50,150 +2,2023-02-27,21,Clothing,2,500,1000 +3,2023-01-13,19,Electronics,1,30,30 +4,2023-05-21,34,Clothing,1,500,500 +5,2023-05-06,38,Beauty,2,50,100 +6,2023-04-25,14,Beauty,1,30,30 +7,2023-03-13,22,Clothing,2,25,50 +8,2023-02-22,4,Electronics,4,25,100 +9,2023-12-13,22,Electronics,2,300,600 +10,2023-10-07,50,Clothing,4,50,200 +11,2023-02-14,12,Clothing,2,50,100 +12,2023-10-30,29,Beauty,3,25,75 +13,2023-08-05,36,Electronics,3,500,1500 +14,2023-01-17,41,Clothing,4,30,120 +15,2023-01-16,1,Electronics,4,500,2000 +16,2023-02-17,6,Clothing,3,500,1500 +17,2023-04-22,44,Clothing,4,25,100 +18,2023-04-30,6,Electronics,2,25,50 +19,2023-09-16,9,Clothing,2,25,50 +20,2023-11-05,1,Clothing,3,300,900 +21,2023-01-14,28,Beauty,1,500,500 +22,2023-10-15,2,Clothing,2,50,100 +23,2023-04-12,29,Clothing,4,30,120 +24,2023-11-29,22,Clothing,1,300,300 +25,2023-12-26,42,Beauty,1,50,50 +26,2023-10-07,22,Electronics,2,500,1000 +27,2023-08-03,10,Beauty,2,25,50 +28,2023-04-23,31,Beauty,1,500,500 +29,2023-08-18,11,Electronics,1,30,30 +30,2023-10-29,42,Beauty,3,300,900 +31,2023-05-23,37,Electronics,4,300,1200 +32,2023-01-04,42,Beauty,3,30,90 +33,2023-03-23,10,Electronics,2,50,100 +34,2023-12-24,28,Clothing,3,50,150 +35,2023-08-05,40,Beauty,3,300,900 +36,2023-06-24,28,Beauty,3,300,900 +37,2023-05-23,10,Beauty,3,25,75 +38,2023-03-21,42,Beauty,4,50,200 +39,2023-04-21,29,Clothing,4,30,120 +40,2023-06-22,6,Beauty,1,50,50 +41,2023-02-22,46,Clothing,2,25,50 +42,2023-02-17,39,Clothing,3,300,900 +43,2023-07-14,20,Clothing,1,300,300 +44,2023-02-19,37,Clothing,1,25,25 +45,2023-07-03,5,Electronics,1,30,30 +46,2023-06-26,12,Electronics,4,300,1200 +47,2023-11-06,12,Beauty,3,500,1500 +48,2023-05-16,41,Electronics,3,300,900 +49,2023-01-23,21,Electronics,2,500,1000 +50,2023-08-24,21,Beauty,3,25,75 +51,2023-10-02,10,Beauty,3,25,75 +52,2023-03-05,26,Beauty,1,300,300 +53,2023-07-13,3,Electronics,2,50,100 +54,2023-02-10,41,Electronics,3,500,1500 +55,2023-10-10,14,Beauty,4,30,120 +56,2023-05-31,32,Clothing,3,300,900 +57,2023-11-18,24,Beauty,1,30,30 +58,2023-11-13,44,Clothing,4,300,1200 +59,2023-07-05,1,Clothing,1,50,50 +60,2023-10-23,41,Beauty,3,50,150 +61,2023-04-09,1,Beauty,4,50,200 +62,2023-12-27,17,Beauty,2,50,100 +63,2023-02-05,25,Electronics,2,25,50 +64,2023-01-24,34,Clothing,4,25,100 +65,2023-12-05,48,Electronics,4,500,2000 +66,2023-04-27,21,Electronics,1,30,30 +67,2023-05-29,42,Beauty,4,300,1200 +68,2023-02-10,24,Electronics,1,300,300 +69,2023-04-30,33,Beauty,3,25,75 +70,2023-02-21,21,Clothing,1,300,300 +71,2023-07-14,37,Beauty,4,25,100 +72,2023-05-23,15,Electronics,4,500,2000 +73,2023-08-21,1,Electronics,3,30,90 +74,2023-11-22,50,Beauty,4,500,2000 +75,2023-07-06,44,Beauty,4,50,200 +76,2023-03-25,14,Electronics,2,50,100 +77,2023-07-09,28,Clothing,2,50,100 +78,2023-07-01,28,Clothing,3,500,1500 +79,2023-04-18,21,Beauty,1,300,300 +80,2023-12-10,14,Clothing,2,30,60 +81,2023-05-17,35,Electronics,1,50,50 +82,2023-12-26,7,Beauty,4,50,200 +83,2023-12-16,21,Electronics,2,50,100 +84,2023-11-28,37,Electronics,3,30,90 +85,2023-02-06,28,Clothing,3,50,150 +86,2023-11-08,47,Beauty,3,30,90 +87,2023-11-22,2,Beauty,2,50,100 +88,2023-03-29,15,Clothing,1,500,500 +89,2023-10-01,47,Electronics,4,500,2000 +90,2023-05-06,14,Electronics,1,30,30 +91,2023-03-25,45,Electronics,1,500,500 +92,2023-08-25,37,Electronics,4,30,120 +93,2023-07-14,33,Beauty,4,500,2000 +94,2023-05-19,10,Beauty,2,500,1000 +95,2023-11-24,17,Clothing,2,30,60 +96,2023-12-19,20,Clothing,2,300,600 +97,2023-10-13,20,Beauty,2,500,1000 +98,2023-04-23,4,Beauty,2,50,100 +99,2023-12-17,35,Electronics,4,300,1200 +100,2023-06-16,36,Electronics,1,30,30 +101,2023-01-29,39,Clothing,2,300,600 +102,2023-04-28,6,Beauty,2,25,50 +103,2023-01-17,46,Clothing,1,25,25 +104,2023-06-11,28,Beauty,2,500,1000 +105,2023-07-25,37,Electronics,1,500,500 +106,2023-05-18,46,Clothing,1,50,50 +107,2023-02-03,44,Clothing,4,300,1200 +108,2023-04-19,39,Beauty,3,25,75 +109,2023-10-18,21,Electronics,4,500,2000 +110,2023-06-11,15,Clothing,3,300,900 +111,2023-04-19,11,Electronics,3,500,1500 +112,2023-12-02,23,Clothing,3,500,1500 +113,2023-09-13,11,Electronics,2,25,50 +114,2023-07-22,17,Beauty,4,25,100 +115,2023-11-26,39,Clothing,3,500,1500 +116,2023-08-23,48,Clothing,1,30,30 +117,2023-03-15,41,Electronics,2,500,1000 +118,2023-05-16,44,Electronics,4,500,2000 +119,2023-03-13,23,Clothing,3,50,150 +120,2023-05-07,37,Beauty,1,50,50 +121,2023-10-15,30,Electronics,4,50,200 +122,2023-10-03,11,Electronics,4,30,120 +123,2023-05-15,1,Electronics,2,30,60 +124,2023-10-27,37,Clothing,4,500,2000 +125,2023-08-08,10,Clothing,2,50,100 +126,2023-10-26,4,Clothing,3,30,90 +127,2023-07-24,26,Clothing,2,25,50 +128,2023-07-05,22,Beauty,1,500,500 +129,2023-04-23,1,Beauty,2,300,600 +130,2023-03-12,39,Clothing,1,500,500 +131,2023-09-18,27,Beauty,2,300,600 +132,2023-09-10,10,Electronics,4,50,200 +133,2023-02-16,15,Electronics,3,300,900 +134,2023-01-25,6,Electronics,1,50,50 +135,2023-02-26,22,Clothing,2,25,50 +136,2023-03-20,48,Electronics,2,300,600 +137,2023-11-18,50,Beauty,2,500,1000 +138,2023-03-23,7,Clothing,4,50,200 +139,2023-12-15,33,Beauty,4,500,2000 +140,2023-08-05,34,Electronics,1,30,30 +141,2023-11-02,8,Electronics,1,50,50 +142,2023-02-02,30,Electronics,4,300,1200 +143,2023-07-17,32,Clothing,1,50,50 +144,2023-07-15,41,Beauty,3,500,1500 +145,2023-11-02,46,Clothing,3,25,75 +146,2023-08-28,29,Clothing,4,50,200 +147,2023-09-28,16,Electronics,1,300,300 +148,2023-05-09,42,Clothing,2,30,60 +149,2023-10-11,5,Clothing,3,25,75 +150,2023-01-06,38,Electronics,4,30,120 +151,2023-12-15,45,Clothing,1,50,50 +152,2023-02-28,30,Electronics,4,500,2000 +153,2023-12-16,37,Electronics,2,500,1000 +154,2023-10-02,45,Electronics,3,300,900 +155,2023-05-17,42,Electronics,4,500,2000 +156,2023-11-25,8,Clothing,4,25,100 +157,2023-06-24,47,Electronics,4,500,2000 +158,2023-02-27,41,Electronics,2,300,600 +159,2023-05-31,5,Clothing,4,50,200 +160,2023-08-11,6,Clothing,2,50,100 +161,2023-03-22,22,Beauty,2,500,1000 +162,2023-08-21,22,Clothing,2,30,60 +163,2023-01-02,49,Clothing,3,50,150 +164,2023-05-15,35,Beauty,3,500,1500 +165,2023-09-14,10,Clothing,4,300,1200 +166,2023-04-02,32,Clothing,4,500,2000 +167,2023-09-17,8,Clothing,3,50,150 +168,2023-02-24,44,Clothing,1,300,300 +169,2023-11-17,46,Beauty,3,500,1500 +170,2023-06-02,48,Clothing,2,25,50 +171,2023-11-24,8,Clothing,3,300,900 +172,2023-09-17,18,Beauty,2,25,50 +173,2023-11-08,46,Electronics,4,30,120 +174,2023-04-12,1,Beauty,1,300,300 +175,2023-03-20,18,Electronics,4,25,100 +176,2023-07-11,2,Beauty,2,50,100 +177,2023-03-24,46,Beauty,2,50,100 +178,2023-10-04,5,Clothing,2,30,60 +179,2023-09-29,7,Electronics,1,300,300 +180,2023-01-01,5,Clothing,3,300,900 +181,2023-11-03,50,Electronics,4,300,1200 +182,2023-06-15,44,Beauty,4,30,120 +183,2023-09-08,13,Beauty,3,300,900 +184,2023-01-10,27,Electronics,4,50,200 +185,2023-02-27,22,Clothing,1,25,25 +186,2023-07-05,7,Clothing,4,50,200 +187,2023-06-07,17,Clothing,2,50,100 +188,2023-05-03,45,Clothing,3,25,75 +189,2023-01-30,25,Beauty,1,50,50 +190,2023-05-04,35,Beauty,3,30,90 +191,2023-10-18,5,Beauty,1,25,25 +192,2023-02-10,14,Beauty,2,50,100 +193,2023-02-13,34,Beauty,3,500,1500 +194,2023-09-06,24,Clothing,4,50,200 +195,2023-02-05,36,Clothing,1,30,30 +196,2023-09-30,9,Clothing,3,300,900 +197,2023-03-06,9,Clothing,4,50,200 +198,2023-03-07,3,Beauty,3,300,900 +199,2023-12-04,39,Beauty,3,500,1500 +200,2023-09-01,12,Beauty,3,50,150 +201,2023-10-09,18,Electronics,1,25,25 +202,2023-03-26,2,Clothing,4,300,1200 +203,2023-05-16,3,Clothing,2,500,1000 +204,2023-09-28,9,Beauty,1,25,25 +205,2023-11-07,5,Clothing,1,25,25 +206,2023-08-05,27,Clothing,1,25,25 +207,2023-04-19,23,Beauty,2,25,50 +208,2023-10-04,9,Electronics,4,50,200 +209,2023-12-20,13,Electronics,4,50,200 +210,2023-04-13,13,Electronics,4,50,200 +211,2024-01-01,38,Beauty,3,500,1500 +212,2023-06-09,31,Clothing,3,500,1500 +213,2023-07-24,19,Beauty,3,500,1500 +214,2023-12-10,34,Beauty,2,30,60 +215,2023-11-29,48,Clothing,3,500,1500 +216,2023-07-11,6,Electronics,2,50,100 +217,2023-08-13,40,Electronics,4,50,200 +218,2023-09-22,32,Beauty,3,30,90 +219,2023-08-20,33,Electronics,3,30,90 +220,2023-03-03,12,Beauty,1,500,500 +221,2023-05-07,5,Beauty,2,300,600 +222,2023-04-26,9,Clothing,4,30,120 +223,2023-02-02,31,Clothing,1,25,25 +224,2023-06-23,41,Clothing,1,50,50 +225,2023-01-11,28,Beauty,4,25,100 +226,2023-10-29,45,Clothing,1,50,50 +227,2023-10-11,25,Electronics,2,50,100 +228,2023-04-28,23,Electronics,2,30,60 +229,2023-10-29,7,Beauty,3,30,90 +230,2023-04-23,28,Beauty,1,25,25 +231,2023-01-04,21,Clothing,3,50,150 +232,2023-02-06,1,Beauty,1,25,25 +233,2023-12-29,37,Beauty,2,300,600 +234,2023-11-20,11,Electronics,2,25,50 +235,2023-01-31,49,Electronics,2,500,1000 +236,2023-04-28,4,Clothing,1,25,25 +237,2023-02-04,21,Beauty,2,500,1000 +238,2023-01-17,41,Beauty,1,500,500 +239,2023-06-19,13,Electronics,3,500,1500 +240,2023-02-06,1,Beauty,1,300,300 +241,2023-09-21,1,Electronics,3,25,75 +242,2023-05-02,12,Clothing,1,25,25 +243,2023-05-23,35,Electronics,3,300,900 +244,2023-12-09,29,Beauty,2,50,100 +245,2023-09-06,35,Clothing,3,30,90 +246,2023-04-20,33,Electronics,2,25,50 +247,2023-10-04,2,Electronics,2,30,60 +248,2023-03-09,47,Clothing,3,300,900 +249,2023-10-20,16,Clothing,1,50,50 +250,2023-10-23,21,Electronics,1,50,50 +251,2023-08-31,2,Beauty,4,50,200 +252,2023-05-05,42,Electronics,1,300,300 +253,2023-08-31,9,Clothing,4,500,2000 +254,2023-07-28,37,Electronics,1,500,500 +255,2023-04-08,25,Clothing,1,30,30 +256,2023-02-18,40,Clothing,2,500,1000 +257,2023-02-19,27,Beauty,4,500,2000 +258,2023-12-04,25,Clothing,1,50,50 +259,2023-08-09,13,Clothing,4,50,200 +260,2023-07-01,2,Beauty,2,30,60 +261,2023-08-05,10,Clothing,2,25,50 +262,2023-07-30,32,Beauty,4,30,120 +263,2023-08-28,22,Beauty,2,30,60 +264,2023-01-28,4,Clothing,3,300,900 +265,2023-12-11,4,Clothing,3,300,900 +266,2023-12-01,33,Electronics,2,30,60 +267,2023-11-27,1,Beauty,3,30,90 +268,2023-02-20,6,Electronics,1,30,30 +269,2023-02-01,50,Clothing,4,500,2000 +270,2023-07-26,35,Electronics,1,300,300 +271,2023-06-23,28,Beauty,4,30,120 +272,2023-02-25,34,Electronics,2,50,100 +273,2023-05-08,37,Beauty,1,50,50 +274,2023-04-09,44,Clothing,2,500,1000 +275,2023-04-08,10,Clothing,2,500,1000 +276,2023-10-02,5,Beauty,4,25,100 +277,2023-08-18,27,Clothing,4,25,100 +278,2023-03-13,43,Clothing,4,25,100 +279,2023-08-05,36,Clothing,1,500,500 +280,2023-04-04,5,Clothing,3,500,1500 +281,2023-05-23,30,Beauty,4,500,2000 +282,2023-08-25,31,Electronics,4,50,200 +283,2023-05-08,45,Electronics,1,500,500 +284,2023-02-08,9,Clothing,4,50,200 +285,2023-08-15,12,Electronics,1,25,25 +286,2023-10-09,3,Electronics,2,25,50 +287,2023-02-20,2,Clothing,4,25,100 +288,2023-01-26,28,Clothing,4,30,120 +289,2023-11-30,33,Electronics,2,30,60 +290,2023-10-04,26,Beauty,2,300,600 +291,2023-01-08,32,Clothing,2,300,600 +292,2023-02-17,14,Beauty,4,300,1200 +293,2023-05-02,39,Electronics,3,30,90 +294,2023-03-27,9,Clothing,3,30,90 +295,2023-07-28,31,Beauty,3,300,900 +296,2023-09-06,7,Clothing,4,300,1200 +297,2023-09-04,13,Electronics,2,500,1000 +298,2023-04-20,9,Beauty,4,300,1200 +299,2023-07-25,24,Electronics,2,500,1000 +300,2023-01-31,25,Electronics,4,50,200 +301,2023-03-26,47,Clothing,4,30,120 +302,2023-07-14,1,Beauty,2,300,600 +303,2023-01-02,46,Electronics,3,30,90 +304,2023-07-19,19,Electronics,2,30,60 +305,2023-05-16,48,Beauty,1,30,30 +306,2023-08-21,50,Electronics,1,50,50 +307,2023-05-27,20,Electronics,2,25,50 +308,2023-08-05,45,Beauty,4,300,1200 +309,2023-12-23,12,Beauty,1,25,25 +310,2023-10-12,14,Beauty,1,25,25 +311,2023-12-05,6,Beauty,4,25,100 +312,2023-09-07,42,Clothing,4,30,120 +313,2023-03-21,11,Beauty,3,500,1500 +314,2023-04-08,20,Clothing,4,30,120 +315,2023-06-01,8,Clothing,2,30,60 +316,2023-04-22,2,Clothing,2,25,50 +317,2023-01-30,43,Electronics,3,30,90 +318,2023-10-24,21,Clothing,1,25,25 +319,2023-10-05,1,Clothing,1,500,500 +320,2023-02-01,15,Electronics,4,300,1200 +321,2023-06-10,34,Electronics,2,25,50 +322,2023-01-30,19,Electronics,1,500,500 +323,2023-01-26,29,Beauty,3,300,900 +324,2023-10-27,38,Electronics,3,50,150 +325,2023-09-02,49,Electronics,2,25,50 +326,2023-09-15,32,Clothing,3,25,75 +327,2023-09-29,20,Electronics,3,50,150 +328,2023-03-22,8,Beauty,2,50,100 +329,2023-01-30,29,Electronics,4,25,100 +330,2023-09-18,45,Beauty,4,50,200 +331,2023-02-11,44,Electronics,3,30,90 +332,2023-04-06,41,Electronics,4,300,1200 +333,2023-02-05,46,Electronics,4,300,1200 +334,2023-11-01,33,Electronics,3,300,900 +335,2023-02-04,21,Beauty,4,30,120 +336,2023-12-12,35,Beauty,3,50,150 +337,2023-05-01,7,Clothing,1,500,500 +338,2023-07-26,34,Beauty,2,50,100 +339,2023-03-03,29,Electronics,2,25,50 +340,2023-10-19,16,Clothing,4,300,1200 +341,2023-05-07,4,Clothing,4,50,200 +342,2023-10-24,46,Clothing,4,500,2000 +343,2023-11-01,9,Electronics,2,25,50 +344,2023-01-21,20,Beauty,1,30,30 +345,2023-11-14,45,Electronics,1,30,30 +346,2023-02-11,15,Clothing,2,500,1000 +347,2023-08-03,49,Electronics,1,25,25 +348,2023-12-03,17,Electronics,2,300,600 +349,2023-10-26,2,Beauty,1,50,50 +350,2023-10-17,15,Beauty,3,25,75 +351,2023-09-25,3,Clothing,3,30,90 +352,2023-06-11,37,Electronics,2,500,1000 +353,2023-05-14,36,Electronics,1,500,500 +354,2023-04-15,39,Beauty,4,50,200 +355,2023-12-09,15,Electronics,1,500,500 +356,2023-06-10,45,Electronics,3,500,1500 +357,2023-05-03,14,Electronics,3,25,75 +358,2023-05-16,23,Beauty,1,300,300 +359,2023-07-22,26,Clothing,1,50,50 +360,2023-03-09,40,Clothing,4,25,100 +361,2023-12-10,31,Electronics,4,300,1200 +362,2023-11-27,5,Clothing,1,25,25 +363,2023-06-03,9,Beauty,1,25,25 +364,2023-08-23,17,Beauty,1,500,500 +365,2023-06-11,10,Clothing,1,300,300 +366,2023-02-07,35,Clothing,2,50,100 +367,2023-01-05,26,Electronics,1,50,50 +368,2023-08-23,38,Clothing,4,300,1200 +369,2023-11-15,35,Electronics,3,500,1500 +370,2023-10-16,1,Electronics,2,30,60 +371,2023-02-21,36,Beauty,1,25,25 +372,2023-02-07,29,Beauty,3,500,1500 +373,2023-10-03,22,Beauty,2,300,600 +374,2023-04-20,34,Beauty,3,25,75 +375,2023-09-17,44,Clothing,1,50,50 +376,2023-05-16,15,Beauty,1,30,30 +377,2023-03-09,1,Clothing,4,50,200 +378,2023-06-28,30,Beauty,1,300,300 +379,2023-02-05,26,Clothing,1,25,25 +380,2023-05-06,10,Electronics,2,300,600 +381,2023-07-09,42,Clothing,4,25,100 +382,2023-05-26,15,Clothing,2,500,1000 +383,2023-03-22,50,Beauty,3,30,90 +384,2023-08-13,5,Clothing,1,500,500 +385,2023-10-06,45,Electronics,3,500,1500 +386,2023-12-27,49,Electronics,2,300,600 +387,2023-06-04,26,Beauty,1,30,30 +388,2023-11-10,45,Electronics,1,25,25 +389,2023-12-01,17,Clothing,2,25,50 +390,2023-09-28,42,Electronics,2,50,100 +391,2023-01-05,42,Beauty,2,25,50 +392,2023-12-08,10,Clothing,2,300,600 +393,2023-10-11,8,Beauty,2,500,1000 +394,2023-06-03,15,Clothing,1,500,500 +395,2023-12-06,15,Electronics,2,500,1000 +396,2023-02-23,42,Beauty,1,30,30 +397,2023-03-10,38,Beauty,1,25,25 +398,2023-05-16,3,Clothing,2,300,600 +399,2023-03-01,12,Beauty,2,30,60 +400,2023-02-24,46,Clothing,4,50,200 +401,2023-10-11,21,Clothing,1,300,300 +402,2023-03-21,3,Clothing,2,300,600 +403,2023-05-20,15,Clothing,2,300,600 +404,2023-05-25,17,Electronics,2,500,1000 +405,2023-11-06,16,Clothing,4,300,1200 +406,2023-04-18,39,Beauty,4,25,100 +407,2023-06-25,39,Electronics,3,300,900 +408,2023-04-15,32,Beauty,1,500,500 +409,2023-12-18,8,Electronics,3,300,900 +410,2023-11-21,9,Clothing,2,50,100 +411,2023-05-16,6,Electronics,4,50,200 +412,2023-09-16,14,Electronics,4,500,2000 +413,2023-09-08,5,Beauty,3,25,75 +414,2023-05-09,17,Beauty,4,25,100 +415,2023-01-27,42,Clothing,2,30,60 +416,2023-02-17,18,Electronics,4,500,2000 +417,2023-11-21,14,Electronics,3,300,900 +418,2023-08-05,16,Electronics,2,500,1000 +419,2023-05-22,39,Clothing,3,30,90 +420,2023-01-23,37,Clothing,4,500,2000 +421,2023-01-02,10,Clothing,3,500,1500 +422,2023-06-20,35,Clothing,3,30,90 +423,2023-03-08,23,Clothing,1,25,25 +424,2023-11-23,4,Beauty,4,300,1200 +425,2023-05-15,28,Electronics,4,30,120 +426,2023-03-24,33,Electronics,3,50,150 +427,2023-08-15,43,Electronics,1,25,25 +428,2023-10-10,26,Electronics,4,50,200 +429,2023-12-28,43,Electronics,2,25,50 +430,2023-08-07,9,Electronics,3,300,900 +431,2023-10-15,25,Electronics,4,300,1200 +432,2023-01-05,31,Electronics,2,500,1000 +433,2023-02-27,1,Beauty,4,50,200 +434,2023-02-08,47,Electronics,2,25,50 +435,2023-12-20,22,Beauty,3,300,900 +436,2023-03-18,17,Clothing,4,30,120 +437,2023-10-07,6,Electronics,4,300,1200 +438,2023-01-19,16,Clothing,1,30,30 +439,2023-07-09,30,Clothing,3,25,75 +440,2023-10-26,39,Clothing,2,300,600 +441,2023-10-10,4,Beauty,4,300,1200 +442,2023-03-17,20,Clothing,4,25,100 +443,2023-08-09,34,Clothing,2,300,600 +444,2023-03-07,16,Clothing,3,30,90 +445,2023-01-22,31,Electronics,1,300,300 +446,2023-06-07,47,Electronics,1,50,50 +447,2023-07-06,31,Beauty,4,500,2000 +448,2023-01-21,31,Beauty,2,30,60 +449,2023-07-03,11,Electronics,4,50,200 +450,2023-04-18,4,Beauty,2,25,50 +451,2023-12-16,14,Electronics,1,30,30 +452,2023-05-08,37,Clothing,3,500,1500 +453,2023-12-08,32,Clothing,2,500,1000 +454,2023-02-22,40,Beauty,1,25,25 +455,2023-07-01,4,Electronics,4,25,100 +456,2023-10-14,50,Electronics,2,30,60 +457,2023-07-28,16,Beauty,3,300,900 +458,2023-11-14,30,Electronics,4,25,100 +459,2023-03-21,7,Clothing,4,300,1200 +460,2023-05-02,7,Beauty,1,50,50 +461,2023-03-25,33,Beauty,2,500,1000 +462,2023-04-01,8,Electronics,4,300,1200 +463,2023-07-31,41,Beauty,3,500,1500 +464,2023-01-13,21,Electronics,2,300,600 +465,2023-04-02,3,Electronics,3,50,150 +466,2023-06-20,16,Electronics,4,25,100 +467,2023-07-30,4,Electronics,3,50,150 +468,2023-12-09,26,Electronics,1,25,25 +469,2023-05-08,34,Beauty,3,25,75 +470,2023-05-17,7,Clothing,2,500,1000 +471,2023-03-23,16,Clothing,3,50,150 +472,2023-12-26,16,Beauty,3,300,900 +473,2023-02-25,46,Beauty,1,50,50 +474,2023-07-15,21,Clothing,3,500,1500 +475,2023-01-20,11,Clothing,3,25,75 +476,2023-08-29,49,Clothing,4,500,2000 +477,2023-04-24,19,Clothing,4,30,120 +478,2023-04-13,49,Clothing,2,30,60 +479,2023-08-24,41,Electronics,4,300,1200 +480,2023-06-29,2,Beauty,4,500,2000 +481,2023-06-06,37,Electronics,4,300,1200 +482,2023-04-27,25,Clothing,4,300,1200 +483,2023-04-25,34,Clothing,1,30,30 +484,2023-01-13,49,Clothing,4,300,1200 +485,2023-12-04,41,Electronics,1,30,30 +486,2023-04-09,15,Electronics,1,25,25 +487,2023-07-24,23,Clothing,4,500,2000 +488,2023-06-18,42,Electronics,3,300,900 +489,2023-05-23,39,Electronics,1,30,30 +490,2023-02-05,33,Clothing,3,50,150 +491,2023-05-23,21,Electronics,3,300,900 +492,2023-06-29,25,Beauty,4,25,100 +493,2023-11-25,7,Beauty,2,25,50 +494,2023-09-18,42,Beauty,4,50,200 +495,2023-07-24,12,Beauty,2,30,60 +496,2023-12-14,20,Clothing,2,300,600 +497,2023-10-02,48,Clothing,4,30,120 +498,2023-06-19,4,Clothing,4,25,100 +499,2023-01-15,33,Beauty,2,30,60 +500,2023-03-01,11,Beauty,4,25,100 +501,2023-05-14,23,Electronics,2,30,60 +502,2023-04-02,43,Electronics,3,50,150 +503,2023-10-25,17,Beauty,4,500,2000 +504,2023-05-16,10,Beauty,3,50,150 +505,2023-01-20,28,Beauty,1,50,50 +506,2023-02-25,33,Beauty,3,500,1500 +507,2023-11-02,42,Electronics,3,500,1500 +508,2023-08-11,44,Beauty,2,300,600 +509,2023-06-26,11,Electronics,3,300,900 +510,2023-06-10,27,Beauty,4,50,200 +511,2023-08-12,41,Beauty,2,50,100 +512,2023-11-07,27,Beauty,1,25,25 +513,2023-09-19,15,Electronics,4,25,100 +514,2023-03-01,3,Electronics,1,300,300 +515,2023-07-17,16,Clothing,3,300,900 +516,2023-10-23,20,Beauty,4,25,100 +517,2023-04-08,11,Clothing,4,25,100 +518,2023-05-11,19,Clothing,1,30,30 +519,2023-01-23,22,Electronics,4,30,120 +520,2023-12-29,33,Electronics,4,25,100 +521,2023-08-12,13,Clothing,4,30,120 +522,2023-01-01,27,Beauty,3,500,1500 +523,2023-09-24,19,Electronics,1,300,300 +524,2023-10-03,6,Beauty,4,300,1200 +525,2023-12-18,20,Beauty,2,25,50 +526,2023-12-10,27,Clothing,2,50,100 +527,2023-04-11,23,Clothing,2,25,50 +528,2023-07-06,39,Clothing,2,30,60 +529,2023-08-09,25,Clothing,3,50,150 +530,2023-02-05,12,Electronics,4,30,120 +531,2023-12-07,43,Electronics,1,500,500 +532,2023-06-19,32,Clothing,4,30,120 +533,2023-11-16,10,Electronics,3,500,1500 +534,2023-06-10,12,Clothing,2,500,1000 +535,2023-12-06,44,Beauty,3,30,90 +536,2023-03-05,5,Beauty,4,30,120 +537,2023-06-03,14,Beauty,1,500,500 +538,2023-09-17,27,Clothing,3,50,150 +539,2023-06-08,39,Beauty,1,500,500 +540,2023-12-08,48,Electronics,3,300,900 +541,2023-07-29,29,Beauty,1,500,500 +542,2023-06-17,50,Beauty,1,50,50 +543,2023-07-26,36,Beauty,2,300,600 +544,2023-12-23,14,Electronics,1,25,25 +545,2023-06-01,39,Clothing,2,25,50 +546,2023-10-11,5,Electronics,4,50,200 +547,2023-03-07,37,Clothing,4,500,2000 +548,2023-04-09,38,Clothing,2,30,60 +549,2023-08-04,33,Beauty,2,50,100 +550,2023-12-07,13,Clothing,3,300,900 +551,2023-07-14,47,Electronics,3,300,900 +552,2023-12-13,36,Electronics,3,25,75 +553,2023-03-31,15,Clothing,4,300,1200 +554,2023-11-12,31,Beauty,3,50,150 +555,2023-10-19,45,Beauty,1,300,300 +556,2023-06-04,12,Electronics,1,50,50 +557,2023-07-27,2,Beauty,3,30,90 +558,2023-10-08,33,Clothing,1,25,25 +559,2023-01-01,11,Clothing,4,300,1200 +560,2023-06-05,34,Electronics,1,50,50 +561,2023-05-27,12,Clothing,4,500,2000 +562,2023-04-18,6,Electronics,2,25,50 +563,2023-08-09,33,Clothing,2,30,60 +564,2023-10-24,36,Electronics,2,50,100 +565,2023-11-07,23,Beauty,2,30,60 +566,2023-12-02,39,Clothing,1,30,30 +567,2023-06-14,42,Clothing,3,300,900 +568,2023-08-27,6,Electronics,1,300,300 +569,2023-08-15,38,Electronics,4,50,200 +570,2023-08-15,22,Clothing,1,500,500 +571,2023-12-12,39,Electronics,1,50,50 +572,2023-04-20,50,Clothing,4,500,2000 +573,2023-09-19,32,Beauty,2,30,60 +574,2023-08-31,28,Electronics,2,25,50 +575,2023-03-28,16,Clothing,2,50,100 +576,2023-12-04,48,Beauty,3,50,150 +577,2023-02-13,38,Beauty,4,500,2000 +578,2023-05-26,27,Clothing,4,30,120 +579,2023-09-21,13,Electronics,1,30,30 +580,2023-12-06,4,Clothing,3,500,1500 +581,2023-11-21,41,Beauty,2,30,60 +582,2023-11-14,22,Clothing,3,300,900 +583,2023-06-21,12,Electronics,4,25,100 +584,2023-02-17,38,Beauty,4,50,200 +585,2023-05-01,11,Clothing,1,25,25 +586,2023-12-11,21,Electronics,1,50,50 +587,2023-06-08,1,Beauty,4,300,1200 +588,2023-04-26,45,Electronics,2,30,60 +589,2023-04-12,43,Beauty,2,500,1000 +590,2023-03-17,39,Clothing,3,300,900 +591,2023-01-13,46,Electronics,4,25,100 +592,2023-01-24,16,Beauty,4,500,2000 +593,2023-05-06,27,Electronics,2,30,60 +594,2023-09-01,39,Electronics,2,300,600 +595,2023-11-09,34,Clothing,4,500,2000 +596,2023-02-07,1,Electronics,1,300,300 +597,2023-08-22,44,Beauty,4,300,1200 +598,2023-08-01,25,Beauty,4,30,120 +599,2023-11-19,32,Beauty,2,50,100 +600,2023-10-22,38,Beauty,2,500,1000 +601,2023-04-10,10,Clothing,1,30,30 +602,2023-12-23,1,Electronics,1,300,300 +603,2023-07-16,39,Clothing,3,30,90 +604,2023-09-11,23,Electronics,4,50,200 +605,2023-07-24,30,Electronics,2,500,1000 +606,2023-05-05,39,Electronics,1,50,50 +607,2023-03-17,21,Clothing,3,25,75 +608,2023-12-02,30,Electronics,3,500,1500 +609,2023-12-19,44,Clothing,2,50,100 +610,2023-01-03,1,Beauty,2,300,600 +611,2023-02-24,46,Beauty,3,500,1500 +612,2023-08-06,15,Electronics,1,500,500 +613,2023-04-23,39,Clothing,3,30,90 +614,2023-04-01,50,Beauty,4,300,1200 +615,2023-12-23,36,Clothing,4,25,100 +616,2023-09-23,24,Clothing,2,50,100 +617,2023-08-26,47,Electronics,1,30,30 +618,2023-01-26,26,Beauty,1,50,50 +619,2023-10-13,12,Electronics,4,25,100 +620,2023-05-08,25,Electronics,3,25,75 +621,2023-03-04,42,Beauty,2,500,1000 +622,2023-08-22,45,Beauty,3,25,75 +623,2023-03-10,34,Clothing,3,50,150 +624,2023-08-26,16,Beauty,3,300,900 +625,2023-12-08,29,Clothing,1,300,300 +626,2023-09-29,35,Clothing,4,500,2000 +627,2023-10-14,38,Clothing,1,50,50 +628,2023-11-01,1,Beauty,4,50,200 +629,2023-06-12,13,Electronics,2,25,50 +630,2023-08-15,5,Clothing,2,50,100 +631,2023-11-10,26,Electronics,3,30,90 +632,2023-09-16,48,Electronics,4,25,100 +633,2023-08-07,35,Beauty,4,30,120 +634,2023-10-08,32,Electronics,4,500,2000 +635,2023-08-17,35,Electronics,3,300,900 +636,2023-03-23,27,Beauty,3,500,1500 +637,2023-09-01,12,Clothing,2,300,600 +638,2023-08-19,24,Electronics,1,500,500 +639,2023-05-13,18,Beauty,4,50,200 +640,2023-05-07,27,Electronics,4,30,120 +641,2023-11-23,35,Electronics,1,300,300 +642,2023-05-22,4,Clothing,4,25,100 +643,2023-09-24,38,Electronics,3,30,90 +644,2023-09-06,6,Beauty,3,25,75 +645,2023-11-17,47,Electronics,4,30,120 +646,2023-05-03,26,Clothing,3,30,90 +647,2023-05-21,28,Clothing,3,500,1500 +648,2023-08-14,21,Beauty,4,300,1200 +649,2023-02-09,47,Clothing,2,300,600 +650,2024-01-01,37,Electronics,1,30,30 +651,2023-05-27,49,Clothing,3,50,150 +652,2023-05-01,20,Beauty,2,50,100 +653,2023-05-20,16,Clothing,3,25,75 +654,2023-06-21,50,Clothing,3,25,75 +655,2023-06-13,13,Clothing,1,500,500 +656,2023-10-04,14,Beauty,3,30,90 +657,2023-02-11,38,Clothing,1,25,25 +658,2023-03-12,34,Clothing,1,25,25 +659,2023-03-19,35,Electronics,1,30,30 +660,2023-04-29,34,Beauty,2,500,1000 +661,2023-07-16,8,Clothing,4,25,100 +662,2023-12-22,9,Beauty,2,500,1000 +663,2023-03-20,46,Clothing,4,300,1200 +664,2023-12-28,29,Clothing,4,500,2000 +665,2023-04-20,50,Clothing,1,50,50 +666,2023-02-02,3,Electronics,3,50,150 +667,2023-08-01,31,Electronics,1,500,500 +668,2023-07-28,28,Electronics,3,50,150 +669,2023-06-19,41,Beauty,4,300,1200 +670,2023-10-05,49,Beauty,1,30,30 +671,2023-08-27,41,Electronics,3,50,150 +672,2023-08-01,32,Beauty,2,50,100 +673,2023-02-01,29,Clothing,3,500,1500 +674,2023-04-16,42,Clothing,1,300,300 +675,2023-08-04,7,Clothing,2,30,60 +676,2023-07-19,7,Electronics,3,500,1500 +677,2023-10-27,11,Beauty,3,500,1500 +678,2023-12-23,43,Electronics,3,300,900 +679,2023-01-11,47,Beauty,3,30,90 +680,2023-10-22,47,Clothing,3,300,900 +681,2023-07-14,34,Electronics,2,30,60 +682,2023-09-02,19,Beauty,4,300,1200 +683,2023-01-04,16,Beauty,2,500,1000 +684,2023-06-30,47,Clothing,2,500,1000 +685,2023-06-02,25,Electronics,2,25,50 +686,2023-07-19,40,Electronics,4,50,200 +687,2023-08-03,35,Electronics,1,300,300 +688,2023-10-03,33,Clothing,4,25,100 +689,2023-10-07,14,Electronics,2,50,100 +690,2023-11-05,5,Clothing,3,300,900 +691,2023-04-23,18,Clothing,3,30,90 +692,2023-09-07,5,Clothing,2,50,100 +693,2023-04-23,31,Beauty,3,500,1500 +694,2023-05-20,48,Electronics,2,25,50 +695,2023-08-12,13,Electronics,3,50,150 +696,2023-09-06,3,Clothing,4,50,200 +697,2023-01-15,17,Clothing,1,500,500 +698,2023-07-19,29,Electronics,1,300,300 +699,2023-06-22,7,Clothing,4,30,120 +700,2023-12-09,20,Electronics,4,500,2000 +701,2023-12-14,6,Beauty,2,30,60 +702,2023-07-27,18,Clothing,2,300,600 +703,2023-03-26,38,Electronics,2,50,100 +704,2023-08-28,36,Clothing,3,30,90 +705,2023-03-07,50,Electronics,2,25,50 +706,2023-11-15,37,Electronics,4,25,100 +707,2023-10-01,24,Clothing,1,500,500 +708,2023-01-14,11,Beauty,3,300,900 +709,2023-07-21,17,Electronics,2,500,1000 +710,2023-10-31,24,Electronics,3,500,1500 +711,2023-10-16,15,Electronics,3,500,1500 +712,2023-12-06,28,Beauty,2,25,50 +713,2023-01-14,50,Beauty,3,25,75 +714,2023-02-12,47,Clothing,1,500,500 +715,2023-11-26,1,Beauty,4,25,100 +716,2023-08-08,28,Clothing,4,300,1200 +717,2023-03-11,1,Clothing,1,500,500 +718,2023-08-25,35,Beauty,3,25,75 +719,2023-04-04,39,Clothing,2,30,60 +720,2023-01-26,42,Beauty,3,500,1500 +721,2023-05-14,48,Clothing,1,500,500 +722,2023-07-14,10,Beauty,3,300,900 +723,2023-06-17,48,Beauty,4,50,200 +724,2023-04-19,29,Clothing,3,50,150 +725,2023-08-21,11,Electronics,1,300,300 +726,2023-06-17,50,Clothing,4,300,1200 +727,2023-06-22,47,Beauty,3,300,900 +728,2023-07-14,16,Electronics,3,50,150 +729,2023-05-23,36,Clothing,4,300,1200 +730,2023-08-04,6,Clothing,2,25,50 +731,2023-05-10,50,Clothing,4,500,2000 +732,2023-02-11,21,Electronics,2,500,1000 +733,2023-08-29,35,Beauty,1,30,30 +734,2023-01-10,11,Clothing,1,30,30 +735,2023-10-04,40,Clothing,4,500,2000 +736,2023-01-27,18,Clothing,4,25,100 +737,2023-06-29,49,Clothing,1,50,50 +738,2023-04-25,29,Clothing,2,50,100 +739,2023-11-29,11,Beauty,1,25,25 +740,2023-02-05,8,Beauty,4,50,200 +741,2023-11-30,25,Clothing,1,300,300 +742,2023-01-21,43,Electronics,4,500,2000 +743,2023-01-16,47,Beauty,4,500,2000 +744,2023-05-07,18,Electronics,1,25,25 +745,2023-04-13,4,Beauty,2,50,100 +746,2023-01-11,46,Clothing,3,30,90 +747,2023-11-15,39,Beauty,1,30,30 +748,2023-03-20,14,Clothing,3,50,150 +749,2023-05-03,2,Beauty,1,30,30 +750,2023-03-06,9,Clothing,3,25,75 +751,2023-08-31,3,Clothing,2,25,50 +752,2023-12-09,29,Clothing,2,50,100 +753,2023-02-28,21,Clothing,1,30,30 +754,2023-10-16,47,Electronics,4,25,100 +755,2023-04-22,34,Clothing,3,25,75 +756,2023-08-27,44,Electronics,4,300,1200 +757,2023-12-25,14,Electronics,4,300,1200 +758,2023-05-12,18,Clothing,4,25,100 +759,2023-07-08,21,Electronics,2,50,100 +760,2023-03-27,45,Beauty,1,500,500 +761,2023-11-07,7,Clothing,1,500,500 +762,2023-11-07,39,Electronics,2,25,50 +763,2023-02-28,48,Clothing,2,25,50 +764,2023-03-25,25,Clothing,1,25,25 +765,2023-06-09,29,Clothing,4,50,200 +766,2023-02-25,27,Electronics,3,300,900 +767,2023-10-24,34,Beauty,3,25,75 +768,2023-01-14,41,Beauty,3,25,75 +769,2023-06-09,40,Electronics,4,30,120 +770,2023-10-22,43,Clothing,1,50,50 +771,2023-12-13,47,Electronics,2,25,50 +772,2023-07-12,28,Electronics,1,30,30 +773,2023-07-23,15,Electronics,4,500,2000 +774,2023-04-12,8,Clothing,2,25,50 +775,2023-02-08,47,Electronics,4,25,100 +776,2023-10-31,49,Clothing,3,30,90 +777,2023-12-20,15,Electronics,3,50,150 +778,2023-11-18,48,Beauty,4,25,100 +779,2023-05-05,34,Electronics,2,500,1000 +780,2023-02-22,21,Electronics,2,25,50 +781,2023-12-23,20,Beauty,1,500,500 +782,2023-06-04,11,Clothing,3,300,900 +783,2023-12-17,47,Clothing,1,300,300 +784,2023-11-04,22,Electronics,1,500,500 +785,2023-03-03,22,Beauty,4,50,200 +786,2023-10-17,36,Clothing,4,25,100 +787,2023-01-22,20,Electronics,1,25,25 +788,2023-06-27,34,Beauty,3,300,900 +789,2023-09-30,23,Clothing,4,500,2000 +790,2023-08-08,42,Clothing,1,25,25 +791,2023-12-05,42,Beauty,1,25,25 +792,2023-07-09,22,Beauty,1,50,50 +793,2023-02-05,26,Beauty,1,30,30 +794,2023-09-17,30,Beauty,1,300,300 +795,2023-11-28,44,Electronics,1,300,300 +796,2023-06-24,16,Beauty,4,30,120 +797,2023-01-07,1,Clothing,3,25,75 +798,2023-08-04,38,Clothing,1,50,50 +799,2023-09-08,5,Electronics,2,50,100 +800,2023-02-24,12,Clothing,4,300,1200 +801,2023-08-10,3,Clothing,4,50,200 +802,2023-07-05,13,Beauty,1,30,30 +803,2023-11-22,43,Clothing,4,25,100 +804,2023-08-24,45,Electronics,1,30,30 +805,2023-12-29,42,Beauty,3,500,1500 +806,2023-03-20,16,Beauty,3,300,900 +807,2023-08-11,8,Electronics,4,50,200 +808,2023-04-01,22,Beauty,4,500,2000 +809,2023-09-25,35,Beauty,2,50,100 +810,2023-11-30,12,Electronics,4,25,100 +811,2023-05-19,48,Beauty,2,25,50 +812,2023-11-12,24,Electronics,3,25,75 +813,2023-10-03,50,Electronics,3,50,150 +814,2023-09-05,7,Clothing,1,500,500 +815,2023-08-27,5,Clothing,3,25,75 +816,2023-08-12,39,Beauty,2,500,1000 +817,2023-10-31,23,Beauty,4,50,200 +818,2023-05-18,38,Electronics,1,500,500 +819,2023-06-15,40,Beauty,2,50,100 +820,2023-05-06,19,Electronics,4,50,200 +821,2023-02-14,21,Electronics,1,300,300 +822,2023-05-23,35,Beauty,3,50,150 +823,2023-08-19,33,Electronics,2,50,100 +824,2023-05-05,12,Clothing,4,30,120 +825,2023-08-26,18,Beauty,1,25,25 +826,2023-10-19,25,Clothing,1,300,300 +827,2023-11-09,7,Beauty,3,300,900 +828,2023-12-09,2,Electronics,4,300,1200 +829,2023-07-14,26,Beauty,3,30,90 +830,2023-06-22,13,Clothing,3,50,150 +831,2023-01-15,34,Electronics,4,25,100 +832,2023-09-11,9,Beauty,4,500,2000 +833,2023-06-16,43,Beauty,4,50,200 +834,2023-04-04,29,Beauty,2,30,60 +835,2023-09-07,24,Clothing,4,50,200 +836,2023-04-19,49,Clothing,1,50,50 +837,2023-07-01,8,Beauty,3,30,90 +838,2023-05-13,3,Electronics,2,300,600 +839,2023-06-24,30,Electronics,4,300,1200 +840,2023-05-24,29,Clothing,2,25,50 +841,2023-11-02,20,Electronics,4,25,100 +842,2023-12-26,1,Clothing,2,300,600 +843,2023-05-22,3,Beauty,3,500,1500 +844,2023-10-12,17,Clothing,3,50,150 +845,2023-01-06,30,Clothing,1,500,500 +846,2023-09-22,27,Beauty,1,50,50 +847,2023-04-08,10,Electronics,4,300,1200 +848,2023-02-13,39,Clothing,3,25,75 +849,2023-05-04,28,Clothing,2,25,50 +850,2023-07-28,20,Beauty,2,500,1000 +851,2023-09-08,34,Electronics,2,25,50 +852,2023-10-12,5,Clothing,1,300,300 +853,2023-05-04,46,Beauty,2,500,1000 +854,2023-12-20,19,Clothing,1,50,50 +855,2023-09-01,29,Beauty,1,25,25 +856,2023-11-27,14,Electronics,4,30,120 +857,2023-12-31,6,Electronics,2,25,50 +858,2023-09-09,28,Electronics,2,50,100 +859,2023-08-18,13,Electronics,3,500,1500 +860,2023-01-09,47,Clothing,4,50,200 +861,2023-02-17,16,Clothing,3,30,90 +862,2023-05-31,1,Electronics,4,300,1200 +863,2023-04-24,13,Electronics,2,25,50 +864,2023-07-27,16,Electronics,1,500,500 +865,2023-12-21,12,Clothing,1,300,300 +866,2023-05-05,32,Electronics,1,50,50 +867,2023-06-06,25,Electronics,1,500,500 +868,2023-12-06,27,Electronics,1,300,300 +869,2023-10-25,38,Beauty,3,500,1500 +870,2023-07-08,26,Electronics,4,30,120 +871,2023-08-31,1,Beauty,2,30,60 +872,2023-10-11,27,Beauty,3,25,75 +873,2023-09-29,24,Electronics,4,25,100 +874,2023-06-26,27,Beauty,1,30,30 +875,2023-08-06,41,Electronics,4,500,2000 +876,2023-10-09,40,Clothing,4,30,120 +877,2023-06-19,37,Clothing,1,25,25 +878,2023-06-30,34,Clothing,1,30,30 +879,2023-12-26,35,Clothing,1,30,30 +880,2023-08-21,42,Beauty,2,500,1000 +881,2023-05-19,24,Electronics,1,300,300 +882,2023-06-06,39,Electronics,2,25,50 +883,2023-05-09,24,Electronics,1,500,500 +884,2023-04-29,46,Clothing,2,30,60 +885,2023-03-03,50,Clothing,4,30,120 +886,2023-04-09,29,Electronics,3,300,900 +887,2023-06-11,43,Clothing,4,25,100 +888,2023-03-03,15,Electronics,4,25,100 +889,2023-10-02,25,Electronics,1,50,50 +890,2023-12-20,24,Electronics,2,25,50 +891,2023-04-05,38,Electronics,3,300,900 +892,2023-04-09,32,Electronics,1,50,50 +893,2023-04-21,40,Electronics,1,50,50 +894,2023-09-05,20,Electronics,1,30,30 +895,2023-05-22,24,Clothing,4,30,120 +896,2023-10-29,19,Electronics,2,25,50 +897,2023-09-26,49,Electronics,2,50,100 +898,2023-11-02,33,Clothing,3,30,90 +899,2023-05-25,3,Clothing,2,300,600 +900,2023-02-21,7,Clothing,2,30,60 +901,2023-04-10,32,Electronics,1,30,30 +902,2023-06-01,45,Beauty,1,50,50 +903,2023-04-27,40,Beauty,4,50,200 +904,2023-07-04,24,Clothing,1,500,500 +905,2023-04-02,48,Beauty,1,300,300 +906,2023-06-04,6,Clothing,1,50,50 +907,2023-01-08,46,Electronics,1,25,25 +908,2023-12-29,7,Beauty,4,300,1200 +909,2023-10-01,45,Electronics,1,300,300 +910,2023-03-06,45,Beauty,3,50,150 +911,2023-05-21,3,Electronics,3,300,900 +912,2023-01-24,7,Beauty,3,50,150 +913,2023-01-28,2,Electronics,3,30,90 +914,2023-10-11,41,Electronics,1,500,500 +915,2023-05-30,8,Beauty,3,30,90 +916,2023-12-24,19,Electronics,1,50,50 +917,2023-03-06,30,Electronics,4,50,200 +918,2023-11-23,35,Electronics,3,30,90 +919,2023-09-09,37,Beauty,2,25,50 +920,2023-02-22,10,Beauty,3,25,75 +921,2023-01-07,10,Electronics,3,25,75 +922,2023-10-21,17,Electronics,1,50,50 +923,2023-05-26,14,Beauty,3,300,900 +924,2023-08-29,18,Beauty,2,50,100 +925,2023-09-03,21,Electronics,1,300,300 +926,2023-08-14,21,Electronics,1,30,30 +927,2023-06-24,24,Electronics,4,500,2000 +928,2023-04-05,22,Clothing,4,300,1200 +929,2023-01-27,29,Beauty,3,25,75 +930,2023-05-10,41,Clothing,4,50,200 +931,2023-09-02,8,Beauty,4,30,120 +932,2023-02-28,12,Beauty,4,25,100 +933,2023-02-03,17,Beauty,1,30,30 +934,2023-07-25,20,Beauty,1,500,500 +935,2023-09-09,46,Beauty,1,50,50 +936,2023-02-07,39,Beauty,4,50,200 +937,2023-10-23,8,Beauty,1,500,500 +938,2023-11-19,30,Clothing,4,50,200 +939,2023-12-18,39,Electronics,1,300,300 +940,2023-01-28,7,Electronics,1,30,30 +941,2023-03-19,49,Clothing,2,25,50 +942,2023-03-18,21,Clothing,3,500,1500 +943,2023-10-16,6,Clothing,4,300,1200 +944,2023-06-05,23,Clothing,2,25,50 +945,2023-02-13,34,Beauty,1,25,25 +946,2023-05-08,20,Electronics,4,500,2000 +947,2023-03-02,7,Beauty,1,300,300 +948,2023-10-13,12,Electronics,3,25,75 +949,2023-08-02,11,Electronics,2,25,50 +950,2023-11-07,17,Clothing,3,300,900 +951,2023-11-02,5,Beauty,2,50,100 +952,2023-11-13,41,Clothing,1,25,25 +953,2023-04-26,37,Beauty,3,30,90 +954,2023-09-25,28,Electronics,3,300,900 +955,2023-07-14,45,Clothing,1,25,25 +956,2023-08-19,24,Clothing,3,500,1500 +957,2023-08-15,34,Electronics,4,30,120 +958,2023-06-02,2,Electronics,2,25,50 +959,2023-10-29,49,Electronics,2,30,60 +960,2023-08-08,17,Clothing,2,30,60 +961,2023-06-06,23,Beauty,4,50,200 +962,2023-10-19,50,Clothing,2,30,60 +963,2023-11-14,15,Beauty,1,50,50 +964,2023-01-31,32,Clothing,3,300,900 +965,2023-11-09,16,Clothing,4,50,200 +966,2023-02-20,21,Electronics,2,500,1000 +967,2023-04-17,23,Beauty,1,25,25 +968,2023-11-17,8,Clothing,3,300,900 +969,2023-04-19,8,Clothing,3,300,900 +970,2023-05-16,43,Electronics,4,500,2000 +971,2023-12-05,20,Electronics,4,50,200 +972,2023-02-11,11,Beauty,4,25,100 +973,2023-03-22,50,Clothing,1,50,50 +974,2023-05-03,21,Beauty,1,30,30 +975,2023-03-30,39,Clothing,4,50,200 +976,2023-10-10,18,Beauty,2,300,600 +977,2023-02-08,20,Electronics,3,25,75 +978,2023-03-22,36,Clothing,3,50,150 +979,2023-01-02,38,Beauty,1,25,25 +980,2023-07-29,26,Electronics,3,25,75 +981,2023-08-19,49,Electronics,2,30,60 +982,2023-12-19,4,Beauty,3,30,90 +983,2023-11-01,27,Clothing,1,300,300 +984,2023-08-29,36,Clothing,1,500,500 +985,2023-05-30,38,Electronics,2,25,50 +986,2023-01-17,9,Clothing,2,500,1000 +987,2023-04-29,45,Clothing,3,300,900 +988,2023-05-28,20,Clothing,3,25,75 +989,2023-12-28,31,Electronics,1,25,25 +990,2023-05-25,45,Beauty,2,500,1000 +991,2023-12-26,27,Clothing,2,50,100 +992,2023-08-21,21,Electronics,2,30,60 +993,2023-02-06,20,Electronics,3,50,150 +994,2023-12-18,45,Beauty,2,500,1000 +995,2023-04-30,24,Clothing,1,30,30 +996,2023-05-16,6,Clothing,1,50,50 +997,2023-11-17,35,Beauty,3,30,90 +998,2023-10-29,5,Beauty,4,25,100 +999,2023-12-05,2,Electronics,3,50,150 +1000,2023-04-12,15,Electronics,4,30,120 \ No newline at end of file diff --git a/ai-ml/nl-to-sql/manifests/01-postgres-cluster/my-cluster.yaml b/ai-ml/nl-to-sql/manifests/01-postgres-cluster/my-cluster.yaml new file mode 100644 index 0000000000..444e22c5e3 --- /dev/null +++ b/ai-ml/nl-to-sql/manifests/01-postgres-cluster/my-cluster.yaml @@ -0,0 +1,88 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START gke_databases_postgres_zalando_manifests_01_cluster] +apiVersion: "acid.zalan.do/v1" +kind: postgresql +metadata: + name: my-cluster +spec: + dockerImage: ghcr.io/zalando/spilo-15:3.0-p1 + teamId: "my-team" + numberOfInstances: 3 + users: + mydatabaseowner: + - superuser + - createdb + myuser: [] + databases: + mydatabase: mydatabaseowner + postgresql: + version: "15" + parameters: + shared_buffers: "32MB" + max_connections: "10" + log_statement: "all" + password_encryption: scram-sha-256 + volume: + size: 5Gi + storageClass: premium-rwo + enableShmVolume: true + podAnnotations: + cluster-autoscaler.kubernetes.io/safe-to-evict: "true" + tolerations: + - key: "app.stateful/component" + operator: "Equal" + value: "postgres-operator" + effect: NoSchedule + nodeAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 1 + preference: + matchExpressions: + - key: "app.stateful/component" + operator: In + values: + - "postgres-operator" + resources: + requests: + cpu: "1" + memory: 4Gi + limits: + cpu: "2" + memory: 4Gi + sidecars: + - name: exporter + image: quay.io/prometheuscommunity/postgres-exporter:v0.14.0 + args: + - --collector.stat_statements + ports: + - name: exporter + containerPort: 9187 + protocol: TCP + resources: + limits: + cpu: 500m + memory: 256M + requests: + cpu: 100m + memory: 256M + env: + - name: "DATA_SOURCE_URI" + value: "localhost/postgres?sslmode=require" + - name: "DATA_SOURCE_USER" + value: "$(POSTGRES_USER)" + - name: "DATA_SOURCE_PASS" + value: "$(POSTGRES_PASSWORD)" +# [END gke_databases_postgres_zalando_manifests_01_cluster] diff --git a/ai-ml/nl-to-sql/manifests/02-tgi/tgi.yaml b/ai-ml/nl-to-sql/manifests/02-tgi/tgi.yaml new file mode 100644 index 0000000000..3635cd9c8a --- /dev/null +++ b/ai-ml/nl-to-sql/manifests/02-tgi/tgi.yaml @@ -0,0 +1,83 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START gke_ai_ml_llm_serving_gemma_tgi_2b_it_deployment] +apiVersion: apps/v1 +kind: Deployment +metadata: + name: tgi +spec: + replicas: 1 + selector: + matchLabels: + app: tgi-runtime + template: + metadata: + labels: + app: tgi-runtime + ai.gke.io/model: gemma-2b-it + ai.gke.io/inference-server: text-generation-inference + examples.ai.gke.io/source: user-guide + spec: + containers: + - name: inference-server + image: ghcr.io/huggingface/text-generation-inference:2.0.2 + resources: + requests: + cpu: "2" + memory: "7Gi" + ephemeral-storage: "20Gi" + nvidia.com/gpu: 1 + limits: + cpu: "2" + memory: "7Gi" + ephemeral-storage: "20Gi" + nvidia.com/gpu: 1 + args: + - --model-id=$(MODEL_ID) + - --num-shard=1 + env: + - name: MODEL_ID + #value: google/gemma-2b-it + value: dganochenko/llama-3-8b-chat + - name: PORT + value: "8000" + - name: HUGGING_FACE_HUB_TOKEN + valueFrom: + secretKeyRef: + name: hf-secret + key: hf_api_token + volumeMounts: + - mountPath: /dev/shm + name: dshm + volumes: + - name: dshm + emptyDir: + medium: Memory + nodeSelector: + cloud.google.com/gke-accelerator: nvidia-l4 +--- +apiVersion: v1 +kind: Service +metadata: + name: llm-service +spec: + selector: + app: tgi-runtime + type: ClusterIP + ports: + - protocol: TCP + port: 8000 + targetPort: 8000 +# [END gke_ai_ml_llm_serving_gemma_tgi_2b_it_deployment] diff --git a/ai-ml/nl-to-sql/manifests/02-tgi/tgi_.yaml b/ai-ml/nl-to-sql/manifests/02-tgi/tgi_.yaml new file mode 100644 index 0000000000..8720d153e1 --- /dev/null +++ b/ai-ml/nl-to-sql/manifests/02-tgi/tgi_.yaml @@ -0,0 +1,86 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START gke_ai_ml_llm_serving_gemma_tgi_2b_it_deployment] +apiVersion: apps/v1 +kind: Deployment +metadata: + name: tgi +spec: + replicas: 1 + selector: + matchLabels: + app: tgi-runtime + template: + metadata: + labels: + app: tgi-runtime + ai.gke.io/model: gemma-2b-it + ai.gke.io/inference-server: text-generation-inference + examples.ai.gke.io/source: user-guide + spec: + containers: + - name: inference-server + image: ghcr.io/huggingface/text-generation-inference:2.0.2 + resources: + requests: + cpu: "2" + memory: "7Gi" + ephemeral-storage: "20Gi" + nvidia.com/gpu: 1 + limits: + cpu: "2" + memory: "7Gi" + ephemeral-storage: "20Gi" + nvidia.com/gpu: 1 + args: + - --model-id=$(MODEL_ID) + - --num-shard=1 + - --max-total-tokens=3072 + - --max-batch-prefill-tokens=1024 + - --max-input-length=1024 + env: + - name: MODEL_ID + #value: google/gemma-2b-it + value: google/gemma-7b-it + - name: PORT + value: "8000" + - name: HUGGING_FACE_HUB_TOKEN + valueFrom: + secretKeyRef: + name: hf-secret + key: hf_api_token + volumeMounts: + - mountPath: /dev/shm + name: dshm + volumes: + - name: dshm + emptyDir: + medium: Memory + nodeSelector: + cloud.google.com/gke-accelerator: nvidia-l4 +--- +apiVersion: v1 +kind: Service +metadata: + name: llm-service +spec: + selector: + app: tgi-runtime + type: ClusterIP + ports: + - protocol: TCP + port: 8000 + targetPort: 8000 +# [END gke_ai_ml_llm_serving_gemma_tgi_2b_it_deployment] From 2557ed3f9ce629af8600d6dac676c44647458267 Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Thu, 16 May 2024 13:48:26 +0200 Subject: [PATCH 02/28] add python clinet --- .../manifests/03-client/client-pod.yaml | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 ai-ml/nl-to-sql/manifests/03-client/client-pod.yaml diff --git a/ai-ml/nl-to-sql/manifests/03-client/client-pod.yaml b/ai-ml/nl-to-sql/manifests/03-client/client-pod.yaml new file mode 100644 index 0000000000..bf71014ba6 --- /dev/null +++ b/ai-ml/nl-to-sql/manifests/03-client/client-pod.yaml @@ -0,0 +1,49 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: v1 +kind: Pod +metadata: + name: client + annotations: + cluster-autoscaler.kubernetes.io/safe-to-evict: "true" +spec: + restartPolicy: Never + containers: + - name: client + image: python:3.11 + command: [ "/bin/bash", "-c", "--" ] + args: [ "while true; do sleep 30; done;" ] + env: + - name: CLIENTPASSWORD + valueFrom: + secretKeyRef: + name: myuser.my-cluster.credentials.postgresql.acid.zalan.do + key: password + - name: CLIENTUSERNAME + valueFrom: + secretKeyRef: + name: myuser.my-cluster.credentials.postgresql.acid.zalan.do + key: username + - name: OWNERPASSWORD + valueFrom: + secretKeyRef: + name: mydatabaseowner.my-cluster.credentials.postgresql.acid.zalan.do + key: password + - name: OWNERUSERNAME + valueFrom: + secretKeyRef: + name: mydatabaseowner.my-cluster.credentials.postgresql.acid.zalan.do + key: username + From 54d2362d5149594f09d9e8db75be4d335c37a5bf Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Thu, 16 May 2024 15:58:55 +0200 Subject: [PATCH 03/28] updates --- ai-ml/nl-to-sql/dataset/customers.csv | 100 +++++++++--------- .../manifests/03-client/client-pod.yaml | 16 ++- ai-ml/nl-to-sql/manifests/03-client/script.py | 64 +++++++++++ 3 files changed, 120 insertions(+), 60 deletions(-) create mode 100644 ai-ml/nl-to-sql/manifests/03-client/script.py diff --git a/ai-ml/nl-to-sql/dataset/customers.csv b/ai-ml/nl-to-sql/dataset/customers.csv index 24fd309527..d5c3e729a9 100644 --- a/ai-ml/nl-to-sql/dataset/customers.csv +++ b/ai-ml/nl-to-sql/dataset/customers.csv @@ -1,51 +1,51 @@ CustomerID,Name,Gender,Age -1,James,Male,34 -2,Patricia,Female,26 -3,Michael,Male,50 -4,Robert,Male,37 -5,John,Male,30 -6,Jennifer,Female,45 -7,William,Male,46 -8,David,Male,30 -9,Richard,Male,63 -10,Linda,Female,52 -11,Joseph,Male,23 -12,Thomas,Male,35 -13,Christopher,Male,22 -14,Charles,Male,64 -15,Elizabeth,Female,42 -16,Daniel,Male,19 -17,Barbara,Female,27 -18,Susan,Female,47 -19,Jessica,Female,62 -20,Matthew,Male,22 -21,Karen,Female,50 -22,Anthony,Male,18 -23,Sarah,Female,35 -24,Lisa,Female,49 -25,Nancy,Female,64 -26,Sandra,Female,28 -27,Betty,Female,38 -28,Ashley,Female,43 -29,Kimberly,Female,42 -30,Margaret,Female,39 -31,Mark,Male,44 -32,Steven,Male,30 -33,Donna,Female,50 -34,Michelle,Female,51 -35,Carol,Female,58 -36,Andrew,Male,52 -37,Melissa,Female,18 -38,Paul,Male,38 -39,Kevin,Male,23 -40,Brian,Male,45 -41,George,Male,34 -42,Jason,Male,22 -43,Rebecca,Female,48 -44,Sharon,Female,22 -45,Laura,Female,55 -46,Amy,Female,20 -47,Angela,Female,40 -48,Edward,Male,54 -49,Emma,Female,54 -50,Brenda,Female,27 \ No newline at end of file +1,James,M,34 +2,Patricia,F,26 +3,Michael,M,50 +4,Robert,M,37 +5,John,M,30 +6,Jennifer,F,45 +7,William,M,46 +8,David,M,30 +9,Richard,M,63 +10,Linda,F,52 +11,Joseph,M,23 +12,Thomas,M,35 +13,Christopher,M,22 +14,Charles,M,64 +15,Elizabeth,F,42 +16,Daniel,M,19 +17,Barbara,F,27 +18,Susan,F,47 +19,Jessica,F,62 +20,Matthew,M,22 +21,Karen,F,50 +22,Anthony,M,18 +23,Sarah,F,35 +24,Lisa,F,49 +25,Nancy,F,64 +26,Sandra,F,28 +27,Betty,F,38 +28,Ashley,F,43 +29,Kimberly,F,42 +30,Margaret,F,39 +31,Mark,M,44 +32,Steven,M,30 +33,Donna,F,50 +34,Michelle,F,51 +35,Carol,F,58 +36,Andrew,M,52 +37,Melissa,F,18 +38,Paul,M,38 +39,Kevin,M,23 +40,Brian,M,45 +41,George,M,34 +42,Jason,M,22 +43,Rebecca,F,48 +44,Sharon,F,22 +45,Laura,F,55 +46,Amy,F,20 +47,Angela,F,40 +48,Edward,M,54 +49,Emma,F,54 +50,Brenda,F,27 diff --git a/ai-ml/nl-to-sql/manifests/03-client/client-pod.yaml b/ai-ml/nl-to-sql/manifests/03-client/client-pod.yaml index bf71014ba6..8470ed76fd 100644 --- a/ai-ml/nl-to-sql/manifests/03-client/client-pod.yaml +++ b/ai-ml/nl-to-sql/manifests/03-client/client-pod.yaml @@ -26,16 +26,6 @@ spec: command: [ "/bin/bash", "-c", "--" ] args: [ "while true; do sleep 30; done;" ] env: - - name: CLIENTPASSWORD - valueFrom: - secretKeyRef: - name: myuser.my-cluster.credentials.postgresql.acid.zalan.do - key: password - - name: CLIENTUSERNAME - valueFrom: - secretKeyRef: - name: myuser.my-cluster.credentials.postgresql.acid.zalan.do - key: username - name: OWNERPASSWORD valueFrom: secretKeyRef: @@ -46,4 +36,10 @@ spec: secretKeyRef: name: mydatabaseowner.my-cluster.credentials.postgresql.acid.zalan.do key: username + - name: POSTGRES_URL + value: my-cluster.postgres + - name: DATABASE_NAME + value: mydatabase + - name: LLM_ENDPOINT + value: http://llm-service.llm:8000 diff --git a/ai-ml/nl-to-sql/manifests/03-client/script.py b/ai-ml/nl-to-sql/manifests/03-client/script.py new file mode 100644 index 0000000000..e69aef38ea --- /dev/null +++ b/ai-ml/nl-to-sql/manifests/03-client/script.py @@ -0,0 +1,64 @@ +import psycopg +import os +from tabulate import tabulate +from langchain_community.llms import HuggingFaceTextGenInference +from langchain_core.prompts import PromptTemplate + +conn = psycopg.connect( + dbname=os.environ.get("DATABASE_NAME"), + host=os.environ.get("POSTGRES_URL"), + user=os.environ.get("OWNERUSERNAME"), + password=os.environ.get("OWNERPASSWORD"), + autocommit=True) + +db_schema = conn.execute("SELECT table_name, column_name as Columns, data_type as DataTypes FROM information_schema.columns where table_name NOT LIKE 'pg_stat%' AND table_schema='public' order by table_name,column_name;") +colnames = [desc[0] for desc in db_schema.description] +db_schema_formatted=tabulate(db_schema.fetchall(), headers=colnames, tablefmt='psql') + +llm = HuggingFaceTextGenInference( + inference_server_url=os.environ.get("LLM_ENDPOINT"), + temperature=0.9, +) + +sql_prompt_template = PromptTemplate.from_template(""" +<|begin_of_text|><|start_header_id|>system<|end_header_id|> +You are a helpful AI assistant that can transform user queries into SQL commands to retrieve the data from the Postgresql database. The database has the next tables schema: +{db_schema} + +Please prepare and return only the SQL command, based on the user query, without any formatting or newlines. The answer must contain only valid SQL command.<|eot_id|><|start_header_id|>user<|end_header_id|> +{query}<|eot_id|><|start_header_id|>assistant<|end_header_id|> +""") + +final_prompt_template = PromptTemplate.from_template(""" +<|begin_of_text|><|start_header_id|>system<|end_header_id|> +You are a helpful AI assistant that can understand Postgresql replies and explain this data to the user. The database has the next tables schema: +{db_schema} + +User query: {query} + +Postgresql reply: +{postgres_reply} + +Please prepare and return the answer, based on the user question and Postgresql reply. It should be easy to understand your answer. Don't add any introductory words, start answering right away. Keep your answer to a one or two sentences (if possible) that specifically answers the user's question. If not - try to keep the answer short, summarizing the returned data. +If you do not know the answer or Postgres reply is empty, response with "I don't know". +<|eot_id|><|start_header_id|>assistant<|end_header_id|> +""") + +def handle_query(query): + sql_query=llm.invoke(sql_prompt_template.format(db_schema=db_schema_formatted, query=query)) + try: + postgres_reply = conn.execute(sql_query) + except psycopg.Error as e: + print("Unable to process query: ", query) + return "Try another query" + colnames = [desc[0] for desc in postgres_reply.description] + postgres_reply_formatted=tabulate(postgres_reply.fetchall(), headers=colnames, tablefmt='psql') + # debug section + # print(sql_query) + # print(postgres_reply_formatted) + # end of debug section + return llm.invoke(final_prompt_template.format(db_schema=db_schema_formatted, query=query, postgres_reply=postgres_reply_formatted)) + +print(handle_query("Please calculate the total sum of all John transactions.")) +print(handle_query("Which woman spent more money in 2023 and how much?")) +print(handle_query("Who let the dogs out?")) From 27c23a47177d61c7fef9b64decca22fbba853086 Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Thu, 16 May 2024 17:04:56 +0200 Subject: [PATCH 04/28] add script updates --- ai-ml/nl-to-sql/manifests/03-client/script.py | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/ai-ml/nl-to-sql/manifests/03-client/script.py b/ai-ml/nl-to-sql/manifests/03-client/script.py index e69aef38ea..ce8b9309bc 100644 --- a/ai-ml/nl-to-sql/manifests/03-client/script.py +++ b/ai-ml/nl-to-sql/manifests/03-client/script.py @@ -17,7 +17,10 @@ llm = HuggingFaceTextGenInference( inference_server_url=os.environ.get("LLM_ENDPOINT"), - temperature=0.9, + temperature=0.5, + top_k=10, + top_p=0.5, + repetition_penalty=1.03, ) sql_prompt_template = PromptTemplate.from_template(""" @@ -39,8 +42,13 @@ Postgresql reply: {postgres_reply} -Please prepare and return the answer, based on the user question and Postgresql reply. It should be easy to understand your answer. Don't add any introductory words, start answering right away. Keep your answer to a one or two sentences (if possible) that specifically answers the user's question. If not - try to keep the answer short, summarizing the returned data. -If you do not know the answer or Postgres reply is empty, response with "I don't know". +Base your answer on the provided user query and Postgresql reply. +Generate a draft response using the selected information. +It should be easy to understand your answer. Don't add any introductory words, start answering right away. +Keep your answer to a one or two sentences (if possible) that specifically answers the user's question. If not - try to keep the answer short, summarising the returned data. +Generate your final response after adjusting it to increase accuracy and relevance. +Now only show your final response! +If you do not know the answer or context is not relevant, response with "I don't know". <|eot_id|><|start_header_id|>assistant<|end_header_id|> """) @@ -52,13 +60,18 @@ def handle_query(query): print("Unable to process query: ", query) return "Try another query" colnames = [desc[0] for desc in postgres_reply.description] - postgres_reply_formatted=tabulate(postgres_reply.fetchall(), headers=colnames, tablefmt='psql') + postgres_reply_data = postgres_reply.fetchall() + if postgres_reply_data == []: + return "Received empty SQL answer, try another query" + postgres_reply_formatted=tabulate(postgres_reply_data, headers=colnames, tablefmt='psql') # debug section - # print(sql_query) - # print(postgres_reply_formatted) + print(sql_query) + print(postgres_reply_formatted) # end of debug section return llm.invoke(final_prompt_template.format(db_schema=db_schema_formatted, query=query, postgres_reply=postgres_reply_formatted)) print(handle_query("Please calculate the total sum of all John transactions.")) print(handle_query("Which woman spent more money in 2023 and how much?")) print(handle_query("Who let the dogs out?")) +print(handle_query("Who bought more electronics in last month?")) +print(handle_query("Who bought more electronics in 10 last months?")) From cf33ea2e00c2022e6ad76bd2177977ec2ab4bade Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Thu, 16 May 2024 17:11:39 +0200 Subject: [PATCH 05/28] add script updates --- ai-ml/nl-to-sql/manifests/03-client/script.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ai-ml/nl-to-sql/manifests/03-client/script.py b/ai-ml/nl-to-sql/manifests/03-client/script.py index ce8b9309bc..f6f0493370 100644 --- a/ai-ml/nl-to-sql/manifests/03-client/script.py +++ b/ai-ml/nl-to-sql/manifests/03-client/script.py @@ -65,8 +65,8 @@ def handle_query(query): return "Received empty SQL answer, try another query" postgres_reply_formatted=tabulate(postgres_reply_data, headers=colnames, tablefmt='psql') # debug section - print(sql_query) - print(postgres_reply_formatted) + # print(sql_query) + # print(postgres_reply_formatted) # end of debug section return llm.invoke(final_prompt_template.format(db_schema=db_schema_formatted, query=query, postgres_reply=postgres_reply_formatted)) From a109c7cd3b4e4eb628942c2b134e463f0c288f90 Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Thu, 16 May 2024 17:20:14 +0200 Subject: [PATCH 06/28] add script updates --- ai-ml/nl-to-sql/manifests/03-client/script.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ai-ml/nl-to-sql/manifests/03-client/script.py b/ai-ml/nl-to-sql/manifests/03-client/script.py index f6f0493370..509fa5e10a 100644 --- a/ai-ml/nl-to-sql/manifests/03-client/script.py +++ b/ai-ml/nl-to-sql/manifests/03-client/script.py @@ -45,7 +45,7 @@ Base your answer on the provided user query and Postgresql reply. Generate a draft response using the selected information. It should be easy to understand your answer. Don't add any introductory words, start answering right away. -Keep your answer to a one or two sentences (if possible) that specifically answers the user's question. If not - try to keep the answer short, summarising the returned data. +Keep your answer to a one or two sentences (if possible) that specifically answers the user's question. If not - try to keep the answer short, summarizing the returned data. Generate your final response after adjusting it to increase accuracy and relevance. Now only show your final response! If you do not know the answer or context is not relevant, response with "I don't know". From 9476cdebb2d6e715002a99726005893aba4b9dc5 Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Mon, 20 May 2024 09:41:07 +0200 Subject: [PATCH 07/28] updates --- .../01-postgres-cluster/my-cluster.yaml | 7 +- .../manifests/02-dataset/customers.csv | 51 + .../nl-to-sql/manifests/02-dataset/dataset.sh | 29 + ai-ml/nl-to-sql/manifests/02-dataset/job.yaml | 37 + .../manifests/02-dataset/transactions.csv | 1001 +++++++++++++++++ ai-ml/nl-to-sql/manifests/02-tgi/tgi_.yaml | 86 -- .../manifests/{02-tgi => 03-llm}/tgi.yaml | 0 .../client-pod.yaml | 0 .../{03-client => 04-notebook}/script.py | 0 9 files changed, 1121 insertions(+), 90 deletions(-) create mode 100644 ai-ml/nl-to-sql/manifests/02-dataset/customers.csv create mode 100755 ai-ml/nl-to-sql/manifests/02-dataset/dataset.sh create mode 100644 ai-ml/nl-to-sql/manifests/02-dataset/job.yaml create mode 100644 ai-ml/nl-to-sql/manifests/02-dataset/transactions.csv delete mode 100644 ai-ml/nl-to-sql/manifests/02-tgi/tgi_.yaml rename ai-ml/nl-to-sql/manifests/{02-tgi => 03-llm}/tgi.yaml (100%) rename ai-ml/nl-to-sql/manifests/{03-client => 04-notebook}/client-pod.yaml (100%) rename ai-ml/nl-to-sql/manifests/{03-client => 04-notebook}/script.py (100%) diff --git a/ai-ml/nl-to-sql/manifests/01-postgres-cluster/my-cluster.yaml b/ai-ml/nl-to-sql/manifests/01-postgres-cluster/my-cluster.yaml index 444e22c5e3..081911321a 100644 --- a/ai-ml/nl-to-sql/manifests/01-postgres-cluster/my-cluster.yaml +++ b/ai-ml/nl-to-sql/manifests/01-postgres-cluster/my-cluster.yaml @@ -47,10 +47,9 @@ spec: value: "postgres-operator" effect: NoSchedule nodeAffinity: - preferredDuringSchedulingIgnoredDuringExecution: - - weight: 1 - preference: - matchExpressions: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: - key: "app.stateful/component" operator: In values: diff --git a/ai-ml/nl-to-sql/manifests/02-dataset/customers.csv b/ai-ml/nl-to-sql/manifests/02-dataset/customers.csv new file mode 100644 index 0000000000..d5c3e729a9 --- /dev/null +++ b/ai-ml/nl-to-sql/manifests/02-dataset/customers.csv @@ -0,0 +1,51 @@ +CustomerID,Name,Gender,Age +1,James,M,34 +2,Patricia,F,26 +3,Michael,M,50 +4,Robert,M,37 +5,John,M,30 +6,Jennifer,F,45 +7,William,M,46 +8,David,M,30 +9,Richard,M,63 +10,Linda,F,52 +11,Joseph,M,23 +12,Thomas,M,35 +13,Christopher,M,22 +14,Charles,M,64 +15,Elizabeth,F,42 +16,Daniel,M,19 +17,Barbara,F,27 +18,Susan,F,47 +19,Jessica,F,62 +20,Matthew,M,22 +21,Karen,F,50 +22,Anthony,M,18 +23,Sarah,F,35 +24,Lisa,F,49 +25,Nancy,F,64 +26,Sandra,F,28 +27,Betty,F,38 +28,Ashley,F,43 +29,Kimberly,F,42 +30,Margaret,F,39 +31,Mark,M,44 +32,Steven,M,30 +33,Donna,F,50 +34,Michelle,F,51 +35,Carol,F,58 +36,Andrew,M,52 +37,Melissa,F,18 +38,Paul,M,38 +39,Kevin,M,23 +40,Brian,M,45 +41,George,M,34 +42,Jason,M,22 +43,Rebecca,F,48 +44,Sharon,F,22 +45,Laura,F,55 +46,Amy,F,20 +47,Angela,F,40 +48,Edward,M,54 +49,Emma,F,54 +50,Brenda,F,27 diff --git a/ai-ml/nl-to-sql/manifests/02-dataset/dataset.sh b/ai-ml/nl-to-sql/manifests/02-dataset/dataset.sh new file mode 100755 index 0000000000..2bcac97ef6 --- /dev/null +++ b/ai-ml/nl-to-sql/manifests/02-dataset/dataset.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +PGPASSWORD=$OWNERPASSWORD psql -U $OWNERUSERNAME -d $DATABASE_NAME -h $POSTGRES_URL -c \ + "CREATE TABLE IF NOT EXISTS customers ( + CustomerID INTEGER PRIMARY KEY, + Name VARCHAR(100), + Gender VARCHAR(10), + Age INTEGER + ); + CREATE TABLE IF NOT EXISTS transactions ( + TransactionID INTEGER PRIMARY KEY, + Date DATE, + CustomerID INTEGER, + ProductCategory VARCHAR(50), + Quantity INTEGER, + PricePerUnit INTEGER, + TotalAmount INTEGER + );" + +PGPASSWORD=$OWNERPASSWORD psql -U $OWNERUSERNAME -d $DATABASE_NAME -h $POSTGRES_URL -c \ + "\copy customers (CustomerID, Name, Gender, Age) + FROM '/usr/local/dataset/customers.csv' + WITH CSV HEADER DELIMITER AS ','" + +PGPASSWORD=$OWNERPASSWORD psql -U $OWNERUSERNAME -d $DATABASE_NAME -h $POSTGRES_URL -c \ + "\copy transactions (TransactionID, Date, CustomerID, ProductCategory, Quantity, PricePerUnit, TotalAmount) + FROM '/usr/local/dataset/transactions.csv' + WITH CSV HEADER DELIMITER AS ','" + diff --git a/ai-ml/nl-to-sql/manifests/02-dataset/job.yaml b/ai-ml/nl-to-sql/manifests/02-dataset/job.yaml new file mode 100644 index 0000000000..96c3b10ee8 --- /dev/null +++ b/ai-ml/nl-to-sql/manifests/02-dataset/job.yaml @@ -0,0 +1,37 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: upload-dataset +spec: + ttlSecondsAfterFinished: 120 + template: + spec: + containers: + - name: psql + image: postgres:15.7 + command: [ "/bin/bash", "-c" ] + args: [ "/usr/local/dataset/dataset.sh" ] + env: + - name: OWNERPASSWORD + valueFrom: + secretKeyRef: + name: mydatabaseowner.my-cluster.credentials.postgresql.acid.zalan.do + key: password + - name: OWNERUSERNAME + valueFrom: + secretKeyRef: + name: mydatabaseowner.my-cluster.credentials.postgresql.acid.zalan.do + key: username + - name: POSTGRES_URL + value: my-cluster.postgres + - name: DATABASE_NAME + value: mydatabase + volumeMounts: + - name: customers-dataset + mountPath: /usr/local/dataset + volumes: + - name: customers-dataset + configMap: + name: customers-dataset + defaultMode: 0500 + restartPolicy: Never diff --git a/ai-ml/nl-to-sql/manifests/02-dataset/transactions.csv b/ai-ml/nl-to-sql/manifests/02-dataset/transactions.csv new file mode 100644 index 0000000000..91fe8552f7 --- /dev/null +++ b/ai-ml/nl-to-sql/manifests/02-dataset/transactions.csv @@ -0,0 +1,1001 @@ +TransactionID,Date,CustomerID,ProductCategory,Quantity,PricePerUnit,TotalAmount +1,2023-11-24,41,Beauty,3,50,150 +2,2023-02-27,21,Clothing,2,500,1000 +3,2023-01-13,19,Electronics,1,30,30 +4,2023-05-21,34,Clothing,1,500,500 +5,2023-05-06,38,Beauty,2,50,100 +6,2023-04-25,14,Beauty,1,30,30 +7,2023-03-13,22,Clothing,2,25,50 +8,2023-02-22,4,Electronics,4,25,100 +9,2023-12-13,22,Electronics,2,300,600 +10,2023-10-07,50,Clothing,4,50,200 +11,2023-02-14,12,Clothing,2,50,100 +12,2023-10-30,29,Beauty,3,25,75 +13,2023-08-05,36,Electronics,3,500,1500 +14,2023-01-17,41,Clothing,4,30,120 +15,2023-01-16,1,Electronics,4,500,2000 +16,2023-02-17,6,Clothing,3,500,1500 +17,2023-04-22,44,Clothing,4,25,100 +18,2023-04-30,6,Electronics,2,25,50 +19,2023-09-16,9,Clothing,2,25,50 +20,2023-11-05,1,Clothing,3,300,900 +21,2023-01-14,28,Beauty,1,500,500 +22,2023-10-15,2,Clothing,2,50,100 +23,2023-04-12,29,Clothing,4,30,120 +24,2023-11-29,22,Clothing,1,300,300 +25,2023-12-26,42,Beauty,1,50,50 +26,2023-10-07,22,Electronics,2,500,1000 +27,2023-08-03,10,Beauty,2,25,50 +28,2023-04-23,31,Beauty,1,500,500 +29,2023-08-18,11,Electronics,1,30,30 +30,2023-10-29,42,Beauty,3,300,900 +31,2023-05-23,37,Electronics,4,300,1200 +32,2023-01-04,42,Beauty,3,30,90 +33,2023-03-23,10,Electronics,2,50,100 +34,2023-12-24,28,Clothing,3,50,150 +35,2023-08-05,40,Beauty,3,300,900 +36,2023-06-24,28,Beauty,3,300,900 +37,2023-05-23,10,Beauty,3,25,75 +38,2023-03-21,42,Beauty,4,50,200 +39,2023-04-21,29,Clothing,4,30,120 +40,2023-06-22,6,Beauty,1,50,50 +41,2023-02-22,46,Clothing,2,25,50 +42,2023-02-17,39,Clothing,3,300,900 +43,2023-07-14,20,Clothing,1,300,300 +44,2023-02-19,37,Clothing,1,25,25 +45,2023-07-03,5,Electronics,1,30,30 +46,2023-06-26,12,Electronics,4,300,1200 +47,2023-11-06,12,Beauty,3,500,1500 +48,2023-05-16,41,Electronics,3,300,900 +49,2023-01-23,21,Electronics,2,500,1000 +50,2023-08-24,21,Beauty,3,25,75 +51,2023-10-02,10,Beauty,3,25,75 +52,2023-03-05,26,Beauty,1,300,300 +53,2023-07-13,3,Electronics,2,50,100 +54,2023-02-10,41,Electronics,3,500,1500 +55,2023-10-10,14,Beauty,4,30,120 +56,2023-05-31,32,Clothing,3,300,900 +57,2023-11-18,24,Beauty,1,30,30 +58,2023-11-13,44,Clothing,4,300,1200 +59,2023-07-05,1,Clothing,1,50,50 +60,2023-10-23,41,Beauty,3,50,150 +61,2023-04-09,1,Beauty,4,50,200 +62,2023-12-27,17,Beauty,2,50,100 +63,2023-02-05,25,Electronics,2,25,50 +64,2023-01-24,34,Clothing,4,25,100 +65,2023-12-05,48,Electronics,4,500,2000 +66,2023-04-27,21,Electronics,1,30,30 +67,2023-05-29,42,Beauty,4,300,1200 +68,2023-02-10,24,Electronics,1,300,300 +69,2023-04-30,33,Beauty,3,25,75 +70,2023-02-21,21,Clothing,1,300,300 +71,2023-07-14,37,Beauty,4,25,100 +72,2023-05-23,15,Electronics,4,500,2000 +73,2023-08-21,1,Electronics,3,30,90 +74,2023-11-22,50,Beauty,4,500,2000 +75,2023-07-06,44,Beauty,4,50,200 +76,2023-03-25,14,Electronics,2,50,100 +77,2023-07-09,28,Clothing,2,50,100 +78,2023-07-01,28,Clothing,3,500,1500 +79,2023-04-18,21,Beauty,1,300,300 +80,2023-12-10,14,Clothing,2,30,60 +81,2023-05-17,35,Electronics,1,50,50 +82,2023-12-26,7,Beauty,4,50,200 +83,2023-12-16,21,Electronics,2,50,100 +84,2023-11-28,37,Electronics,3,30,90 +85,2023-02-06,28,Clothing,3,50,150 +86,2023-11-08,47,Beauty,3,30,90 +87,2023-11-22,2,Beauty,2,50,100 +88,2023-03-29,15,Clothing,1,500,500 +89,2023-10-01,47,Electronics,4,500,2000 +90,2023-05-06,14,Electronics,1,30,30 +91,2023-03-25,45,Electronics,1,500,500 +92,2023-08-25,37,Electronics,4,30,120 +93,2023-07-14,33,Beauty,4,500,2000 +94,2023-05-19,10,Beauty,2,500,1000 +95,2023-11-24,17,Clothing,2,30,60 +96,2023-12-19,20,Clothing,2,300,600 +97,2023-10-13,20,Beauty,2,500,1000 +98,2023-04-23,4,Beauty,2,50,100 +99,2023-12-17,35,Electronics,4,300,1200 +100,2023-06-16,36,Electronics,1,30,30 +101,2023-01-29,39,Clothing,2,300,600 +102,2023-04-28,6,Beauty,2,25,50 +103,2023-01-17,46,Clothing,1,25,25 +104,2023-06-11,28,Beauty,2,500,1000 +105,2023-07-25,37,Electronics,1,500,500 +106,2023-05-18,46,Clothing,1,50,50 +107,2023-02-03,44,Clothing,4,300,1200 +108,2023-04-19,39,Beauty,3,25,75 +109,2023-10-18,21,Electronics,4,500,2000 +110,2023-06-11,15,Clothing,3,300,900 +111,2023-04-19,11,Electronics,3,500,1500 +112,2023-12-02,23,Clothing,3,500,1500 +113,2023-09-13,11,Electronics,2,25,50 +114,2023-07-22,17,Beauty,4,25,100 +115,2023-11-26,39,Clothing,3,500,1500 +116,2023-08-23,48,Clothing,1,30,30 +117,2023-03-15,41,Electronics,2,500,1000 +118,2023-05-16,44,Electronics,4,500,2000 +119,2023-03-13,23,Clothing,3,50,150 +120,2023-05-07,37,Beauty,1,50,50 +121,2023-10-15,30,Electronics,4,50,200 +122,2023-10-03,11,Electronics,4,30,120 +123,2023-05-15,1,Electronics,2,30,60 +124,2023-10-27,37,Clothing,4,500,2000 +125,2023-08-08,10,Clothing,2,50,100 +126,2023-10-26,4,Clothing,3,30,90 +127,2023-07-24,26,Clothing,2,25,50 +128,2023-07-05,22,Beauty,1,500,500 +129,2023-04-23,1,Beauty,2,300,600 +130,2023-03-12,39,Clothing,1,500,500 +131,2023-09-18,27,Beauty,2,300,600 +132,2023-09-10,10,Electronics,4,50,200 +133,2023-02-16,15,Electronics,3,300,900 +134,2023-01-25,6,Electronics,1,50,50 +135,2023-02-26,22,Clothing,2,25,50 +136,2023-03-20,48,Electronics,2,300,600 +137,2023-11-18,50,Beauty,2,500,1000 +138,2023-03-23,7,Clothing,4,50,200 +139,2023-12-15,33,Beauty,4,500,2000 +140,2023-08-05,34,Electronics,1,30,30 +141,2023-11-02,8,Electronics,1,50,50 +142,2023-02-02,30,Electronics,4,300,1200 +143,2023-07-17,32,Clothing,1,50,50 +144,2023-07-15,41,Beauty,3,500,1500 +145,2023-11-02,46,Clothing,3,25,75 +146,2023-08-28,29,Clothing,4,50,200 +147,2023-09-28,16,Electronics,1,300,300 +148,2023-05-09,42,Clothing,2,30,60 +149,2023-10-11,5,Clothing,3,25,75 +150,2023-01-06,38,Electronics,4,30,120 +151,2023-12-15,45,Clothing,1,50,50 +152,2023-02-28,30,Electronics,4,500,2000 +153,2023-12-16,37,Electronics,2,500,1000 +154,2023-10-02,45,Electronics,3,300,900 +155,2023-05-17,42,Electronics,4,500,2000 +156,2023-11-25,8,Clothing,4,25,100 +157,2023-06-24,47,Electronics,4,500,2000 +158,2023-02-27,41,Electronics,2,300,600 +159,2023-05-31,5,Clothing,4,50,200 +160,2023-08-11,6,Clothing,2,50,100 +161,2023-03-22,22,Beauty,2,500,1000 +162,2023-08-21,22,Clothing,2,30,60 +163,2023-01-02,49,Clothing,3,50,150 +164,2023-05-15,35,Beauty,3,500,1500 +165,2023-09-14,10,Clothing,4,300,1200 +166,2023-04-02,32,Clothing,4,500,2000 +167,2023-09-17,8,Clothing,3,50,150 +168,2023-02-24,44,Clothing,1,300,300 +169,2023-11-17,46,Beauty,3,500,1500 +170,2023-06-02,48,Clothing,2,25,50 +171,2023-11-24,8,Clothing,3,300,900 +172,2023-09-17,18,Beauty,2,25,50 +173,2023-11-08,46,Electronics,4,30,120 +174,2023-04-12,1,Beauty,1,300,300 +175,2023-03-20,18,Electronics,4,25,100 +176,2023-07-11,2,Beauty,2,50,100 +177,2023-03-24,46,Beauty,2,50,100 +178,2023-10-04,5,Clothing,2,30,60 +179,2023-09-29,7,Electronics,1,300,300 +180,2023-01-01,5,Clothing,3,300,900 +181,2023-11-03,50,Electronics,4,300,1200 +182,2023-06-15,44,Beauty,4,30,120 +183,2023-09-08,13,Beauty,3,300,900 +184,2023-01-10,27,Electronics,4,50,200 +185,2023-02-27,22,Clothing,1,25,25 +186,2023-07-05,7,Clothing,4,50,200 +187,2023-06-07,17,Clothing,2,50,100 +188,2023-05-03,45,Clothing,3,25,75 +189,2023-01-30,25,Beauty,1,50,50 +190,2023-05-04,35,Beauty,3,30,90 +191,2023-10-18,5,Beauty,1,25,25 +192,2023-02-10,14,Beauty,2,50,100 +193,2023-02-13,34,Beauty,3,500,1500 +194,2023-09-06,24,Clothing,4,50,200 +195,2023-02-05,36,Clothing,1,30,30 +196,2023-09-30,9,Clothing,3,300,900 +197,2023-03-06,9,Clothing,4,50,200 +198,2023-03-07,3,Beauty,3,300,900 +199,2023-12-04,39,Beauty,3,500,1500 +200,2023-09-01,12,Beauty,3,50,150 +201,2023-10-09,18,Electronics,1,25,25 +202,2023-03-26,2,Clothing,4,300,1200 +203,2023-05-16,3,Clothing,2,500,1000 +204,2023-09-28,9,Beauty,1,25,25 +205,2023-11-07,5,Clothing,1,25,25 +206,2023-08-05,27,Clothing,1,25,25 +207,2023-04-19,23,Beauty,2,25,50 +208,2023-10-04,9,Electronics,4,50,200 +209,2023-12-20,13,Electronics,4,50,200 +210,2023-04-13,13,Electronics,4,50,200 +211,2024-01-01,38,Beauty,3,500,1500 +212,2023-06-09,31,Clothing,3,500,1500 +213,2023-07-24,19,Beauty,3,500,1500 +214,2023-12-10,34,Beauty,2,30,60 +215,2023-11-29,48,Clothing,3,500,1500 +216,2023-07-11,6,Electronics,2,50,100 +217,2023-08-13,40,Electronics,4,50,200 +218,2023-09-22,32,Beauty,3,30,90 +219,2023-08-20,33,Electronics,3,30,90 +220,2023-03-03,12,Beauty,1,500,500 +221,2023-05-07,5,Beauty,2,300,600 +222,2023-04-26,9,Clothing,4,30,120 +223,2023-02-02,31,Clothing,1,25,25 +224,2023-06-23,41,Clothing,1,50,50 +225,2023-01-11,28,Beauty,4,25,100 +226,2023-10-29,45,Clothing,1,50,50 +227,2023-10-11,25,Electronics,2,50,100 +228,2023-04-28,23,Electronics,2,30,60 +229,2023-10-29,7,Beauty,3,30,90 +230,2023-04-23,28,Beauty,1,25,25 +231,2023-01-04,21,Clothing,3,50,150 +232,2023-02-06,1,Beauty,1,25,25 +233,2023-12-29,37,Beauty,2,300,600 +234,2023-11-20,11,Electronics,2,25,50 +235,2023-01-31,49,Electronics,2,500,1000 +236,2023-04-28,4,Clothing,1,25,25 +237,2023-02-04,21,Beauty,2,500,1000 +238,2023-01-17,41,Beauty,1,500,500 +239,2023-06-19,13,Electronics,3,500,1500 +240,2023-02-06,1,Beauty,1,300,300 +241,2023-09-21,1,Electronics,3,25,75 +242,2023-05-02,12,Clothing,1,25,25 +243,2023-05-23,35,Electronics,3,300,900 +244,2023-12-09,29,Beauty,2,50,100 +245,2023-09-06,35,Clothing,3,30,90 +246,2023-04-20,33,Electronics,2,25,50 +247,2023-10-04,2,Electronics,2,30,60 +248,2023-03-09,47,Clothing,3,300,900 +249,2023-10-20,16,Clothing,1,50,50 +250,2023-10-23,21,Electronics,1,50,50 +251,2023-08-31,2,Beauty,4,50,200 +252,2023-05-05,42,Electronics,1,300,300 +253,2023-08-31,9,Clothing,4,500,2000 +254,2023-07-28,37,Electronics,1,500,500 +255,2023-04-08,25,Clothing,1,30,30 +256,2023-02-18,40,Clothing,2,500,1000 +257,2023-02-19,27,Beauty,4,500,2000 +258,2023-12-04,25,Clothing,1,50,50 +259,2023-08-09,13,Clothing,4,50,200 +260,2023-07-01,2,Beauty,2,30,60 +261,2023-08-05,10,Clothing,2,25,50 +262,2023-07-30,32,Beauty,4,30,120 +263,2023-08-28,22,Beauty,2,30,60 +264,2023-01-28,4,Clothing,3,300,900 +265,2023-12-11,4,Clothing,3,300,900 +266,2023-12-01,33,Electronics,2,30,60 +267,2023-11-27,1,Beauty,3,30,90 +268,2023-02-20,6,Electronics,1,30,30 +269,2023-02-01,50,Clothing,4,500,2000 +270,2023-07-26,35,Electronics,1,300,300 +271,2023-06-23,28,Beauty,4,30,120 +272,2023-02-25,34,Electronics,2,50,100 +273,2023-05-08,37,Beauty,1,50,50 +274,2023-04-09,44,Clothing,2,500,1000 +275,2023-04-08,10,Clothing,2,500,1000 +276,2023-10-02,5,Beauty,4,25,100 +277,2023-08-18,27,Clothing,4,25,100 +278,2023-03-13,43,Clothing,4,25,100 +279,2023-08-05,36,Clothing,1,500,500 +280,2023-04-04,5,Clothing,3,500,1500 +281,2023-05-23,30,Beauty,4,500,2000 +282,2023-08-25,31,Electronics,4,50,200 +283,2023-05-08,45,Electronics,1,500,500 +284,2023-02-08,9,Clothing,4,50,200 +285,2023-08-15,12,Electronics,1,25,25 +286,2023-10-09,3,Electronics,2,25,50 +287,2023-02-20,2,Clothing,4,25,100 +288,2023-01-26,28,Clothing,4,30,120 +289,2023-11-30,33,Electronics,2,30,60 +290,2023-10-04,26,Beauty,2,300,600 +291,2023-01-08,32,Clothing,2,300,600 +292,2023-02-17,14,Beauty,4,300,1200 +293,2023-05-02,39,Electronics,3,30,90 +294,2023-03-27,9,Clothing,3,30,90 +295,2023-07-28,31,Beauty,3,300,900 +296,2023-09-06,7,Clothing,4,300,1200 +297,2023-09-04,13,Electronics,2,500,1000 +298,2023-04-20,9,Beauty,4,300,1200 +299,2023-07-25,24,Electronics,2,500,1000 +300,2023-01-31,25,Electronics,4,50,200 +301,2023-03-26,47,Clothing,4,30,120 +302,2023-07-14,1,Beauty,2,300,600 +303,2023-01-02,46,Electronics,3,30,90 +304,2023-07-19,19,Electronics,2,30,60 +305,2023-05-16,48,Beauty,1,30,30 +306,2023-08-21,50,Electronics,1,50,50 +307,2023-05-27,20,Electronics,2,25,50 +308,2023-08-05,45,Beauty,4,300,1200 +309,2023-12-23,12,Beauty,1,25,25 +310,2023-10-12,14,Beauty,1,25,25 +311,2023-12-05,6,Beauty,4,25,100 +312,2023-09-07,42,Clothing,4,30,120 +313,2023-03-21,11,Beauty,3,500,1500 +314,2023-04-08,20,Clothing,4,30,120 +315,2023-06-01,8,Clothing,2,30,60 +316,2023-04-22,2,Clothing,2,25,50 +317,2023-01-30,43,Electronics,3,30,90 +318,2023-10-24,21,Clothing,1,25,25 +319,2023-10-05,1,Clothing,1,500,500 +320,2023-02-01,15,Electronics,4,300,1200 +321,2023-06-10,34,Electronics,2,25,50 +322,2023-01-30,19,Electronics,1,500,500 +323,2023-01-26,29,Beauty,3,300,900 +324,2023-10-27,38,Electronics,3,50,150 +325,2023-09-02,49,Electronics,2,25,50 +326,2023-09-15,32,Clothing,3,25,75 +327,2023-09-29,20,Electronics,3,50,150 +328,2023-03-22,8,Beauty,2,50,100 +329,2023-01-30,29,Electronics,4,25,100 +330,2023-09-18,45,Beauty,4,50,200 +331,2023-02-11,44,Electronics,3,30,90 +332,2023-04-06,41,Electronics,4,300,1200 +333,2023-02-05,46,Electronics,4,300,1200 +334,2023-11-01,33,Electronics,3,300,900 +335,2023-02-04,21,Beauty,4,30,120 +336,2023-12-12,35,Beauty,3,50,150 +337,2023-05-01,7,Clothing,1,500,500 +338,2023-07-26,34,Beauty,2,50,100 +339,2023-03-03,29,Electronics,2,25,50 +340,2023-10-19,16,Clothing,4,300,1200 +341,2023-05-07,4,Clothing,4,50,200 +342,2023-10-24,46,Clothing,4,500,2000 +343,2023-11-01,9,Electronics,2,25,50 +344,2023-01-21,20,Beauty,1,30,30 +345,2023-11-14,45,Electronics,1,30,30 +346,2023-02-11,15,Clothing,2,500,1000 +347,2023-08-03,49,Electronics,1,25,25 +348,2023-12-03,17,Electronics,2,300,600 +349,2023-10-26,2,Beauty,1,50,50 +350,2023-10-17,15,Beauty,3,25,75 +351,2023-09-25,3,Clothing,3,30,90 +352,2023-06-11,37,Electronics,2,500,1000 +353,2023-05-14,36,Electronics,1,500,500 +354,2023-04-15,39,Beauty,4,50,200 +355,2023-12-09,15,Electronics,1,500,500 +356,2023-06-10,45,Electronics,3,500,1500 +357,2023-05-03,14,Electronics,3,25,75 +358,2023-05-16,23,Beauty,1,300,300 +359,2023-07-22,26,Clothing,1,50,50 +360,2023-03-09,40,Clothing,4,25,100 +361,2023-12-10,31,Electronics,4,300,1200 +362,2023-11-27,5,Clothing,1,25,25 +363,2023-06-03,9,Beauty,1,25,25 +364,2023-08-23,17,Beauty,1,500,500 +365,2023-06-11,10,Clothing,1,300,300 +366,2023-02-07,35,Clothing,2,50,100 +367,2023-01-05,26,Electronics,1,50,50 +368,2023-08-23,38,Clothing,4,300,1200 +369,2023-11-15,35,Electronics,3,500,1500 +370,2023-10-16,1,Electronics,2,30,60 +371,2023-02-21,36,Beauty,1,25,25 +372,2023-02-07,29,Beauty,3,500,1500 +373,2023-10-03,22,Beauty,2,300,600 +374,2023-04-20,34,Beauty,3,25,75 +375,2023-09-17,44,Clothing,1,50,50 +376,2023-05-16,15,Beauty,1,30,30 +377,2023-03-09,1,Clothing,4,50,200 +378,2023-06-28,30,Beauty,1,300,300 +379,2023-02-05,26,Clothing,1,25,25 +380,2023-05-06,10,Electronics,2,300,600 +381,2023-07-09,42,Clothing,4,25,100 +382,2023-05-26,15,Clothing,2,500,1000 +383,2023-03-22,50,Beauty,3,30,90 +384,2023-08-13,5,Clothing,1,500,500 +385,2023-10-06,45,Electronics,3,500,1500 +386,2023-12-27,49,Electronics,2,300,600 +387,2023-06-04,26,Beauty,1,30,30 +388,2023-11-10,45,Electronics,1,25,25 +389,2023-12-01,17,Clothing,2,25,50 +390,2023-09-28,42,Electronics,2,50,100 +391,2023-01-05,42,Beauty,2,25,50 +392,2023-12-08,10,Clothing,2,300,600 +393,2023-10-11,8,Beauty,2,500,1000 +394,2023-06-03,15,Clothing,1,500,500 +395,2023-12-06,15,Electronics,2,500,1000 +396,2023-02-23,42,Beauty,1,30,30 +397,2023-03-10,38,Beauty,1,25,25 +398,2023-05-16,3,Clothing,2,300,600 +399,2023-03-01,12,Beauty,2,30,60 +400,2023-02-24,46,Clothing,4,50,200 +401,2023-10-11,21,Clothing,1,300,300 +402,2023-03-21,3,Clothing,2,300,600 +403,2023-05-20,15,Clothing,2,300,600 +404,2023-05-25,17,Electronics,2,500,1000 +405,2023-11-06,16,Clothing,4,300,1200 +406,2023-04-18,39,Beauty,4,25,100 +407,2023-06-25,39,Electronics,3,300,900 +408,2023-04-15,32,Beauty,1,500,500 +409,2023-12-18,8,Electronics,3,300,900 +410,2023-11-21,9,Clothing,2,50,100 +411,2023-05-16,6,Electronics,4,50,200 +412,2023-09-16,14,Electronics,4,500,2000 +413,2023-09-08,5,Beauty,3,25,75 +414,2023-05-09,17,Beauty,4,25,100 +415,2023-01-27,42,Clothing,2,30,60 +416,2023-02-17,18,Electronics,4,500,2000 +417,2023-11-21,14,Electronics,3,300,900 +418,2023-08-05,16,Electronics,2,500,1000 +419,2023-05-22,39,Clothing,3,30,90 +420,2023-01-23,37,Clothing,4,500,2000 +421,2023-01-02,10,Clothing,3,500,1500 +422,2023-06-20,35,Clothing,3,30,90 +423,2023-03-08,23,Clothing,1,25,25 +424,2023-11-23,4,Beauty,4,300,1200 +425,2023-05-15,28,Electronics,4,30,120 +426,2023-03-24,33,Electronics,3,50,150 +427,2023-08-15,43,Electronics,1,25,25 +428,2023-10-10,26,Electronics,4,50,200 +429,2023-12-28,43,Electronics,2,25,50 +430,2023-08-07,9,Electronics,3,300,900 +431,2023-10-15,25,Electronics,4,300,1200 +432,2023-01-05,31,Electronics,2,500,1000 +433,2023-02-27,1,Beauty,4,50,200 +434,2023-02-08,47,Electronics,2,25,50 +435,2023-12-20,22,Beauty,3,300,900 +436,2023-03-18,17,Clothing,4,30,120 +437,2023-10-07,6,Electronics,4,300,1200 +438,2023-01-19,16,Clothing,1,30,30 +439,2023-07-09,30,Clothing,3,25,75 +440,2023-10-26,39,Clothing,2,300,600 +441,2023-10-10,4,Beauty,4,300,1200 +442,2023-03-17,20,Clothing,4,25,100 +443,2023-08-09,34,Clothing,2,300,600 +444,2023-03-07,16,Clothing,3,30,90 +445,2023-01-22,31,Electronics,1,300,300 +446,2023-06-07,47,Electronics,1,50,50 +447,2023-07-06,31,Beauty,4,500,2000 +448,2023-01-21,31,Beauty,2,30,60 +449,2023-07-03,11,Electronics,4,50,200 +450,2023-04-18,4,Beauty,2,25,50 +451,2023-12-16,14,Electronics,1,30,30 +452,2023-05-08,37,Clothing,3,500,1500 +453,2023-12-08,32,Clothing,2,500,1000 +454,2023-02-22,40,Beauty,1,25,25 +455,2023-07-01,4,Electronics,4,25,100 +456,2023-10-14,50,Electronics,2,30,60 +457,2023-07-28,16,Beauty,3,300,900 +458,2023-11-14,30,Electronics,4,25,100 +459,2023-03-21,7,Clothing,4,300,1200 +460,2023-05-02,7,Beauty,1,50,50 +461,2023-03-25,33,Beauty,2,500,1000 +462,2023-04-01,8,Electronics,4,300,1200 +463,2023-07-31,41,Beauty,3,500,1500 +464,2023-01-13,21,Electronics,2,300,600 +465,2023-04-02,3,Electronics,3,50,150 +466,2023-06-20,16,Electronics,4,25,100 +467,2023-07-30,4,Electronics,3,50,150 +468,2023-12-09,26,Electronics,1,25,25 +469,2023-05-08,34,Beauty,3,25,75 +470,2023-05-17,7,Clothing,2,500,1000 +471,2023-03-23,16,Clothing,3,50,150 +472,2023-12-26,16,Beauty,3,300,900 +473,2023-02-25,46,Beauty,1,50,50 +474,2023-07-15,21,Clothing,3,500,1500 +475,2023-01-20,11,Clothing,3,25,75 +476,2023-08-29,49,Clothing,4,500,2000 +477,2023-04-24,19,Clothing,4,30,120 +478,2023-04-13,49,Clothing,2,30,60 +479,2023-08-24,41,Electronics,4,300,1200 +480,2023-06-29,2,Beauty,4,500,2000 +481,2023-06-06,37,Electronics,4,300,1200 +482,2023-04-27,25,Clothing,4,300,1200 +483,2023-04-25,34,Clothing,1,30,30 +484,2023-01-13,49,Clothing,4,300,1200 +485,2023-12-04,41,Electronics,1,30,30 +486,2023-04-09,15,Electronics,1,25,25 +487,2023-07-24,23,Clothing,4,500,2000 +488,2023-06-18,42,Electronics,3,300,900 +489,2023-05-23,39,Electronics,1,30,30 +490,2023-02-05,33,Clothing,3,50,150 +491,2023-05-23,21,Electronics,3,300,900 +492,2023-06-29,25,Beauty,4,25,100 +493,2023-11-25,7,Beauty,2,25,50 +494,2023-09-18,42,Beauty,4,50,200 +495,2023-07-24,12,Beauty,2,30,60 +496,2023-12-14,20,Clothing,2,300,600 +497,2023-10-02,48,Clothing,4,30,120 +498,2023-06-19,4,Clothing,4,25,100 +499,2023-01-15,33,Beauty,2,30,60 +500,2023-03-01,11,Beauty,4,25,100 +501,2023-05-14,23,Electronics,2,30,60 +502,2023-04-02,43,Electronics,3,50,150 +503,2023-10-25,17,Beauty,4,500,2000 +504,2023-05-16,10,Beauty,3,50,150 +505,2023-01-20,28,Beauty,1,50,50 +506,2023-02-25,33,Beauty,3,500,1500 +507,2023-11-02,42,Electronics,3,500,1500 +508,2023-08-11,44,Beauty,2,300,600 +509,2023-06-26,11,Electronics,3,300,900 +510,2023-06-10,27,Beauty,4,50,200 +511,2023-08-12,41,Beauty,2,50,100 +512,2023-11-07,27,Beauty,1,25,25 +513,2023-09-19,15,Electronics,4,25,100 +514,2023-03-01,3,Electronics,1,300,300 +515,2023-07-17,16,Clothing,3,300,900 +516,2023-10-23,20,Beauty,4,25,100 +517,2023-04-08,11,Clothing,4,25,100 +518,2023-05-11,19,Clothing,1,30,30 +519,2023-01-23,22,Electronics,4,30,120 +520,2023-12-29,33,Electronics,4,25,100 +521,2023-08-12,13,Clothing,4,30,120 +522,2023-01-01,27,Beauty,3,500,1500 +523,2023-09-24,19,Electronics,1,300,300 +524,2023-10-03,6,Beauty,4,300,1200 +525,2023-12-18,20,Beauty,2,25,50 +526,2023-12-10,27,Clothing,2,50,100 +527,2023-04-11,23,Clothing,2,25,50 +528,2023-07-06,39,Clothing,2,30,60 +529,2023-08-09,25,Clothing,3,50,150 +530,2023-02-05,12,Electronics,4,30,120 +531,2023-12-07,43,Electronics,1,500,500 +532,2023-06-19,32,Clothing,4,30,120 +533,2023-11-16,10,Electronics,3,500,1500 +534,2023-06-10,12,Clothing,2,500,1000 +535,2023-12-06,44,Beauty,3,30,90 +536,2023-03-05,5,Beauty,4,30,120 +537,2023-06-03,14,Beauty,1,500,500 +538,2023-09-17,27,Clothing,3,50,150 +539,2023-06-08,39,Beauty,1,500,500 +540,2023-12-08,48,Electronics,3,300,900 +541,2023-07-29,29,Beauty,1,500,500 +542,2023-06-17,50,Beauty,1,50,50 +543,2023-07-26,36,Beauty,2,300,600 +544,2023-12-23,14,Electronics,1,25,25 +545,2023-06-01,39,Clothing,2,25,50 +546,2023-10-11,5,Electronics,4,50,200 +547,2023-03-07,37,Clothing,4,500,2000 +548,2023-04-09,38,Clothing,2,30,60 +549,2023-08-04,33,Beauty,2,50,100 +550,2023-12-07,13,Clothing,3,300,900 +551,2023-07-14,47,Electronics,3,300,900 +552,2023-12-13,36,Electronics,3,25,75 +553,2023-03-31,15,Clothing,4,300,1200 +554,2023-11-12,31,Beauty,3,50,150 +555,2023-10-19,45,Beauty,1,300,300 +556,2023-06-04,12,Electronics,1,50,50 +557,2023-07-27,2,Beauty,3,30,90 +558,2023-10-08,33,Clothing,1,25,25 +559,2023-01-01,11,Clothing,4,300,1200 +560,2023-06-05,34,Electronics,1,50,50 +561,2023-05-27,12,Clothing,4,500,2000 +562,2023-04-18,6,Electronics,2,25,50 +563,2023-08-09,33,Clothing,2,30,60 +564,2023-10-24,36,Electronics,2,50,100 +565,2023-11-07,23,Beauty,2,30,60 +566,2023-12-02,39,Clothing,1,30,30 +567,2023-06-14,42,Clothing,3,300,900 +568,2023-08-27,6,Electronics,1,300,300 +569,2023-08-15,38,Electronics,4,50,200 +570,2023-08-15,22,Clothing,1,500,500 +571,2023-12-12,39,Electronics,1,50,50 +572,2023-04-20,50,Clothing,4,500,2000 +573,2023-09-19,32,Beauty,2,30,60 +574,2023-08-31,28,Electronics,2,25,50 +575,2023-03-28,16,Clothing,2,50,100 +576,2023-12-04,48,Beauty,3,50,150 +577,2023-02-13,38,Beauty,4,500,2000 +578,2023-05-26,27,Clothing,4,30,120 +579,2023-09-21,13,Electronics,1,30,30 +580,2023-12-06,4,Clothing,3,500,1500 +581,2023-11-21,41,Beauty,2,30,60 +582,2023-11-14,22,Clothing,3,300,900 +583,2023-06-21,12,Electronics,4,25,100 +584,2023-02-17,38,Beauty,4,50,200 +585,2023-05-01,11,Clothing,1,25,25 +586,2023-12-11,21,Electronics,1,50,50 +587,2023-06-08,1,Beauty,4,300,1200 +588,2023-04-26,45,Electronics,2,30,60 +589,2023-04-12,43,Beauty,2,500,1000 +590,2023-03-17,39,Clothing,3,300,900 +591,2023-01-13,46,Electronics,4,25,100 +592,2023-01-24,16,Beauty,4,500,2000 +593,2023-05-06,27,Electronics,2,30,60 +594,2023-09-01,39,Electronics,2,300,600 +595,2023-11-09,34,Clothing,4,500,2000 +596,2023-02-07,1,Electronics,1,300,300 +597,2023-08-22,44,Beauty,4,300,1200 +598,2023-08-01,25,Beauty,4,30,120 +599,2023-11-19,32,Beauty,2,50,100 +600,2023-10-22,38,Beauty,2,500,1000 +601,2023-04-10,10,Clothing,1,30,30 +602,2023-12-23,1,Electronics,1,300,300 +603,2023-07-16,39,Clothing,3,30,90 +604,2023-09-11,23,Electronics,4,50,200 +605,2023-07-24,30,Electronics,2,500,1000 +606,2023-05-05,39,Electronics,1,50,50 +607,2023-03-17,21,Clothing,3,25,75 +608,2023-12-02,30,Electronics,3,500,1500 +609,2023-12-19,44,Clothing,2,50,100 +610,2023-01-03,1,Beauty,2,300,600 +611,2023-02-24,46,Beauty,3,500,1500 +612,2023-08-06,15,Electronics,1,500,500 +613,2023-04-23,39,Clothing,3,30,90 +614,2023-04-01,50,Beauty,4,300,1200 +615,2023-12-23,36,Clothing,4,25,100 +616,2023-09-23,24,Clothing,2,50,100 +617,2023-08-26,47,Electronics,1,30,30 +618,2023-01-26,26,Beauty,1,50,50 +619,2023-10-13,12,Electronics,4,25,100 +620,2023-05-08,25,Electronics,3,25,75 +621,2023-03-04,42,Beauty,2,500,1000 +622,2023-08-22,45,Beauty,3,25,75 +623,2023-03-10,34,Clothing,3,50,150 +624,2023-08-26,16,Beauty,3,300,900 +625,2023-12-08,29,Clothing,1,300,300 +626,2023-09-29,35,Clothing,4,500,2000 +627,2023-10-14,38,Clothing,1,50,50 +628,2023-11-01,1,Beauty,4,50,200 +629,2023-06-12,13,Electronics,2,25,50 +630,2023-08-15,5,Clothing,2,50,100 +631,2023-11-10,26,Electronics,3,30,90 +632,2023-09-16,48,Electronics,4,25,100 +633,2023-08-07,35,Beauty,4,30,120 +634,2023-10-08,32,Electronics,4,500,2000 +635,2023-08-17,35,Electronics,3,300,900 +636,2023-03-23,27,Beauty,3,500,1500 +637,2023-09-01,12,Clothing,2,300,600 +638,2023-08-19,24,Electronics,1,500,500 +639,2023-05-13,18,Beauty,4,50,200 +640,2023-05-07,27,Electronics,4,30,120 +641,2023-11-23,35,Electronics,1,300,300 +642,2023-05-22,4,Clothing,4,25,100 +643,2023-09-24,38,Electronics,3,30,90 +644,2023-09-06,6,Beauty,3,25,75 +645,2023-11-17,47,Electronics,4,30,120 +646,2023-05-03,26,Clothing,3,30,90 +647,2023-05-21,28,Clothing,3,500,1500 +648,2023-08-14,21,Beauty,4,300,1200 +649,2023-02-09,47,Clothing,2,300,600 +650,2024-01-01,37,Electronics,1,30,30 +651,2023-05-27,49,Clothing,3,50,150 +652,2023-05-01,20,Beauty,2,50,100 +653,2023-05-20,16,Clothing,3,25,75 +654,2023-06-21,50,Clothing,3,25,75 +655,2023-06-13,13,Clothing,1,500,500 +656,2023-10-04,14,Beauty,3,30,90 +657,2023-02-11,38,Clothing,1,25,25 +658,2023-03-12,34,Clothing,1,25,25 +659,2023-03-19,35,Electronics,1,30,30 +660,2023-04-29,34,Beauty,2,500,1000 +661,2023-07-16,8,Clothing,4,25,100 +662,2023-12-22,9,Beauty,2,500,1000 +663,2023-03-20,46,Clothing,4,300,1200 +664,2023-12-28,29,Clothing,4,500,2000 +665,2023-04-20,50,Clothing,1,50,50 +666,2023-02-02,3,Electronics,3,50,150 +667,2023-08-01,31,Electronics,1,500,500 +668,2023-07-28,28,Electronics,3,50,150 +669,2023-06-19,41,Beauty,4,300,1200 +670,2023-10-05,49,Beauty,1,30,30 +671,2023-08-27,41,Electronics,3,50,150 +672,2023-08-01,32,Beauty,2,50,100 +673,2023-02-01,29,Clothing,3,500,1500 +674,2023-04-16,42,Clothing,1,300,300 +675,2023-08-04,7,Clothing,2,30,60 +676,2023-07-19,7,Electronics,3,500,1500 +677,2023-10-27,11,Beauty,3,500,1500 +678,2023-12-23,43,Electronics,3,300,900 +679,2023-01-11,47,Beauty,3,30,90 +680,2023-10-22,47,Clothing,3,300,900 +681,2023-07-14,34,Electronics,2,30,60 +682,2023-09-02,19,Beauty,4,300,1200 +683,2023-01-04,16,Beauty,2,500,1000 +684,2023-06-30,47,Clothing,2,500,1000 +685,2023-06-02,25,Electronics,2,25,50 +686,2023-07-19,40,Electronics,4,50,200 +687,2023-08-03,35,Electronics,1,300,300 +688,2023-10-03,33,Clothing,4,25,100 +689,2023-10-07,14,Electronics,2,50,100 +690,2023-11-05,5,Clothing,3,300,900 +691,2023-04-23,18,Clothing,3,30,90 +692,2023-09-07,5,Clothing,2,50,100 +693,2023-04-23,31,Beauty,3,500,1500 +694,2023-05-20,48,Electronics,2,25,50 +695,2023-08-12,13,Electronics,3,50,150 +696,2023-09-06,3,Clothing,4,50,200 +697,2023-01-15,17,Clothing,1,500,500 +698,2023-07-19,29,Electronics,1,300,300 +699,2023-06-22,7,Clothing,4,30,120 +700,2023-12-09,20,Electronics,4,500,2000 +701,2023-12-14,6,Beauty,2,30,60 +702,2023-07-27,18,Clothing,2,300,600 +703,2023-03-26,38,Electronics,2,50,100 +704,2023-08-28,36,Clothing,3,30,90 +705,2023-03-07,50,Electronics,2,25,50 +706,2023-11-15,37,Electronics,4,25,100 +707,2023-10-01,24,Clothing,1,500,500 +708,2023-01-14,11,Beauty,3,300,900 +709,2023-07-21,17,Electronics,2,500,1000 +710,2023-10-31,24,Electronics,3,500,1500 +711,2023-10-16,15,Electronics,3,500,1500 +712,2023-12-06,28,Beauty,2,25,50 +713,2023-01-14,50,Beauty,3,25,75 +714,2023-02-12,47,Clothing,1,500,500 +715,2023-11-26,1,Beauty,4,25,100 +716,2023-08-08,28,Clothing,4,300,1200 +717,2023-03-11,1,Clothing,1,500,500 +718,2023-08-25,35,Beauty,3,25,75 +719,2023-04-04,39,Clothing,2,30,60 +720,2023-01-26,42,Beauty,3,500,1500 +721,2023-05-14,48,Clothing,1,500,500 +722,2023-07-14,10,Beauty,3,300,900 +723,2023-06-17,48,Beauty,4,50,200 +724,2023-04-19,29,Clothing,3,50,150 +725,2023-08-21,11,Electronics,1,300,300 +726,2023-06-17,50,Clothing,4,300,1200 +727,2023-06-22,47,Beauty,3,300,900 +728,2023-07-14,16,Electronics,3,50,150 +729,2023-05-23,36,Clothing,4,300,1200 +730,2023-08-04,6,Clothing,2,25,50 +731,2023-05-10,50,Clothing,4,500,2000 +732,2023-02-11,21,Electronics,2,500,1000 +733,2023-08-29,35,Beauty,1,30,30 +734,2023-01-10,11,Clothing,1,30,30 +735,2023-10-04,40,Clothing,4,500,2000 +736,2023-01-27,18,Clothing,4,25,100 +737,2023-06-29,49,Clothing,1,50,50 +738,2023-04-25,29,Clothing,2,50,100 +739,2023-11-29,11,Beauty,1,25,25 +740,2023-02-05,8,Beauty,4,50,200 +741,2023-11-30,25,Clothing,1,300,300 +742,2023-01-21,43,Electronics,4,500,2000 +743,2023-01-16,47,Beauty,4,500,2000 +744,2023-05-07,18,Electronics,1,25,25 +745,2023-04-13,4,Beauty,2,50,100 +746,2023-01-11,46,Clothing,3,30,90 +747,2023-11-15,39,Beauty,1,30,30 +748,2023-03-20,14,Clothing,3,50,150 +749,2023-05-03,2,Beauty,1,30,30 +750,2023-03-06,9,Clothing,3,25,75 +751,2023-08-31,3,Clothing,2,25,50 +752,2023-12-09,29,Clothing,2,50,100 +753,2023-02-28,21,Clothing,1,30,30 +754,2023-10-16,47,Electronics,4,25,100 +755,2023-04-22,34,Clothing,3,25,75 +756,2023-08-27,44,Electronics,4,300,1200 +757,2023-12-25,14,Electronics,4,300,1200 +758,2023-05-12,18,Clothing,4,25,100 +759,2023-07-08,21,Electronics,2,50,100 +760,2023-03-27,45,Beauty,1,500,500 +761,2023-11-07,7,Clothing,1,500,500 +762,2023-11-07,39,Electronics,2,25,50 +763,2023-02-28,48,Clothing,2,25,50 +764,2023-03-25,25,Clothing,1,25,25 +765,2023-06-09,29,Clothing,4,50,200 +766,2023-02-25,27,Electronics,3,300,900 +767,2023-10-24,34,Beauty,3,25,75 +768,2023-01-14,41,Beauty,3,25,75 +769,2023-06-09,40,Electronics,4,30,120 +770,2023-10-22,43,Clothing,1,50,50 +771,2023-12-13,47,Electronics,2,25,50 +772,2023-07-12,28,Electronics,1,30,30 +773,2023-07-23,15,Electronics,4,500,2000 +774,2023-04-12,8,Clothing,2,25,50 +775,2023-02-08,47,Electronics,4,25,100 +776,2023-10-31,49,Clothing,3,30,90 +777,2023-12-20,15,Electronics,3,50,150 +778,2023-11-18,48,Beauty,4,25,100 +779,2023-05-05,34,Electronics,2,500,1000 +780,2023-02-22,21,Electronics,2,25,50 +781,2023-12-23,20,Beauty,1,500,500 +782,2023-06-04,11,Clothing,3,300,900 +783,2023-12-17,47,Clothing,1,300,300 +784,2023-11-04,22,Electronics,1,500,500 +785,2023-03-03,22,Beauty,4,50,200 +786,2023-10-17,36,Clothing,4,25,100 +787,2023-01-22,20,Electronics,1,25,25 +788,2023-06-27,34,Beauty,3,300,900 +789,2023-09-30,23,Clothing,4,500,2000 +790,2023-08-08,42,Clothing,1,25,25 +791,2023-12-05,42,Beauty,1,25,25 +792,2023-07-09,22,Beauty,1,50,50 +793,2023-02-05,26,Beauty,1,30,30 +794,2023-09-17,30,Beauty,1,300,300 +795,2023-11-28,44,Electronics,1,300,300 +796,2023-06-24,16,Beauty,4,30,120 +797,2023-01-07,1,Clothing,3,25,75 +798,2023-08-04,38,Clothing,1,50,50 +799,2023-09-08,5,Electronics,2,50,100 +800,2023-02-24,12,Clothing,4,300,1200 +801,2023-08-10,3,Clothing,4,50,200 +802,2023-07-05,13,Beauty,1,30,30 +803,2023-11-22,43,Clothing,4,25,100 +804,2023-08-24,45,Electronics,1,30,30 +805,2023-12-29,42,Beauty,3,500,1500 +806,2023-03-20,16,Beauty,3,300,900 +807,2023-08-11,8,Electronics,4,50,200 +808,2023-04-01,22,Beauty,4,500,2000 +809,2023-09-25,35,Beauty,2,50,100 +810,2023-11-30,12,Electronics,4,25,100 +811,2023-05-19,48,Beauty,2,25,50 +812,2023-11-12,24,Electronics,3,25,75 +813,2023-10-03,50,Electronics,3,50,150 +814,2023-09-05,7,Clothing,1,500,500 +815,2023-08-27,5,Clothing,3,25,75 +816,2023-08-12,39,Beauty,2,500,1000 +817,2023-10-31,23,Beauty,4,50,200 +818,2023-05-18,38,Electronics,1,500,500 +819,2023-06-15,40,Beauty,2,50,100 +820,2023-05-06,19,Electronics,4,50,200 +821,2023-02-14,21,Electronics,1,300,300 +822,2023-05-23,35,Beauty,3,50,150 +823,2023-08-19,33,Electronics,2,50,100 +824,2023-05-05,12,Clothing,4,30,120 +825,2023-08-26,18,Beauty,1,25,25 +826,2023-10-19,25,Clothing,1,300,300 +827,2023-11-09,7,Beauty,3,300,900 +828,2023-12-09,2,Electronics,4,300,1200 +829,2023-07-14,26,Beauty,3,30,90 +830,2023-06-22,13,Clothing,3,50,150 +831,2023-01-15,34,Electronics,4,25,100 +832,2023-09-11,9,Beauty,4,500,2000 +833,2023-06-16,43,Beauty,4,50,200 +834,2023-04-04,29,Beauty,2,30,60 +835,2023-09-07,24,Clothing,4,50,200 +836,2023-04-19,49,Clothing,1,50,50 +837,2023-07-01,8,Beauty,3,30,90 +838,2023-05-13,3,Electronics,2,300,600 +839,2023-06-24,30,Electronics,4,300,1200 +840,2023-05-24,29,Clothing,2,25,50 +841,2023-11-02,20,Electronics,4,25,100 +842,2023-12-26,1,Clothing,2,300,600 +843,2023-05-22,3,Beauty,3,500,1500 +844,2023-10-12,17,Clothing,3,50,150 +845,2023-01-06,30,Clothing,1,500,500 +846,2023-09-22,27,Beauty,1,50,50 +847,2023-04-08,10,Electronics,4,300,1200 +848,2023-02-13,39,Clothing,3,25,75 +849,2023-05-04,28,Clothing,2,25,50 +850,2023-07-28,20,Beauty,2,500,1000 +851,2023-09-08,34,Electronics,2,25,50 +852,2023-10-12,5,Clothing,1,300,300 +853,2023-05-04,46,Beauty,2,500,1000 +854,2023-12-20,19,Clothing,1,50,50 +855,2023-09-01,29,Beauty,1,25,25 +856,2023-11-27,14,Electronics,4,30,120 +857,2023-12-31,6,Electronics,2,25,50 +858,2023-09-09,28,Electronics,2,50,100 +859,2023-08-18,13,Electronics,3,500,1500 +860,2023-01-09,47,Clothing,4,50,200 +861,2023-02-17,16,Clothing,3,30,90 +862,2023-05-31,1,Electronics,4,300,1200 +863,2023-04-24,13,Electronics,2,25,50 +864,2023-07-27,16,Electronics,1,500,500 +865,2023-12-21,12,Clothing,1,300,300 +866,2023-05-05,32,Electronics,1,50,50 +867,2023-06-06,25,Electronics,1,500,500 +868,2023-12-06,27,Electronics,1,300,300 +869,2023-10-25,38,Beauty,3,500,1500 +870,2023-07-08,26,Electronics,4,30,120 +871,2023-08-31,1,Beauty,2,30,60 +872,2023-10-11,27,Beauty,3,25,75 +873,2023-09-29,24,Electronics,4,25,100 +874,2023-06-26,27,Beauty,1,30,30 +875,2023-08-06,41,Electronics,4,500,2000 +876,2023-10-09,40,Clothing,4,30,120 +877,2023-06-19,37,Clothing,1,25,25 +878,2023-06-30,34,Clothing,1,30,30 +879,2023-12-26,35,Clothing,1,30,30 +880,2023-08-21,42,Beauty,2,500,1000 +881,2023-05-19,24,Electronics,1,300,300 +882,2023-06-06,39,Electronics,2,25,50 +883,2023-05-09,24,Electronics,1,500,500 +884,2023-04-29,46,Clothing,2,30,60 +885,2023-03-03,50,Clothing,4,30,120 +886,2023-04-09,29,Electronics,3,300,900 +887,2023-06-11,43,Clothing,4,25,100 +888,2023-03-03,15,Electronics,4,25,100 +889,2023-10-02,25,Electronics,1,50,50 +890,2023-12-20,24,Electronics,2,25,50 +891,2023-04-05,38,Electronics,3,300,900 +892,2023-04-09,32,Electronics,1,50,50 +893,2023-04-21,40,Electronics,1,50,50 +894,2023-09-05,20,Electronics,1,30,30 +895,2023-05-22,24,Clothing,4,30,120 +896,2023-10-29,19,Electronics,2,25,50 +897,2023-09-26,49,Electronics,2,50,100 +898,2023-11-02,33,Clothing,3,30,90 +899,2023-05-25,3,Clothing,2,300,600 +900,2023-02-21,7,Clothing,2,30,60 +901,2023-04-10,32,Electronics,1,30,30 +902,2023-06-01,45,Beauty,1,50,50 +903,2023-04-27,40,Beauty,4,50,200 +904,2023-07-04,24,Clothing,1,500,500 +905,2023-04-02,48,Beauty,1,300,300 +906,2023-06-04,6,Clothing,1,50,50 +907,2023-01-08,46,Electronics,1,25,25 +908,2023-12-29,7,Beauty,4,300,1200 +909,2023-10-01,45,Electronics,1,300,300 +910,2023-03-06,45,Beauty,3,50,150 +911,2023-05-21,3,Electronics,3,300,900 +912,2023-01-24,7,Beauty,3,50,150 +913,2023-01-28,2,Electronics,3,30,90 +914,2023-10-11,41,Electronics,1,500,500 +915,2023-05-30,8,Beauty,3,30,90 +916,2023-12-24,19,Electronics,1,50,50 +917,2023-03-06,30,Electronics,4,50,200 +918,2023-11-23,35,Electronics,3,30,90 +919,2023-09-09,37,Beauty,2,25,50 +920,2023-02-22,10,Beauty,3,25,75 +921,2023-01-07,10,Electronics,3,25,75 +922,2023-10-21,17,Electronics,1,50,50 +923,2023-05-26,14,Beauty,3,300,900 +924,2023-08-29,18,Beauty,2,50,100 +925,2023-09-03,21,Electronics,1,300,300 +926,2023-08-14,21,Electronics,1,30,30 +927,2023-06-24,24,Electronics,4,500,2000 +928,2023-04-05,22,Clothing,4,300,1200 +929,2023-01-27,29,Beauty,3,25,75 +930,2023-05-10,41,Clothing,4,50,200 +931,2023-09-02,8,Beauty,4,30,120 +932,2023-02-28,12,Beauty,4,25,100 +933,2023-02-03,17,Beauty,1,30,30 +934,2023-07-25,20,Beauty,1,500,500 +935,2023-09-09,46,Beauty,1,50,50 +936,2023-02-07,39,Beauty,4,50,200 +937,2023-10-23,8,Beauty,1,500,500 +938,2023-11-19,30,Clothing,4,50,200 +939,2023-12-18,39,Electronics,1,300,300 +940,2023-01-28,7,Electronics,1,30,30 +941,2023-03-19,49,Clothing,2,25,50 +942,2023-03-18,21,Clothing,3,500,1500 +943,2023-10-16,6,Clothing,4,300,1200 +944,2023-06-05,23,Clothing,2,25,50 +945,2023-02-13,34,Beauty,1,25,25 +946,2023-05-08,20,Electronics,4,500,2000 +947,2023-03-02,7,Beauty,1,300,300 +948,2023-10-13,12,Electronics,3,25,75 +949,2023-08-02,11,Electronics,2,25,50 +950,2023-11-07,17,Clothing,3,300,900 +951,2023-11-02,5,Beauty,2,50,100 +952,2023-11-13,41,Clothing,1,25,25 +953,2023-04-26,37,Beauty,3,30,90 +954,2023-09-25,28,Electronics,3,300,900 +955,2023-07-14,45,Clothing,1,25,25 +956,2023-08-19,24,Clothing,3,500,1500 +957,2023-08-15,34,Electronics,4,30,120 +958,2023-06-02,2,Electronics,2,25,50 +959,2023-10-29,49,Electronics,2,30,60 +960,2023-08-08,17,Clothing,2,30,60 +961,2023-06-06,23,Beauty,4,50,200 +962,2023-10-19,50,Clothing,2,30,60 +963,2023-11-14,15,Beauty,1,50,50 +964,2023-01-31,32,Clothing,3,300,900 +965,2023-11-09,16,Clothing,4,50,200 +966,2023-02-20,21,Electronics,2,500,1000 +967,2023-04-17,23,Beauty,1,25,25 +968,2023-11-17,8,Clothing,3,300,900 +969,2023-04-19,8,Clothing,3,300,900 +970,2023-05-16,43,Electronics,4,500,2000 +971,2023-12-05,20,Electronics,4,50,200 +972,2023-02-11,11,Beauty,4,25,100 +973,2023-03-22,50,Clothing,1,50,50 +974,2023-05-03,21,Beauty,1,30,30 +975,2023-03-30,39,Clothing,4,50,200 +976,2023-10-10,18,Beauty,2,300,600 +977,2023-02-08,20,Electronics,3,25,75 +978,2023-03-22,36,Clothing,3,50,150 +979,2023-01-02,38,Beauty,1,25,25 +980,2023-07-29,26,Electronics,3,25,75 +981,2023-08-19,49,Electronics,2,30,60 +982,2023-12-19,4,Beauty,3,30,90 +983,2023-11-01,27,Clothing,1,300,300 +984,2023-08-29,36,Clothing,1,500,500 +985,2023-05-30,38,Electronics,2,25,50 +986,2023-01-17,9,Clothing,2,500,1000 +987,2023-04-29,45,Clothing,3,300,900 +988,2023-05-28,20,Clothing,3,25,75 +989,2023-12-28,31,Electronics,1,25,25 +990,2023-05-25,45,Beauty,2,500,1000 +991,2023-12-26,27,Clothing,2,50,100 +992,2023-08-21,21,Electronics,2,30,60 +993,2023-02-06,20,Electronics,3,50,150 +994,2023-12-18,45,Beauty,2,500,1000 +995,2023-04-30,24,Clothing,1,30,30 +996,2023-05-16,6,Clothing,1,50,50 +997,2023-11-17,35,Beauty,3,30,90 +998,2023-10-29,5,Beauty,4,25,100 +999,2023-12-05,2,Electronics,3,50,150 +1000,2023-04-12,15,Electronics,4,30,120 \ No newline at end of file diff --git a/ai-ml/nl-to-sql/manifests/02-tgi/tgi_.yaml b/ai-ml/nl-to-sql/manifests/02-tgi/tgi_.yaml deleted file mode 100644 index 8720d153e1..0000000000 --- a/ai-ml/nl-to-sql/manifests/02-tgi/tgi_.yaml +++ /dev/null @@ -1,86 +0,0 @@ -# Copyright 2024 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# [START gke_ai_ml_llm_serving_gemma_tgi_2b_it_deployment] -apiVersion: apps/v1 -kind: Deployment -metadata: - name: tgi -spec: - replicas: 1 - selector: - matchLabels: - app: tgi-runtime - template: - metadata: - labels: - app: tgi-runtime - ai.gke.io/model: gemma-2b-it - ai.gke.io/inference-server: text-generation-inference - examples.ai.gke.io/source: user-guide - spec: - containers: - - name: inference-server - image: ghcr.io/huggingface/text-generation-inference:2.0.2 - resources: - requests: - cpu: "2" - memory: "7Gi" - ephemeral-storage: "20Gi" - nvidia.com/gpu: 1 - limits: - cpu: "2" - memory: "7Gi" - ephemeral-storage: "20Gi" - nvidia.com/gpu: 1 - args: - - --model-id=$(MODEL_ID) - - --num-shard=1 - - --max-total-tokens=3072 - - --max-batch-prefill-tokens=1024 - - --max-input-length=1024 - env: - - name: MODEL_ID - #value: google/gemma-2b-it - value: google/gemma-7b-it - - name: PORT - value: "8000" - - name: HUGGING_FACE_HUB_TOKEN - valueFrom: - secretKeyRef: - name: hf-secret - key: hf_api_token - volumeMounts: - - mountPath: /dev/shm - name: dshm - volumes: - - name: dshm - emptyDir: - medium: Memory - nodeSelector: - cloud.google.com/gke-accelerator: nvidia-l4 ---- -apiVersion: v1 -kind: Service -metadata: - name: llm-service -spec: - selector: - app: tgi-runtime - type: ClusterIP - ports: - - protocol: TCP - port: 8000 - targetPort: 8000 -# [END gke_ai_ml_llm_serving_gemma_tgi_2b_it_deployment] diff --git a/ai-ml/nl-to-sql/manifests/02-tgi/tgi.yaml b/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml similarity index 100% rename from ai-ml/nl-to-sql/manifests/02-tgi/tgi.yaml rename to ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml diff --git a/ai-ml/nl-to-sql/manifests/03-client/client-pod.yaml b/ai-ml/nl-to-sql/manifests/04-notebook/client-pod.yaml similarity index 100% rename from ai-ml/nl-to-sql/manifests/03-client/client-pod.yaml rename to ai-ml/nl-to-sql/manifests/04-notebook/client-pod.yaml diff --git a/ai-ml/nl-to-sql/manifests/03-client/script.py b/ai-ml/nl-to-sql/manifests/04-notebook/script.py similarity index 100% rename from ai-ml/nl-to-sql/manifests/03-client/script.py rename to ai-ml/nl-to-sql/manifests/04-notebook/script.py From 601365b6c1f9c9a973a18e6f3fdaa50efefb11d3 Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Mon, 20 May 2024 11:57:25 +0200 Subject: [PATCH 08/28] update --- .../manifests/04-notebook/Untitled.ipynb | 380 ++++++++++++++++++ .../manifests/04-notebook/client-pod.yaml | 45 --- .../manifests/04-notebook/jupyter.yaml | 79 ++++ 3 files changed, 459 insertions(+), 45 deletions(-) create mode 100644 ai-ml/nl-to-sql/manifests/04-notebook/Untitled.ipynb delete mode 100644 ai-ml/nl-to-sql/manifests/04-notebook/client-pod.yaml create mode 100644 ai-ml/nl-to-sql/manifests/04-notebook/jupyter.yaml diff --git a/ai-ml/nl-to-sql/manifests/04-notebook/Untitled.ipynb b/ai-ml/nl-to-sql/manifests/04-notebook/Untitled.ipynb new file mode 100644 index 0000000000..8051b3f65b --- /dev/null +++ b/ai-ml/nl-to-sql/manifests/04-notebook/Untitled.ipynb @@ -0,0 +1,380 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "30c2a1af-87a5-444d-b3d5-9eec9e1050e4", + "metadata": {}, + "source": [ + "Install deps" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "43180104-2132-4102-aa77-e450217724df", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Collecting psycopg-binary\n", + " Downloading psycopg_binary-3.1.19-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (2.8 kB)\n", + "Collecting psycopg\n", + " Downloading psycopg-3.1.19-py3-none-any.whl.metadata (4.2 kB)\n", + "Collecting tabulate\n", + " Downloading tabulate-0.9.0-py3-none-any.whl.metadata (34 kB)\n", + "Collecting text-generation\n", + " Downloading text_generation-0.7.0-py3-none-any.whl.metadata (8.5 kB)\n", + "Collecting langchain\n", + " Downloading langchain-0.2.0-py3-none-any.whl.metadata (13 kB)\n", + "Collecting langchain-community\n", + " Downloading langchain_community-0.2.0-py3-none-any.whl.metadata (8.8 kB)\n", + "Requirement already satisfied: typing-extensions>=4.1 in /usr/local/lib/python3.11/dist-packages (from psycopg) (4.8.0)\n", + "Collecting aiohttp<4.0,>=3.8 (from text-generation)\n", + " Downloading aiohttp-3.9.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (7.5 kB)\n", + "Collecting huggingface-hub<1.0,>=0.12 (from text-generation)\n", + " Downloading huggingface_hub-0.23.0-py3-none-any.whl.metadata (12 kB)\n", + "Collecting pydantic<3,>2 (from text-generation)\n", + " Downloading pydantic-2.7.1-py3-none-any.whl.metadata (107 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m107.3/107.3 kB\u001b[0m \u001b[31m2.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: PyYAML>=5.3 in /usr/local/lib/python3.11/dist-packages (from langchain) (6.0.1)\n", + "Collecting SQLAlchemy<3,>=1.4 (from langchain)\n", + " Downloading SQLAlchemy-2.0.30-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (9.6 kB)\n", + "Collecting dataclasses-json<0.7,>=0.5.7 (from langchain)\n", + " Downloading dataclasses_json-0.6.6-py3-none-any.whl.metadata (25 kB)\n", + "Collecting langchain-core<0.3.0,>=0.2.0 (from langchain)\n", + " Downloading langchain_core-0.2.0-py3-none-any.whl.metadata (5.9 kB)\n", + "Collecting langchain-text-splitters<0.3.0,>=0.2.0 (from langchain)\n", + " Downloading langchain_text_splitters-0.2.0-py3-none-any.whl.metadata (2.2 kB)\n", + "Collecting langsmith<0.2.0,>=0.1.17 (from langchain)\n", + " Downloading langsmith-0.1.59-py3-none-any.whl.metadata (13 kB)\n", + "Requirement already satisfied: numpy<2,>=1 in /usr/local/lib/python3.11/dist-packages (from langchain) (1.26.2)\n", + "Requirement already satisfied: requests<3,>=2 in /usr/local/lib/python3.11/dist-packages (from langchain) (2.31.0)\n", + "Collecting tenacity<9.0.0,>=8.1.0 (from langchain)\n", + " Downloading tenacity-8.3.0-py3-none-any.whl.metadata (1.2 kB)\n", + "Collecting aiosignal>=1.1.2 (from aiohttp<4.0,>=3.8->text-generation)\n", + " Downloading aiosignal-1.3.1-py3-none-any.whl.metadata (4.0 kB)\n", + "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp<4.0,>=3.8->text-generation) (23.1.0)\n", + "Collecting frozenlist>=1.1.1 (from aiohttp<4.0,>=3.8->text-generation)\n", + " Downloading frozenlist-1.4.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (12 kB)\n", + "Collecting multidict<7.0,>=4.5 (from aiohttp<4.0,>=3.8->text-generation)\n", + " Downloading multidict-6.0.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (4.2 kB)\n", + "Collecting yarl<2.0,>=1.0 (from aiohttp<4.0,>=3.8->text-generation)\n", + " Downloading yarl-1.9.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (31 kB)\n", + "Collecting marshmallow<4.0.0,>=3.18.0 (from dataclasses-json<0.7,>=0.5.7->langchain)\n", + " Downloading marshmallow-3.21.2-py3-none-any.whl.metadata (7.1 kB)\n", + "Collecting typing-inspect<1,>=0.4.0 (from dataclasses-json<0.7,>=0.5.7->langchain)\n", + " Downloading typing_inspect-0.9.0-py3-none-any.whl.metadata (1.5 kB)\n", + "Collecting filelock (from huggingface-hub<1.0,>=0.12->text-generation)\n", + " Downloading filelock-3.14.0-py3-none-any.whl.metadata (2.8 kB)\n", + "Collecting fsspec>=2023.5.0 (from huggingface-hub<1.0,>=0.12->text-generation)\n", + " Downloading fsspec-2024.5.0-py3-none-any.whl.metadata (11 kB)\n", + "Requirement already satisfied: packaging>=20.9 in /usr/local/lib/python3.11/dist-packages (from huggingface-hub<1.0,>=0.12->text-generation) (23.2)\n", + "Collecting tqdm>=4.42.1 (from huggingface-hub<1.0,>=0.12->text-generation)\n", + " Downloading tqdm-4.66.4-py3-none-any.whl.metadata (57 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m57.6/57.6 kB\u001b[0m \u001b[31m6.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting jsonpatch<2.0,>=1.33 (from langchain-core<0.3.0,>=0.2.0->langchain)\n", + " Downloading jsonpatch-1.33-py2.py3-none-any.whl.metadata (3.0 kB)\n", + "Collecting orjson<4.0.0,>=3.9.14 (from langsmith<0.2.0,>=0.1.17->langchain)\n", + " Downloading orjson-3.10.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (49 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.7/49.7 kB\u001b[0m \u001b[31m5.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting annotated-types>=0.4.0 (from pydantic<3,>2->text-generation)\n", + " Downloading annotated_types-0.6.0-py3-none-any.whl.metadata (12 kB)\n", + "Collecting pydantic-core==2.18.2 (from pydantic<3,>2->text-generation)\n", + " Downloading pydantic_core-2.18.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (6.5 kB)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests<3,>=2->langchain) (3.3.2)\n", + "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests<3,>=2->langchain) (3.4)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests<3,>=2->langchain) (2.1.0)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/dist-packages (from requests<3,>=2->langchain) (2023.11.17)\n", + "Collecting greenlet!=0.4.17 (from SQLAlchemy<3,>=1.4->langchain)\n", + " Downloading greenlet-3.0.3-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.metadata (3.8 kB)\n", + "Requirement already satisfied: jsonpointer>=1.9 in /usr/local/lib/python3.11/dist-packages (from jsonpatch<2.0,>=1.33->langchain-core<0.3.0,>=0.2.0->langchain) (2.4)\n", + "Collecting mypy-extensions>=0.3.0 (from typing-inspect<1,>=0.4.0->dataclasses-json<0.7,>=0.5.7->langchain)\n", + " Downloading mypy_extensions-1.0.0-py3-none-any.whl.metadata (1.1 kB)\n", + "Downloading psycopg_binary-3.1.19-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.3/3.3 MB\u001b[0m \u001b[31m21.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", + "\u001b[?25hDownloading psycopg-3.1.19-py3-none-any.whl (179 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m179.4/179.4 kB\u001b[0m \u001b[31m20.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading tabulate-0.9.0-py3-none-any.whl (35 kB)\n", + "Downloading text_generation-0.7.0-py3-none-any.whl (12 kB)\n", + "Downloading langchain-0.2.0-py3-none-any.whl (973 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m973.7/973.7 kB\u001b[0m \u001b[31m54.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading langchain_community-0.2.0-py3-none-any.whl (2.1 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.1/2.1 MB\u001b[0m \u001b[31m64.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading aiohttp-3.9.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.3/1.3 MB\u001b[0m \u001b[31m56.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading dataclasses_json-0.6.6-py3-none-any.whl (28 kB)\n", + "Downloading huggingface_hub-0.23.0-py3-none-any.whl (401 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m401.2/401.2 kB\u001b[0m \u001b[31m29.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading langchain_core-0.2.0-py3-none-any.whl (307 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m307.9/307.9 kB\u001b[0m \u001b[31m22.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading langchain_text_splitters-0.2.0-py3-none-any.whl (23 kB)\n", + "Downloading langsmith-0.1.59-py3-none-any.whl (121 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m121.2/121.2 kB\u001b[0m \u001b[31m14.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading pydantic-2.7.1-py3-none-any.whl (409 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m409.3/409.3 kB\u001b[0m \u001b[31m35.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading pydantic_core-2.18.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.1/2.1 MB\u001b[0m \u001b[31m56.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m\n", + "\u001b[?25hDownloading SQLAlchemy-2.0.30-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.2/3.2 MB\u001b[0m \u001b[31m63.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m\n", + "\u001b[?25hDownloading tenacity-8.3.0-py3-none-any.whl (25 kB)\n", + "Downloading aiosignal-1.3.1-py3-none-any.whl (7.6 kB)\n", + "Downloading annotated_types-0.6.0-py3-none-any.whl (12 kB)\n", + "Downloading frozenlist-1.4.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (272 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m272.3/272.3 kB\u001b[0m \u001b[31m26.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading fsspec-2024.5.0-py3-none-any.whl (316 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m316.1/316.1 kB\u001b[0m \u001b[31m30.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading greenlet-3.0.3-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (620 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m620.0/620.0 kB\u001b[0m \u001b[31m47.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading jsonpatch-1.33-py2.py3-none-any.whl (12 kB)\n", + "Downloading marshmallow-3.21.2-py3-none-any.whl (49 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.3/49.3 kB\u001b[0m \u001b[31m6.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading multidict-6.0.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (128 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m128.7/128.7 kB\u001b[0m \u001b[31m13.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading orjson-3.10.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (142 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m142.5/142.5 kB\u001b[0m \u001b[31m8.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading tqdm-4.66.4-py3-none-any.whl (78 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m78.3/78.3 kB\u001b[0m \u001b[31m9.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading typing_inspect-0.9.0-py3-none-any.whl (8.8 kB)\n", + "Downloading yarl-1.9.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (328 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m328.1/328.1 kB\u001b[0m \u001b[31m27.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading filelock-3.14.0-py3-none-any.whl (12 kB)\n", + "Downloading mypy_extensions-1.0.0-py3-none-any.whl (4.7 kB)\n", + "Installing collected packages: tqdm, tenacity, tabulate, pydantic-core, psycopg-binary, psycopg, orjson, mypy-extensions, multidict, marshmallow, jsonpatch, greenlet, fsspec, frozenlist, filelock, annotated-types, yarl, typing-inspect, SQLAlchemy, pydantic, huggingface-hub, aiosignal, langsmith, dataclasses-json, aiohttp, text-generation, langchain-core, langchain-text-splitters, langchain, langchain-community\n", + "Successfully installed SQLAlchemy-2.0.30 aiohttp-3.9.5 aiosignal-1.3.1 annotated-types-0.6.0 dataclasses-json-0.6.6 filelock-3.14.0 frozenlist-1.4.1 fsspec-2024.5.0 greenlet-3.0.3 huggingface-hub-0.23.0 jsonpatch-1.33 langchain-0.2.0 langchain-community-0.2.0 langchain-core-0.2.0 langchain-text-splitters-0.2.0 langsmith-0.1.59 marshmallow-3.21.2 multidict-6.0.5 mypy-extensions-1.0.0 orjson-3.10.3 psycopg-3.1.19 psycopg-binary-3.1.19 pydantic-2.7.1 pydantic-core-2.18.2 tabulate-0.9.0 tenacity-8.3.0 text-generation-0.7.0 tqdm-4.66.4 typing-inspect-0.9.0 yarl-1.9.4\n", + "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n", + "\u001b[0m\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython3 -m pip install --upgrade pip\u001b[0m\n" + ] + } + ], + "source": [ + "! pip install psycopg-binary psycopg tabulate text-generation langchain langchain-community" + ] + }, + { + "cell_type": "markdown", + "id": "156bc717-4f17-4578-a088-d6a33ec5f9a0", + "metadata": {}, + "source": [ + "import all" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "9ad1f62d-38df-4a8c-a656-8dfe80df2c1f", + "metadata": {}, + "outputs": [], + "source": [ + "import psycopg\n", + "import os\n", + "from tabulate import tabulate\n", + "from langchain_community.llms import HuggingFaceTextGenInference\n", + "from langchain_core.prompts import PromptTemplate" + ] + }, + { + "cell_type": "markdown", + "id": "68641d9c-a10c-414b-8156-827d42431edc", + "metadata": {}, + "source": [ + "Postgres things" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "5154583e-aa74-41ce-860f-6c7f000f6fab", + "metadata": {}, + "outputs": [], + "source": [ + "conn = psycopg.connect(\n", + "\tdbname=os.environ.get(\"DATABASE_NAME\"),\n", + "\thost=os.environ.get(\"POSTGRES_URL\"),\n", + "\tuser=os.environ.get(\"OWNERUSERNAME\"),\n", + "\tpassword=os.environ.get(\"OWNERPASSWORD\"),\n", + "\tautocommit=True)\n", + "\n", + "db_schema = conn.execute(\"SELECT table_name, column_name as Columns, data_type as DataTypes FROM information_schema.columns where table_name NOT LIKE 'pg_stat%' AND table_schema='public' order by table_name,column_name;\")\n", + "colnames = [desc[0] for desc in db_schema.description]\n", + "db_schema_formatted=tabulate(db_schema.fetchall(), headers=colnames, tablefmt='psql')" + ] + }, + { + "cell_type": "markdown", + "id": "53a23197-5c73-4f37-b577-7973789663f0", + "metadata": {}, + "source": [ + "llm things" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "16f7c910-a5c5-4d7c-8045-cccd3517366e", + "metadata": {}, + "outputs": [], + "source": [ + "llm = HuggingFaceTextGenInference(\n", + " #inference_server_url=os.environ.get(\"LLM_ENDPOINT\"),\n", + " # my mistake, i wrote wrong url in the jupyter envs so lets use hardcoded version now\n", + " # i really dont want to restart notebook right now\n", + " inference_server_url=\"http://llm-service.llm:8000\",\n", + " temperature=0.5,\n", + " top_k=10,\n", + " top_p=0.5,\n", + " repetition_penalty=1.03,\n", + ")\n", + "\n", + "sql_prompt_template = PromptTemplate.from_template(\"\"\"\n", + "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n", + "You are a helpful AI assistant that can transform user queries into SQL commands to retrieve the data from the Postgresql database. The database has the next tables schema:\n", + "{db_schema}\n", + "\n", + "Please prepare and return only the SQL command, based on the user query, without any formatting or newlines. The answer must contain only valid SQL command.<|eot_id|><|start_header_id|>user<|end_header_id|>\n", + "{query}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n", + "\"\"\")\n", + "\n", + "final_prompt_template = PromptTemplate.from_template(\"\"\"\n", + "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n", + "You are a helpful AI assistant that can understand Postgresql replies and explain this data to the user. The database has the next tables schema:\n", + "{db_schema}\n", + "\n", + "User query: {query}\n", + "\n", + "Postgresql reply:\n", + "{postgres_reply}\n", + "\n", + "Base your answer on the provided user query and Postgresql reply.\n", + "Generate a draft response using the selected information.\n", + "It should be easy to understand your answer. Don't add any introductory words, start answering right away. \n", + "Keep your answer to a one or two sentences (if possible) that specifically answers the user's question. If not - try to keep the answer short, summarizing the returned data.\n", + "Generate your final response after adjusting it to increase accuracy and relevance.\n", + "Now only show your final response!\n", + "If you do not know the answer or context is not relevant, response with \"I don't know\".\n", + "<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n", + "\"\"\")" + ] + }, + { + "cell_type": "markdown", + "id": "e82286bb-f01a-4a6c-b75c-3fc9ce08b90e", + "metadata": {}, + "source": [ + "handle_query function with all app logic" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "49cf0c45-f74e-448d-b990-6a30248e74d9", + "metadata": {}, + "outputs": [], + "source": [ + "def handle_query(query):\n", + " sql_query=llm.invoke(sql_prompt_template.format(db_schema=db_schema_formatted, query=query))\n", + " try:\n", + " postgres_reply = conn.execute(sql_query)\n", + " except psycopg.Error as e:\n", + " print(\"Unable to process query: \", query)\n", + " return \"Try another query\"\n", + " colnames = [desc[0] for desc in postgres_reply.description]\n", + " postgres_reply_data = postgres_reply.fetchall()\n", + " if postgres_reply_data == []:\n", + " return \"Received empty SQL answer, try another query\"\n", + " postgres_reply_formatted=tabulate(postgres_reply_data, headers=colnames, tablefmt='psql')\n", + " # debug section\n", + " # print(sql_query)\n", + " # print(postgres_reply_formatted)\n", + " # end of debug section\n", + " return llm.invoke(final_prompt_template.format(db_schema=db_schema_formatted, query=query, postgres_reply=postgres_reply_formatted))" + ] + }, + { + "cell_type": "markdown", + "id": "f41369f8-1c6c-4276-bbbd-16f65577121a", + "metadata": {}, + "source": [ + "ask something" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "6707f47a-c2ef-45a1-9512-eb7e357e431a", + "metadata": {}, + "outputs": [ + { + "ename": "InvalidURL", + "evalue": "Failed to parse: http://llm-service.llm:8000=", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/urllib3/util/url.py:425\u001b[0m, in \u001b[0;36mparse_url\u001b[0;34m(url)\u001b[0m\n\u001b[1;32m 424\u001b[0m auth \u001b[38;5;241m=\u001b[39m auth \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m--> 425\u001b[0m host, port \u001b[38;5;241m=\u001b[39m \u001b[43m_HOST_PORT_RE\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmatch\u001b[49m\u001b[43m(\u001b[49m\u001b[43mhost_port\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgroups\u001b[49m() \u001b[38;5;66;03m# type: ignore[union-attr]\u001b[39;00m\n\u001b[1;32m 426\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m auth \u001b[38;5;129;01mand\u001b[39;00m normalize_uri:\n", + "\u001b[0;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'groups'", + "\nThe above exception was the direct cause of the following exception:\n", + "\u001b[0;31mLocationParseError\u001b[0m Traceback (most recent call last)", + "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/requests/models.py:434\u001b[0m, in \u001b[0;36mPreparedRequest.prepare_url\u001b[0;34m(self, url, params)\u001b[0m\n\u001b[1;32m 433\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 434\u001b[0m scheme, auth, host, port, path, query, fragment \u001b[38;5;241m=\u001b[39m \u001b[43mparse_url\u001b[49m\u001b[43m(\u001b[49m\u001b[43murl\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 435\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m LocationParseError \u001b[38;5;28;01mas\u001b[39;00m e:\n", + "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/urllib3/util/url.py:451\u001b[0m, in \u001b[0;36mparse_url\u001b[0;34m(url)\u001b[0m\n\u001b[1;32m 450\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m (\u001b[38;5;167;01mValueError\u001b[39;00m, \u001b[38;5;167;01mAttributeError\u001b[39;00m) \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m--> 451\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m LocationParseError(source_url) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01me\u001b[39;00m\n\u001b[1;32m 453\u001b[0m \u001b[38;5;66;03m# For the sake of backwards compatibility we put empty\u001b[39;00m\n\u001b[1;32m 454\u001b[0m \u001b[38;5;66;03m# string values for path if there are any defined values\u001b[39;00m\n\u001b[1;32m 455\u001b[0m \u001b[38;5;66;03m# beyond the path in the URL.\u001b[39;00m\n\u001b[1;32m 456\u001b[0m \u001b[38;5;66;03m# TODO: Remove this when we break backwards compatibility.\u001b[39;00m\n", + "\u001b[0;31mLocationParseError\u001b[0m: Failed to parse: http://llm-service.llm:8000=", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[0;31mInvalidURL\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[7], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mhandle_query\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mPlease calculate the total sum of all John transactions.\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m)\n", + "Cell \u001b[0;32mIn[5], line 2\u001b[0m, in \u001b[0;36mhandle_query\u001b[0;34m(query)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mhandle_query\u001b[39m(query):\n\u001b[0;32m----> 2\u001b[0m sql_query\u001b[38;5;241m=\u001b[39m\u001b[43mllm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minvoke\u001b[49m\u001b[43m(\u001b[49m\u001b[43msql_prompt_template\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mformat\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdb_schema\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdb_schema_formatted\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mquery\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mquery\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 4\u001b[0m postgres_reply \u001b[38;5;241m=\u001b[39m conn\u001b[38;5;241m.\u001b[39mexecute(sql_query)\n", + "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/langchain_core/language_models/llms.py:276\u001b[0m, in \u001b[0;36mBaseLLM.invoke\u001b[0;34m(self, input, config, stop, **kwargs)\u001b[0m\n\u001b[1;32m 266\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21minvoke\u001b[39m(\n\u001b[1;32m 267\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 268\u001b[0m \u001b[38;5;28minput\u001b[39m: LanguageModelInput,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 272\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any,\n\u001b[1;32m 273\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28mstr\u001b[39m:\n\u001b[1;32m 274\u001b[0m config \u001b[38;5;241m=\u001b[39m ensure_config(config)\n\u001b[1;32m 275\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m (\n\u001b[0;32m--> 276\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate_prompt\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 277\u001b[0m \u001b[43m \u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_convert_input\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 278\u001b[0m \u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 279\u001b[0m \u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mcallbacks\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 280\u001b[0m \u001b[43m \u001b[49m\u001b[43mtags\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mtags\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 281\u001b[0m \u001b[43m \u001b[49m\u001b[43mmetadata\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmetadata\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 282\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_name\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mrun_name\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 283\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_id\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpop\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mrun_id\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 284\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 285\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 286\u001b[0m \u001b[38;5;241m.\u001b[39mgenerations[\u001b[38;5;241m0\u001b[39m][\u001b[38;5;241m0\u001b[39m]\n\u001b[1;32m 287\u001b[0m \u001b[38;5;241m.\u001b[39mtext\n\u001b[1;32m 288\u001b[0m )\n", + "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/langchain_core/language_models/llms.py:633\u001b[0m, in \u001b[0;36mBaseLLM.generate_prompt\u001b[0;34m(self, prompts, stop, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m 625\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mgenerate_prompt\u001b[39m(\n\u001b[1;32m 626\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 627\u001b[0m prompts: List[PromptValue],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 630\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any,\n\u001b[1;32m 631\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m LLMResult:\n\u001b[1;32m 632\u001b[0m prompt_strings \u001b[38;5;241m=\u001b[39m [p\u001b[38;5;241m.\u001b[39mto_string() \u001b[38;5;28;01mfor\u001b[39;00m p \u001b[38;5;129;01min\u001b[39;00m prompts]\n\u001b[0;32m--> 633\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprompt_strings\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/langchain_core/language_models/llms.py:803\u001b[0m, in \u001b[0;36mBaseLLM.generate\u001b[0;34m(self, prompts, stop, callbacks, tags, metadata, run_name, run_id, **kwargs)\u001b[0m\n\u001b[1;32m 788\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcache \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m get_llm_cache() \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m) \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcache \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mFalse\u001b[39;00m:\n\u001b[1;32m 789\u001b[0m run_managers \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 790\u001b[0m callback_manager\u001b[38;5;241m.\u001b[39mon_llm_start(\n\u001b[1;32m 791\u001b[0m dumpd(\u001b[38;5;28mself\u001b[39m),\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 801\u001b[0m )\n\u001b[1;32m 802\u001b[0m ]\n\u001b[0;32m--> 803\u001b[0m output \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate_helper\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 804\u001b[0m \u001b[43m \u001b[49m\u001b[43mprompts\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_managers\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mbool\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mnew_arg_supported\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\n\u001b[1;32m 805\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 806\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m output\n\u001b[1;32m 807\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(missing_prompts) \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n", + "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/langchain_core/language_models/llms.py:670\u001b[0m, in \u001b[0;36mBaseLLM._generate_helper\u001b[0;34m(self, prompts, stop, run_managers, new_arg_supported, **kwargs)\u001b[0m\n\u001b[1;32m 668\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m run_manager \u001b[38;5;129;01min\u001b[39;00m run_managers:\n\u001b[1;32m 669\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_llm_error(e, response\u001b[38;5;241m=\u001b[39mLLMResult(generations\u001b[38;5;241m=\u001b[39m[]))\n\u001b[0;32m--> 670\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[1;32m 671\u001b[0m flattened_outputs \u001b[38;5;241m=\u001b[39m output\u001b[38;5;241m.\u001b[39mflatten()\n\u001b[1;32m 672\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m manager, flattened_output \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(run_managers, flattened_outputs):\n", + "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/langchain_core/language_models/llms.py:657\u001b[0m, in \u001b[0;36mBaseLLM._generate_helper\u001b[0;34m(self, prompts, stop, run_managers, new_arg_supported, **kwargs)\u001b[0m\n\u001b[1;32m 647\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_generate_helper\u001b[39m(\n\u001b[1;32m 648\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 649\u001b[0m prompts: List[\u001b[38;5;28mstr\u001b[39m],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 653\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any,\n\u001b[1;32m 654\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m LLMResult:\n\u001b[1;32m 655\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 656\u001b[0m output \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m--> 657\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 658\u001b[0m \u001b[43m \u001b[49m\u001b[43mprompts\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 659\u001b[0m \u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 660\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# TODO: support multiple run managers\u001b[39;49;00m\n\u001b[1;32m 661\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_managers\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mrun_managers\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 662\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 663\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 664\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[1;32m 665\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_generate(prompts, stop\u001b[38;5;241m=\u001b[39mstop)\n\u001b[1;32m 666\u001b[0m )\n\u001b[1;32m 667\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 668\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m run_manager \u001b[38;5;129;01min\u001b[39;00m run_managers:\n", + "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/langchain_core/language_models/llms.py:1317\u001b[0m, in \u001b[0;36mLLM._generate\u001b[0;34m(self, prompts, stop, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m 1314\u001b[0m new_arg_supported \u001b[38;5;241m=\u001b[39m inspect\u001b[38;5;241m.\u001b[39msignature(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call)\u001b[38;5;241m.\u001b[39mparameters\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrun_manager\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 1315\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m prompt \u001b[38;5;129;01min\u001b[39;00m prompts:\n\u001b[1;32m 1316\u001b[0m text \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m-> 1317\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1318\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[1;32m 1319\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call(prompt, stop\u001b[38;5;241m=\u001b[39mstop, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m 1320\u001b[0m )\n\u001b[1;32m 1321\u001b[0m generations\u001b[38;5;241m.\u001b[39mappend([Generation(text\u001b[38;5;241m=\u001b[39mtext)])\n\u001b[1;32m 1322\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m LLMResult(generations\u001b[38;5;241m=\u001b[39mgenerations)\n", + "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/langchain_community/llms/huggingface_text_gen_inference.py:202\u001b[0m, in \u001b[0;36mHuggingFaceTextGenInference._call\u001b[0;34m(self, prompt, stop, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m 199\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m completion\n\u001b[1;32m 201\u001b[0m invocation_params \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_invocation_params(stop, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m--> 202\u001b[0m res \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mclient\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43minvocation_params\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 203\u001b[0m \u001b[38;5;66;03m# remove stop sequences from the end of the generated text\u001b[39;00m\n\u001b[1;32m 204\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m stop_seq \u001b[38;5;129;01min\u001b[39;00m invocation_params[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mstop_sequences\u001b[39m\u001b[38;5;124m\"\u001b[39m]:\n", + "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/text_generation/client.py:275\u001b[0m, in \u001b[0;36mClient.generate\u001b[0;34m(self, prompt, do_sample, max_new_tokens, best_of, repetition_penalty, frequency_penalty, return_full_text, seed, stop_sequences, temperature, top_k, top_p, truncate, typical_p, watermark, decoder_input_details, top_n_tokens, grammar)\u001b[0m\n\u001b[1;32m 253\u001b[0m parameters \u001b[38;5;241m=\u001b[39m Parameters(\n\u001b[1;32m 254\u001b[0m best_of\u001b[38;5;241m=\u001b[39mbest_of,\n\u001b[1;32m 255\u001b[0m details\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 271\u001b[0m grammar\u001b[38;5;241m=\u001b[39mgrammar,\n\u001b[1;32m 272\u001b[0m )\n\u001b[1;32m 273\u001b[0m request \u001b[38;5;241m=\u001b[39m Request(inputs\u001b[38;5;241m=\u001b[39mprompt, stream\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m, parameters\u001b[38;5;241m=\u001b[39mparameters)\n\u001b[0;32m--> 275\u001b[0m resp \u001b[38;5;241m=\u001b[39m \u001b[43mrequests\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpost\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 276\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbase_url\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 277\u001b[0m \u001b[43m \u001b[49m\u001b[43mjson\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdict\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 278\u001b[0m \u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 279\u001b[0m \u001b[43m \u001b[49m\u001b[43mcookies\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcookies\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 280\u001b[0m \u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtimeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 281\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 282\u001b[0m payload \u001b[38;5;241m=\u001b[39m resp\u001b[38;5;241m.\u001b[39mjson()\n\u001b[1;32m 283\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m resp\u001b[38;5;241m.\u001b[39mstatus_code \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m200\u001b[39m:\n", + "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/requests/api.py:115\u001b[0m, in \u001b[0;36mpost\u001b[0;34m(url, data, json, **kwargs)\u001b[0m\n\u001b[1;32m 103\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mpost\u001b[39m(url, data\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, json\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 104\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124;03m\"\"\"Sends a POST request.\u001b[39;00m\n\u001b[1;32m 105\u001b[0m \n\u001b[1;32m 106\u001b[0m \u001b[38;5;124;03m :param url: URL for the new :class:`Request` object.\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 112\u001b[0m \u001b[38;5;124;03m :rtype: requests.Response\u001b[39;00m\n\u001b[1;32m 113\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 115\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mrequest\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mpost\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mjson\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mjson\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/requests/api.py:59\u001b[0m, in \u001b[0;36mrequest\u001b[0;34m(method, url, **kwargs)\u001b[0m\n\u001b[1;32m 55\u001b[0m \u001b[38;5;66;03m# By using the 'with' statement we are sure the session is closed, thus we\u001b[39;00m\n\u001b[1;32m 56\u001b[0m \u001b[38;5;66;03m# avoid leaving sockets open which can trigger a ResourceWarning in some\u001b[39;00m\n\u001b[1;32m 57\u001b[0m \u001b[38;5;66;03m# cases, and look like a memory leak in others.\u001b[39;00m\n\u001b[1;32m 58\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m sessions\u001b[38;5;241m.\u001b[39mSession() \u001b[38;5;28;01mas\u001b[39;00m session:\n\u001b[0;32m---> 59\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43msession\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmethod\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/requests/sessions.py:575\u001b[0m, in \u001b[0;36mSession.request\u001b[0;34m(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)\u001b[0m\n\u001b[1;32m 562\u001b[0m \u001b[38;5;66;03m# Create the Request.\u001b[39;00m\n\u001b[1;32m 563\u001b[0m req \u001b[38;5;241m=\u001b[39m Request(\n\u001b[1;32m 564\u001b[0m method\u001b[38;5;241m=\u001b[39mmethod\u001b[38;5;241m.\u001b[39mupper(),\n\u001b[1;32m 565\u001b[0m url\u001b[38;5;241m=\u001b[39murl,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 573\u001b[0m hooks\u001b[38;5;241m=\u001b[39mhooks,\n\u001b[1;32m 574\u001b[0m )\n\u001b[0;32m--> 575\u001b[0m prep \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mprepare_request\u001b[49m\u001b[43m(\u001b[49m\u001b[43mreq\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 577\u001b[0m proxies \u001b[38;5;241m=\u001b[39m proxies \u001b[38;5;129;01mor\u001b[39;00m {}\n\u001b[1;32m 579\u001b[0m settings \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmerge_environment_settings(\n\u001b[1;32m 580\u001b[0m prep\u001b[38;5;241m.\u001b[39murl, proxies, stream, verify, cert\n\u001b[1;32m 581\u001b[0m )\n", + "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/requests/sessions.py:486\u001b[0m, in \u001b[0;36mSession.prepare_request\u001b[0;34m(self, request)\u001b[0m\n\u001b[1;32m 483\u001b[0m auth \u001b[38;5;241m=\u001b[39m get_netrc_auth(request\u001b[38;5;241m.\u001b[39murl)\n\u001b[1;32m 485\u001b[0m p \u001b[38;5;241m=\u001b[39m PreparedRequest()\n\u001b[0;32m--> 486\u001b[0m \u001b[43mp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mprepare\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 487\u001b[0m \u001b[43m \u001b[49m\u001b[43mmethod\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmethod\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mupper\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 488\u001b[0m \u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 489\u001b[0m \u001b[43m \u001b[49m\u001b[43mfiles\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfiles\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 490\u001b[0m \u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 491\u001b[0m \u001b[43m \u001b[49m\u001b[43mjson\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mjson\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 492\u001b[0m \u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmerge_setting\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 493\u001b[0m \u001b[43m \u001b[49m\u001b[43mrequest\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdict_class\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mCaseInsensitiveDict\u001b[49m\n\u001b[1;32m 494\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 495\u001b[0m \u001b[43m \u001b[49m\u001b[43mparams\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmerge_setting\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrequest\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mparams\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mparams\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 496\u001b[0m \u001b[43m \u001b[49m\u001b[43mauth\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmerge_setting\u001b[49m\u001b[43m(\u001b[49m\u001b[43mauth\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mauth\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 497\u001b[0m \u001b[43m \u001b[49m\u001b[43mcookies\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmerged_cookies\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 498\u001b[0m \u001b[43m \u001b[49m\u001b[43mhooks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmerge_hooks\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrequest\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mhooks\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mhooks\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 499\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 500\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m p\n", + "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/requests/models.py:368\u001b[0m, in \u001b[0;36mPreparedRequest.prepare\u001b[0;34m(self, method, url, headers, files, data, params, auth, cookies, hooks, json)\u001b[0m\n\u001b[1;32m 365\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Prepares the entire request with the given parameters.\"\"\"\u001b[39;00m\n\u001b[1;32m 367\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprepare_method(method)\n\u001b[0;32m--> 368\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mprepare_url\u001b[49m\u001b[43m(\u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mparams\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 369\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprepare_headers(headers)\n\u001b[1;32m 370\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprepare_cookies(cookies)\n", + "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/requests/models.py:436\u001b[0m, in \u001b[0;36mPreparedRequest.prepare_url\u001b[0;34m(self, url, params)\u001b[0m\n\u001b[1;32m 434\u001b[0m scheme, auth, host, port, path, query, fragment \u001b[38;5;241m=\u001b[39m parse_url(url)\n\u001b[1;32m 435\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m LocationParseError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m--> 436\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m InvalidURL(\u001b[38;5;241m*\u001b[39me\u001b[38;5;241m.\u001b[39margs)\n\u001b[1;32m 438\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m scheme:\n\u001b[1;32m 439\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m MissingSchema(\n\u001b[1;32m 440\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid URL \u001b[39m\u001b[38;5;132;01m{\u001b[39;00murl\u001b[38;5;132;01m!r}\u001b[39;00m\u001b[38;5;124m: No scheme supplied. \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 441\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPerhaps you meant https://\u001b[39m\u001b[38;5;132;01m{\u001b[39;00murl\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m?\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 442\u001b[0m )\n", + "\u001b[0;31mInvalidURL\u001b[0m: Failed to parse: http://llm-service.llm:8000=" + ] + } + ], + "source": [ + "print(handle_query(\"Please calculate the total sum of all John transactions.\"))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dfc72471-e4cf-4f42-9721-d22c5939a64a", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.0rc1" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/ai-ml/nl-to-sql/manifests/04-notebook/client-pod.yaml b/ai-ml/nl-to-sql/manifests/04-notebook/client-pod.yaml deleted file mode 100644 index 8470ed76fd..0000000000 --- a/ai-ml/nl-to-sql/manifests/04-notebook/client-pod.yaml +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2023 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -apiVersion: v1 -kind: Pod -metadata: - name: client - annotations: - cluster-autoscaler.kubernetes.io/safe-to-evict: "true" -spec: - restartPolicy: Never - containers: - - name: client - image: python:3.11 - command: [ "/bin/bash", "-c", "--" ] - args: [ "while true; do sleep 30; done;" ] - env: - - name: OWNERPASSWORD - valueFrom: - secretKeyRef: - name: mydatabaseowner.my-cluster.credentials.postgresql.acid.zalan.do - key: password - - name: OWNERUSERNAME - valueFrom: - secretKeyRef: - name: mydatabaseowner.my-cluster.credentials.postgresql.acid.zalan.do - key: username - - name: POSTGRES_URL - value: my-cluster.postgres - - name: DATABASE_NAME - value: mydatabase - - name: LLM_ENDPOINT - value: http://llm-service.llm:8000 - diff --git a/ai-ml/nl-to-sql/manifests/04-notebook/jupyter.yaml b/ai-ml/nl-to-sql/manifests/04-notebook/jupyter.yaml new file mode 100644 index 0000000000..b29e9f040b --- /dev/null +++ b/ai-ml/nl-to-sql/manifests/04-notebook/jupyter.yaml @@ -0,0 +1,79 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START gke_databases_postgres_pgvector_02_notebook] +--- +apiVersion: v1 +kind: Service +metadata: + labels: &labels + app: jupyter-notebook + name: notebook +spec: + ports: + - port: 8888 + selector: *labels + #type: LoadBalancer + type: ClusterIP +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: notebook + labels: &labels + app: jupyter-notebook +spec: + selector: + matchLabels: *labels + template: + metadata: + labels: *labels + spec: + containers: + - name: jupyter + image: tensorflow/tensorflow:2.15.0-jupyter + resources: + requests: + memory: "800Mi" + cpu: "1" + limits: + memory: "800Mi" + cpu: "1" + ports: + - containerPort: 8888 + env: + - name: OWNERPASSWORD + valueFrom: + secretKeyRef: + name: mydatabaseowner.my-cluster.credentials.postgresql.acid.zalan.do + key: password + - name: OWNERUSERNAME + valueFrom: + secretKeyRef: + name: mydatabaseowner.my-cluster.credentials.postgresql.acid.zalan.do + key: username + - name: POSTGRES_URL + value: my-cluster.postgres + - name: DATABASE_NAME + value: mydatabase + - name: LLM_ENDPOINT + value: http://llm-service.llm:8000/ +# volumeMounts: +# - name: notebook +# mountPath: /tf +# volumes: +# - name: notebook +# configMap: +# name: notebook + # [END gke_databases_postgres_pgvector_02_notebook] From 44ce1f0b85ee0a907ea509547fbb66c0dff730c6 Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Tue, 21 May 2024 16:57:34 +0200 Subject: [PATCH 09/28] updates --- ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml | 2 +- .../manifests/04-notebook/client.yaml | 30 +++++++ .../manifests/04-notebook/openai_script.py | 84 +++++++++++++++++++ .../nl-to-sql/manifests/04-notebook/script.py | 75 +++++++++-------- 4 files changed, 156 insertions(+), 35 deletions(-) create mode 100644 ai-ml/nl-to-sql/manifests/04-notebook/client.yaml create mode 100644 ai-ml/nl-to-sql/manifests/04-notebook/openai_script.py diff --git a/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml b/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml index 3635cd9c8a..3d9561665b 100644 --- a/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml +++ b/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml @@ -26,7 +26,7 @@ spec: metadata: labels: app: tgi-runtime - ai.gke.io/model: gemma-2b-it + ai.gke.io/model: llama-3-8b ai.gke.io/inference-server: text-generation-inference examples.ai.gke.io/source: user-guide spec: diff --git a/ai-ml/nl-to-sql/manifests/04-notebook/client.yaml b/ai-ml/nl-to-sql/manifests/04-notebook/client.yaml new file mode 100644 index 0000000000..e013159f28 --- /dev/null +++ b/ai-ml/nl-to-sql/manifests/04-notebook/client.yaml @@ -0,0 +1,30 @@ +apiVersion: v1 +kind: Pod +metadata: + name: client + annotations: + cluster-autoscaler.kubernetes.io/safe-to-evict: "true" +spec: + restartPolicy: Never + containers: + - name: client + image: python:3.11 + command: [ "/bin/bash", "-c", "--" ] + args: [ "while true; do sleep 30; done;" ] + env: + - name: OWNERPASSWORD + valueFrom: + secretKeyRef: + name: mydatabaseowner.my-cluster.credentials.postgresql.acid.zalan.do + key: password + - name: OWNERUSERNAME + valueFrom: + secretKeyRef: + name: mydatabaseowner.my-cluster.credentials.postgresql.acid.zalan.do + key: username + - name: POSTGRES_URL + value: my-cluster.postgres + - name: DATABASE_NAME + value: mydatabase + - name: LLM_ENDPOINT + value: http://llm-service.llm:8000/ diff --git a/ai-ml/nl-to-sql/manifests/04-notebook/openai_script.py b/ai-ml/nl-to-sql/manifests/04-notebook/openai_script.py new file mode 100644 index 0000000000..f39117dd23 --- /dev/null +++ b/ai-ml/nl-to-sql/manifests/04-notebook/openai_script.py @@ -0,0 +1,84 @@ +import psycopg +import os +from tabulate import tabulate +from langchain_core.prompts import ChatPromptTemplate +from langchain_openai import ChatOpenAI + +conn = psycopg.connect( + dbname=os.environ.get("DATABASE_NAME"), + host=os.environ.get("POSTGRES_URL"), + user=os.environ.get("OWNERUSERNAME"), + password=os.environ.get("OWNERPASSWORD"), + autocommit=True) + +db_schema = conn.execute("SELECT table_name, column_name as Columns, data_type as DataTypes FROM information_schema.columns where table_name NOT LIKE 'pg_stat%' AND table_schema='public' order by table_name,column_name;") +colnames = [desc[0] for desc in db_schema.description] +db_schema_formatted=tabulate(db_schema.fetchall(), headers=colnames, tablefmt='psql') + +llm = ChatOpenAI( + openai_api_base=os.environ.get("LLM_ENDPOINT"), + temperature=0.5, + openai_api_key="placeholder", + model="dganochenko/llama-3-8b-chat") + +sql_prompt_template = ChatPromptTemplate.from_messages( + [ + ("system", """ + You are a helpful AI assistant that can transform user queries into SQL commands to retrieve the data from the Postgresql database. The database has the next tables schema: + {db_schema} + Please prepare and return only the SQL command, based on the user query, without any formatting or newlines. The answer must contain only valid SQL command. + """), + ("human", "{query}"), + ] +) + +final_prompt_template = ChatPromptTemplate.from_messages( + [ + ("system", """ + You are a helpful AI assistant that can understand Postgresql replies and explain this data to the user. The database has the next tables schema: + {db_schema} + Postgresql reply: + {postgres_reply} + Base your answer on the provided user query and Postgresql reply. + Generate a draft response using the selected information. + It should be easy to understand your answer. Don't add any introductory words, start answering right away. + Keep your answer to a one or two sentences (if possible) that specifically answers the user's question. If not - try to keep the answer short, summarizing the returned data. + Generate your final response after adjusting it to increase accuracy and relevance. + Now only show your final response! + If you do not know the answer or context is not relevant, response with "I don't know". + """), + ("human", "{query}"), + ] +) + +def postgres_query(query): + try: + postgres_reply = conn.execute(query) + except psycopg.Error as e: + print("Unable to process query") + return False + colnames = [desc[0] for desc in postgres_reply.description] + postgres_reply_data = postgres_reply.fetchall() + if postgres_reply_data == []: + print("Received empty SQL answer") + return False + postgres_reply_formatted=tabulate(postgres_reply_data, headers=colnames, tablefmt='psql') + return postgres_reply_formatted + + +def handle_query(query): + sql_prompt_value=sql_prompt_template.format_messages(db_schema=db_schema_formatted, query=query) + sql_query=llm.invoke(sql_prompt_value).content + print(sql_query) + postgres_reply=postgres_query(sql_query) + if postgres_reply == False: + return "Try another query" + print(postgres_reply) + final_prompt_value=final_prompt_template.format_messages(db_schema=db_schema_formatted, query=query, postgres_reply=postgres_reply) + return llm.invoke(final_prompt_value).content + +print(handle_query("Please calculate the total sum of all John transactions.")) +print(handle_query("Which woman spent more money in 2023 and how much?")) +print(handle_query("Who let the dogs out?")) +print(handle_query("Who bought more electronics in last month?")) +print(handle_query("Who bought more electronics in 10 last months?")) diff --git a/ai-ml/nl-to-sql/manifests/04-notebook/script.py b/ai-ml/nl-to-sql/manifests/04-notebook/script.py index 509fa5e10a..58e02885ef 100644 --- a/ai-ml/nl-to-sql/manifests/04-notebook/script.py +++ b/ai-ml/nl-to-sql/manifests/04-notebook/script.py @@ -18,60 +18,67 @@ llm = HuggingFaceTextGenInference( inference_server_url=os.environ.get("LLM_ENDPOINT"), temperature=0.5, - top_k=10, + top_k=5, top_p=0.5, repetition_penalty=1.03, ) sql_prompt_template = PromptTemplate.from_template(""" -<|begin_of_text|><|start_header_id|>system<|end_header_id|> -You are a helpful AI assistant that can transform user queries into SQL commands to retrieve the data from the Postgresql database. The database has the next tables schema: -{db_schema} - -Please prepare and return only the SQL command, based on the user query, without any formatting or newlines. The answer must contain only valid SQL command.<|eot_id|><|start_header_id|>user<|end_header_id|> -{query}<|eot_id|><|start_header_id|>assistant<|end_header_id|> + <|begin_of_text|><|start_header_id|>system<|end_header_id|> + You are a helpful AI assistant that can transform user queries into SQL commands to retrieve the data from the Postgresql database. The database has the next tables schema: + {db_schema} + Please prepare and return only the SQL command, based on the user query, without any formatting or newlines. The answer must contain only valid SQL command.<|eot_id|><|start_header_id|>user<|end_header_id|> + {query}<|eot_id|><|start_header_id|>assistant<|end_header_id|> """) final_prompt_template = PromptTemplate.from_template(""" -<|begin_of_text|><|start_header_id|>system<|end_header_id|> -You are a helpful AI assistant that can understand Postgresql replies and explain this data to the user. The database has the next tables schema: -{db_schema} - -User query: {query} - -Postgresql reply: -{postgres_reply} - -Base your answer on the provided user query and Postgresql reply. -Generate a draft response using the selected information. -It should be easy to understand your answer. Don't add any introductory words, start answering right away. -Keep your answer to a one or two sentences (if possible) that specifically answers the user's question. If not - try to keep the answer short, summarizing the returned data. -Generate your final response after adjusting it to increase accuracy and relevance. -Now only show your final response! -If you do not know the answer or context is not relevant, response with "I don't know". -<|eot_id|><|start_header_id|>assistant<|end_header_id|> + <|begin_of_text|><|start_header_id|>system<|end_header_id|> + You are a helpful AI assistant that can understand Postgresql replies and explain this data to the user. The database has the next tables schema: + {db_schema} + User query: {query} + Postgresql reply: + {postgres_reply} + Base your answer on the provided user query and Postgresql reply. + Generate a draft response using the selected information. + It should be easy to understand your answer. Don't add any introductory words, start answering right away. + Keep your answer to a one or two sentences (if possible) that specifically answers the user's question. If not - try to keep the answer short, summarizing the returned data. + Generate your final response after adjusting it to increase accuracy and relevance. + Now only show your final response! + If you do not know the answer or context is not relevant, response with "I don't know". + <|eot_id|><|start_header_id|>assistant<|end_header_id|> """) -def handle_query(query): - sql_query=llm.invoke(sql_prompt_template.format(db_schema=db_schema_formatted, query=query)) + +def postgres_query(query): try: - postgres_reply = conn.execute(sql_query) + postgres_reply = conn.execute(query) except psycopg.Error as e: - print("Unable to process query: ", query) - return "Try another query" + print("Unable to process query") + return False colnames = [desc[0] for desc in postgres_reply.description] postgres_reply_data = postgres_reply.fetchall() if postgres_reply_data == []: - return "Received empty SQL answer, try another query" + print("Received empty SQL answer") + return False postgres_reply_formatted=tabulate(postgres_reply_data, headers=colnames, tablefmt='psql') - # debug section + return postgres_reply_formatted + + +def handle_query(query): + sql_prompt_value=sql_prompt_template.format(db_schema=db_schema_formatted, query=query) + sql_query=llm.invoke(sql_prompt_value) # print(sql_query) - # print(postgres_reply_formatted) - # end of debug section - return llm.invoke(final_prompt_template.format(db_schema=db_schema_formatted, query=query, postgres_reply=postgres_reply_formatted)) + postgres_reply=postgres_query(sql_query) + if postgres_reply == False: + return "Try another query" + # print(postgres_reply) + final_prompt_value=final_prompt_template.format(db_schema=db_schema_formatted, query=query, postgres_reply=postgres_reply) + return llm.invoke(final_prompt_value) + print(handle_query("Please calculate the total sum of all John transactions.")) print(handle_query("Which woman spent more money in 2023 and how much?")) print(handle_query("Who let the dogs out?")) print(handle_query("Who bought more electronics in last month?")) print(handle_query("Who bought more electronics in 10 last months?")) +print(handle_query("Give me top 3 buyers of clothing. How much money each person spent?")) From 1bf728054d282476ff5d28d7b5e2f02842045e57 Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Tue, 21 May 2024 16:58:57 +0200 Subject: [PATCH 10/28] update script --- ai-ml/nl-to-sql/manifests/04-notebook/script.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ai-ml/nl-to-sql/manifests/04-notebook/script.py b/ai-ml/nl-to-sql/manifests/04-notebook/script.py index 58e02885ef..5e086392e3 100644 --- a/ai-ml/nl-to-sql/manifests/04-notebook/script.py +++ b/ai-ml/nl-to-sql/manifests/04-notebook/script.py @@ -64,7 +64,7 @@ def postgres_query(query): return postgres_reply_formatted -def handle_query(query): +def llm_query(query): sql_prompt_value=sql_prompt_template.format(db_schema=db_schema_formatted, query=query) sql_query=llm.invoke(sql_prompt_value) # print(sql_query) @@ -76,9 +76,9 @@ def handle_query(query): return llm.invoke(final_prompt_value) -print(handle_query("Please calculate the total sum of all John transactions.")) -print(handle_query("Which woman spent more money in 2023 and how much?")) -print(handle_query("Who let the dogs out?")) -print(handle_query("Who bought more electronics in last month?")) -print(handle_query("Who bought more electronics in 10 last months?")) -print(handle_query("Give me top 3 buyers of clothing. How much money each person spent?")) +print(llm_query("Please calculate the total sum of all John transactions.")) +print(llm_query("Which woman spent more money in 2023 and how much?")) +print(llm_query("Who let the dogs out?")) +print(llm_query("Who bought more electronics in last month?")) +print(llm_query("Who bought more electronics in 10 last months?")) +print(llm_query("Give me top 3 buyers of clothing. How much money each person spent?")) From 473460ec4ab19ecd36f2c3704bbed661289df95d Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Thu, 23 May 2024 12:38:00 +0200 Subject: [PATCH 11/28] updates --- .../manifests/04-notebook/Untitled.ipynb | 380 ----------- .../manifests/04-notebook/client.yaml | 30 - .../manifests/04-notebook/notebook.ipynb | 606 ++++++++++++++++++ .../manifests/04-notebook/openai_script.py | 84 --- .../nl-to-sql/manifests/04-notebook/script.py | 6 +- 5 files changed, 609 insertions(+), 497 deletions(-) delete mode 100644 ai-ml/nl-to-sql/manifests/04-notebook/Untitled.ipynb delete mode 100644 ai-ml/nl-to-sql/manifests/04-notebook/client.yaml create mode 100644 ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb delete mode 100644 ai-ml/nl-to-sql/manifests/04-notebook/openai_script.py diff --git a/ai-ml/nl-to-sql/manifests/04-notebook/Untitled.ipynb b/ai-ml/nl-to-sql/manifests/04-notebook/Untitled.ipynb deleted file mode 100644 index 8051b3f65b..0000000000 --- a/ai-ml/nl-to-sql/manifests/04-notebook/Untitled.ipynb +++ /dev/null @@ -1,380 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "30c2a1af-87a5-444d-b3d5-9eec9e1050e4", - "metadata": {}, - "source": [ - "Install deps" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "43180104-2132-4102-aa77-e450217724df", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Collecting psycopg-binary\n", - " Downloading psycopg_binary-3.1.19-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (2.8 kB)\n", - "Collecting psycopg\n", - " Downloading psycopg-3.1.19-py3-none-any.whl.metadata (4.2 kB)\n", - "Collecting tabulate\n", - " Downloading tabulate-0.9.0-py3-none-any.whl.metadata (34 kB)\n", - "Collecting text-generation\n", - " Downloading text_generation-0.7.0-py3-none-any.whl.metadata (8.5 kB)\n", - "Collecting langchain\n", - " Downloading langchain-0.2.0-py3-none-any.whl.metadata (13 kB)\n", - "Collecting langchain-community\n", - " Downloading langchain_community-0.2.0-py3-none-any.whl.metadata (8.8 kB)\n", - "Requirement already satisfied: typing-extensions>=4.1 in /usr/local/lib/python3.11/dist-packages (from psycopg) (4.8.0)\n", - "Collecting aiohttp<4.0,>=3.8 (from text-generation)\n", - " Downloading aiohttp-3.9.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (7.5 kB)\n", - "Collecting huggingface-hub<1.0,>=0.12 (from text-generation)\n", - " Downloading huggingface_hub-0.23.0-py3-none-any.whl.metadata (12 kB)\n", - "Collecting pydantic<3,>2 (from text-generation)\n", - " Downloading pydantic-2.7.1-py3-none-any.whl.metadata (107 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m107.3/107.3 kB\u001b[0m \u001b[31m2.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n", - "\u001b[?25hRequirement already satisfied: PyYAML>=5.3 in /usr/local/lib/python3.11/dist-packages (from langchain) (6.0.1)\n", - "Collecting SQLAlchemy<3,>=1.4 (from langchain)\n", - " Downloading SQLAlchemy-2.0.30-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (9.6 kB)\n", - "Collecting dataclasses-json<0.7,>=0.5.7 (from langchain)\n", - " Downloading dataclasses_json-0.6.6-py3-none-any.whl.metadata (25 kB)\n", - "Collecting langchain-core<0.3.0,>=0.2.0 (from langchain)\n", - " Downloading langchain_core-0.2.0-py3-none-any.whl.metadata (5.9 kB)\n", - "Collecting langchain-text-splitters<0.3.0,>=0.2.0 (from langchain)\n", - " Downloading langchain_text_splitters-0.2.0-py3-none-any.whl.metadata (2.2 kB)\n", - "Collecting langsmith<0.2.0,>=0.1.17 (from langchain)\n", - " Downloading langsmith-0.1.59-py3-none-any.whl.metadata (13 kB)\n", - "Requirement already satisfied: numpy<2,>=1 in /usr/local/lib/python3.11/dist-packages (from langchain) (1.26.2)\n", - "Requirement already satisfied: requests<3,>=2 in /usr/local/lib/python3.11/dist-packages (from langchain) (2.31.0)\n", - "Collecting tenacity<9.0.0,>=8.1.0 (from langchain)\n", - " Downloading tenacity-8.3.0-py3-none-any.whl.metadata (1.2 kB)\n", - "Collecting aiosignal>=1.1.2 (from aiohttp<4.0,>=3.8->text-generation)\n", - " Downloading aiosignal-1.3.1-py3-none-any.whl.metadata (4.0 kB)\n", - "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp<4.0,>=3.8->text-generation) (23.1.0)\n", - "Collecting frozenlist>=1.1.1 (from aiohttp<4.0,>=3.8->text-generation)\n", - " Downloading frozenlist-1.4.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (12 kB)\n", - "Collecting multidict<7.0,>=4.5 (from aiohttp<4.0,>=3.8->text-generation)\n", - " Downloading multidict-6.0.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (4.2 kB)\n", - "Collecting yarl<2.0,>=1.0 (from aiohttp<4.0,>=3.8->text-generation)\n", - " Downloading yarl-1.9.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (31 kB)\n", - "Collecting marshmallow<4.0.0,>=3.18.0 (from dataclasses-json<0.7,>=0.5.7->langchain)\n", - " Downloading marshmallow-3.21.2-py3-none-any.whl.metadata (7.1 kB)\n", - "Collecting typing-inspect<1,>=0.4.0 (from dataclasses-json<0.7,>=0.5.7->langchain)\n", - " Downloading typing_inspect-0.9.0-py3-none-any.whl.metadata (1.5 kB)\n", - "Collecting filelock (from huggingface-hub<1.0,>=0.12->text-generation)\n", - " Downloading filelock-3.14.0-py3-none-any.whl.metadata (2.8 kB)\n", - "Collecting fsspec>=2023.5.0 (from huggingface-hub<1.0,>=0.12->text-generation)\n", - " Downloading fsspec-2024.5.0-py3-none-any.whl.metadata (11 kB)\n", - "Requirement already satisfied: packaging>=20.9 in /usr/local/lib/python3.11/dist-packages (from huggingface-hub<1.0,>=0.12->text-generation) (23.2)\n", - "Collecting tqdm>=4.42.1 (from huggingface-hub<1.0,>=0.12->text-generation)\n", - " Downloading tqdm-4.66.4-py3-none-any.whl.metadata (57 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m57.6/57.6 kB\u001b[0m \u001b[31m6.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hCollecting jsonpatch<2.0,>=1.33 (from langchain-core<0.3.0,>=0.2.0->langchain)\n", - " Downloading jsonpatch-1.33-py2.py3-none-any.whl.metadata (3.0 kB)\n", - "Collecting orjson<4.0.0,>=3.9.14 (from langsmith<0.2.0,>=0.1.17->langchain)\n", - " Downloading orjson-3.10.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (49 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.7/49.7 kB\u001b[0m \u001b[31m5.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hCollecting annotated-types>=0.4.0 (from pydantic<3,>2->text-generation)\n", - " Downloading annotated_types-0.6.0-py3-none-any.whl.metadata (12 kB)\n", - "Collecting pydantic-core==2.18.2 (from pydantic<3,>2->text-generation)\n", - " Downloading pydantic_core-2.18.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (6.5 kB)\n", - "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests<3,>=2->langchain) (3.3.2)\n", - "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests<3,>=2->langchain) (3.4)\n", - "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests<3,>=2->langchain) (2.1.0)\n", - "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/dist-packages (from requests<3,>=2->langchain) (2023.11.17)\n", - "Collecting greenlet!=0.4.17 (from SQLAlchemy<3,>=1.4->langchain)\n", - " Downloading greenlet-3.0.3-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.metadata (3.8 kB)\n", - "Requirement already satisfied: jsonpointer>=1.9 in /usr/local/lib/python3.11/dist-packages (from jsonpatch<2.0,>=1.33->langchain-core<0.3.0,>=0.2.0->langchain) (2.4)\n", - "Collecting mypy-extensions>=0.3.0 (from typing-inspect<1,>=0.4.0->dataclasses-json<0.7,>=0.5.7->langchain)\n", - " Downloading mypy_extensions-1.0.0-py3-none-any.whl.metadata (1.1 kB)\n", - "Downloading psycopg_binary-3.1.19-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.3/3.3 MB\u001b[0m \u001b[31m21.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", - "\u001b[?25hDownloading psycopg-3.1.19-py3-none-any.whl (179 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m179.4/179.4 kB\u001b[0m \u001b[31m20.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hDownloading tabulate-0.9.0-py3-none-any.whl (35 kB)\n", - "Downloading text_generation-0.7.0-py3-none-any.whl (12 kB)\n", - "Downloading langchain-0.2.0-py3-none-any.whl (973 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m973.7/973.7 kB\u001b[0m \u001b[31m54.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hDownloading langchain_community-0.2.0-py3-none-any.whl (2.1 MB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.1/2.1 MB\u001b[0m \u001b[31m64.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hDownloading aiohttp-3.9.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.3/1.3 MB\u001b[0m \u001b[31m56.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hDownloading dataclasses_json-0.6.6-py3-none-any.whl (28 kB)\n", - "Downloading huggingface_hub-0.23.0-py3-none-any.whl (401 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m401.2/401.2 kB\u001b[0m \u001b[31m29.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hDownloading langchain_core-0.2.0-py3-none-any.whl (307 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m307.9/307.9 kB\u001b[0m \u001b[31m22.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hDownloading langchain_text_splitters-0.2.0-py3-none-any.whl (23 kB)\n", - "Downloading langsmith-0.1.59-py3-none-any.whl (121 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m121.2/121.2 kB\u001b[0m \u001b[31m14.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hDownloading pydantic-2.7.1-py3-none-any.whl (409 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m409.3/409.3 kB\u001b[0m \u001b[31m35.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hDownloading pydantic_core-2.18.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.1/2.1 MB\u001b[0m \u001b[31m56.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m\n", - "\u001b[?25hDownloading SQLAlchemy-2.0.30-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.2/3.2 MB\u001b[0m \u001b[31m63.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m\n", - "\u001b[?25hDownloading tenacity-8.3.0-py3-none-any.whl (25 kB)\n", - "Downloading aiosignal-1.3.1-py3-none-any.whl (7.6 kB)\n", - "Downloading annotated_types-0.6.0-py3-none-any.whl (12 kB)\n", - "Downloading frozenlist-1.4.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (272 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m272.3/272.3 kB\u001b[0m \u001b[31m26.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hDownloading fsspec-2024.5.0-py3-none-any.whl (316 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m316.1/316.1 kB\u001b[0m \u001b[31m30.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hDownloading greenlet-3.0.3-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (620 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m620.0/620.0 kB\u001b[0m \u001b[31m47.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hDownloading jsonpatch-1.33-py2.py3-none-any.whl (12 kB)\n", - "Downloading marshmallow-3.21.2-py3-none-any.whl (49 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.3/49.3 kB\u001b[0m \u001b[31m6.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hDownloading multidict-6.0.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (128 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m128.7/128.7 kB\u001b[0m \u001b[31m13.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hDownloading orjson-3.10.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (142 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m142.5/142.5 kB\u001b[0m \u001b[31m8.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hDownloading tqdm-4.66.4-py3-none-any.whl (78 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m78.3/78.3 kB\u001b[0m \u001b[31m9.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hDownloading typing_inspect-0.9.0-py3-none-any.whl (8.8 kB)\n", - "Downloading yarl-1.9.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (328 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m328.1/328.1 kB\u001b[0m \u001b[31m27.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hDownloading filelock-3.14.0-py3-none-any.whl (12 kB)\n", - "Downloading mypy_extensions-1.0.0-py3-none-any.whl (4.7 kB)\n", - "Installing collected packages: tqdm, tenacity, tabulate, pydantic-core, psycopg-binary, psycopg, orjson, mypy-extensions, multidict, marshmallow, jsonpatch, greenlet, fsspec, frozenlist, filelock, annotated-types, yarl, typing-inspect, SQLAlchemy, pydantic, huggingface-hub, aiosignal, langsmith, dataclasses-json, aiohttp, text-generation, langchain-core, langchain-text-splitters, langchain, langchain-community\n", - "Successfully installed SQLAlchemy-2.0.30 aiohttp-3.9.5 aiosignal-1.3.1 annotated-types-0.6.0 dataclasses-json-0.6.6 filelock-3.14.0 frozenlist-1.4.1 fsspec-2024.5.0 greenlet-3.0.3 huggingface-hub-0.23.0 jsonpatch-1.33 langchain-0.2.0 langchain-community-0.2.0 langchain-core-0.2.0 langchain-text-splitters-0.2.0 langsmith-0.1.59 marshmallow-3.21.2 multidict-6.0.5 mypy-extensions-1.0.0 orjson-3.10.3 psycopg-3.1.19 psycopg-binary-3.1.19 pydantic-2.7.1 pydantic-core-2.18.2 tabulate-0.9.0 tenacity-8.3.0 text-generation-0.7.0 tqdm-4.66.4 typing-inspect-0.9.0 yarl-1.9.4\n", - "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n", - "\u001b[0m\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython3 -m pip install --upgrade pip\u001b[0m\n" - ] - } - ], - "source": [ - "! pip install psycopg-binary psycopg tabulate text-generation langchain langchain-community" - ] - }, - { - "cell_type": "markdown", - "id": "156bc717-4f17-4578-a088-d6a33ec5f9a0", - "metadata": {}, - "source": [ - "import all" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "9ad1f62d-38df-4a8c-a656-8dfe80df2c1f", - "metadata": {}, - "outputs": [], - "source": [ - "import psycopg\n", - "import os\n", - "from tabulate import tabulate\n", - "from langchain_community.llms import HuggingFaceTextGenInference\n", - "from langchain_core.prompts import PromptTemplate" - ] - }, - { - "cell_type": "markdown", - "id": "68641d9c-a10c-414b-8156-827d42431edc", - "metadata": {}, - "source": [ - "Postgres things" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "5154583e-aa74-41ce-860f-6c7f000f6fab", - "metadata": {}, - "outputs": [], - "source": [ - "conn = psycopg.connect(\n", - "\tdbname=os.environ.get(\"DATABASE_NAME\"),\n", - "\thost=os.environ.get(\"POSTGRES_URL\"),\n", - "\tuser=os.environ.get(\"OWNERUSERNAME\"),\n", - "\tpassword=os.environ.get(\"OWNERPASSWORD\"),\n", - "\tautocommit=True)\n", - "\n", - "db_schema = conn.execute(\"SELECT table_name, column_name as Columns, data_type as DataTypes FROM information_schema.columns where table_name NOT LIKE 'pg_stat%' AND table_schema='public' order by table_name,column_name;\")\n", - "colnames = [desc[0] for desc in db_schema.description]\n", - "db_schema_formatted=tabulate(db_schema.fetchall(), headers=colnames, tablefmt='psql')" - ] - }, - { - "cell_type": "markdown", - "id": "53a23197-5c73-4f37-b577-7973789663f0", - "metadata": {}, - "source": [ - "llm things" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "16f7c910-a5c5-4d7c-8045-cccd3517366e", - "metadata": {}, - "outputs": [], - "source": [ - "llm = HuggingFaceTextGenInference(\n", - " #inference_server_url=os.environ.get(\"LLM_ENDPOINT\"),\n", - " # my mistake, i wrote wrong url in the jupyter envs so lets use hardcoded version now\n", - " # i really dont want to restart notebook right now\n", - " inference_server_url=\"http://llm-service.llm:8000\",\n", - " temperature=0.5,\n", - " top_k=10,\n", - " top_p=0.5,\n", - " repetition_penalty=1.03,\n", - ")\n", - "\n", - "sql_prompt_template = PromptTemplate.from_template(\"\"\"\n", - "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n", - "You are a helpful AI assistant that can transform user queries into SQL commands to retrieve the data from the Postgresql database. The database has the next tables schema:\n", - "{db_schema}\n", - "\n", - "Please prepare and return only the SQL command, based on the user query, without any formatting or newlines. The answer must contain only valid SQL command.<|eot_id|><|start_header_id|>user<|end_header_id|>\n", - "{query}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n", - "\"\"\")\n", - "\n", - "final_prompt_template = PromptTemplate.from_template(\"\"\"\n", - "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n", - "You are a helpful AI assistant that can understand Postgresql replies and explain this data to the user. The database has the next tables schema:\n", - "{db_schema}\n", - "\n", - "User query: {query}\n", - "\n", - "Postgresql reply:\n", - "{postgres_reply}\n", - "\n", - "Base your answer on the provided user query and Postgresql reply.\n", - "Generate a draft response using the selected information.\n", - "It should be easy to understand your answer. Don't add any introductory words, start answering right away. \n", - "Keep your answer to a one or two sentences (if possible) that specifically answers the user's question. If not - try to keep the answer short, summarizing the returned data.\n", - "Generate your final response after adjusting it to increase accuracy and relevance.\n", - "Now only show your final response!\n", - "If you do not know the answer or context is not relevant, response with \"I don't know\".\n", - "<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n", - "\"\"\")" - ] - }, - { - "cell_type": "markdown", - "id": "e82286bb-f01a-4a6c-b75c-3fc9ce08b90e", - "metadata": {}, - "source": [ - "handle_query function with all app logic" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "49cf0c45-f74e-448d-b990-6a30248e74d9", - "metadata": {}, - "outputs": [], - "source": [ - "def handle_query(query):\n", - " sql_query=llm.invoke(sql_prompt_template.format(db_schema=db_schema_formatted, query=query))\n", - " try:\n", - " postgres_reply = conn.execute(sql_query)\n", - " except psycopg.Error as e:\n", - " print(\"Unable to process query: \", query)\n", - " return \"Try another query\"\n", - " colnames = [desc[0] for desc in postgres_reply.description]\n", - " postgres_reply_data = postgres_reply.fetchall()\n", - " if postgres_reply_data == []:\n", - " return \"Received empty SQL answer, try another query\"\n", - " postgres_reply_formatted=tabulate(postgres_reply_data, headers=colnames, tablefmt='psql')\n", - " # debug section\n", - " # print(sql_query)\n", - " # print(postgres_reply_formatted)\n", - " # end of debug section\n", - " return llm.invoke(final_prompt_template.format(db_schema=db_schema_formatted, query=query, postgres_reply=postgres_reply_formatted))" - ] - }, - { - "cell_type": "markdown", - "id": "f41369f8-1c6c-4276-bbbd-16f65577121a", - "metadata": {}, - "source": [ - "ask something" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "6707f47a-c2ef-45a1-9512-eb7e357e431a", - "metadata": {}, - "outputs": [ - { - "ename": "InvalidURL", - "evalue": "Failed to parse: http://llm-service.llm:8000=", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", - "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/urllib3/util/url.py:425\u001b[0m, in \u001b[0;36mparse_url\u001b[0;34m(url)\u001b[0m\n\u001b[1;32m 424\u001b[0m auth \u001b[38;5;241m=\u001b[39m auth \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m--> 425\u001b[0m host, port \u001b[38;5;241m=\u001b[39m \u001b[43m_HOST_PORT_RE\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmatch\u001b[49m\u001b[43m(\u001b[49m\u001b[43mhost_port\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgroups\u001b[49m() \u001b[38;5;66;03m# type: ignore[union-attr]\u001b[39;00m\n\u001b[1;32m 426\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m auth \u001b[38;5;129;01mand\u001b[39;00m normalize_uri:\n", - "\u001b[0;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'groups'", - "\nThe above exception was the direct cause of the following exception:\n", - "\u001b[0;31mLocationParseError\u001b[0m Traceback (most recent call last)", - "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/requests/models.py:434\u001b[0m, in \u001b[0;36mPreparedRequest.prepare_url\u001b[0;34m(self, url, params)\u001b[0m\n\u001b[1;32m 433\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 434\u001b[0m scheme, auth, host, port, path, query, fragment \u001b[38;5;241m=\u001b[39m \u001b[43mparse_url\u001b[49m\u001b[43m(\u001b[49m\u001b[43murl\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 435\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m LocationParseError \u001b[38;5;28;01mas\u001b[39;00m e:\n", - "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/urllib3/util/url.py:451\u001b[0m, in \u001b[0;36mparse_url\u001b[0;34m(url)\u001b[0m\n\u001b[1;32m 450\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m (\u001b[38;5;167;01mValueError\u001b[39;00m, \u001b[38;5;167;01mAttributeError\u001b[39;00m) \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m--> 451\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m LocationParseError(source_url) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01me\u001b[39;00m\n\u001b[1;32m 453\u001b[0m \u001b[38;5;66;03m# For the sake of backwards compatibility we put empty\u001b[39;00m\n\u001b[1;32m 454\u001b[0m \u001b[38;5;66;03m# string values for path if there are any defined values\u001b[39;00m\n\u001b[1;32m 455\u001b[0m \u001b[38;5;66;03m# beyond the path in the URL.\u001b[39;00m\n\u001b[1;32m 456\u001b[0m \u001b[38;5;66;03m# TODO: Remove this when we break backwards compatibility.\u001b[39;00m\n", - "\u001b[0;31mLocationParseError\u001b[0m: Failed to parse: http://llm-service.llm:8000=", - "\nDuring handling of the above exception, another exception occurred:\n", - "\u001b[0;31mInvalidURL\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[7], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mhandle_query\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mPlease calculate the total sum of all John transactions.\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m)\n", - "Cell \u001b[0;32mIn[5], line 2\u001b[0m, in \u001b[0;36mhandle_query\u001b[0;34m(query)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mhandle_query\u001b[39m(query):\n\u001b[0;32m----> 2\u001b[0m sql_query\u001b[38;5;241m=\u001b[39m\u001b[43mllm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minvoke\u001b[49m\u001b[43m(\u001b[49m\u001b[43msql_prompt_template\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mformat\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdb_schema\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdb_schema_formatted\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mquery\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mquery\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 4\u001b[0m postgres_reply \u001b[38;5;241m=\u001b[39m conn\u001b[38;5;241m.\u001b[39mexecute(sql_query)\n", - "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/langchain_core/language_models/llms.py:276\u001b[0m, in \u001b[0;36mBaseLLM.invoke\u001b[0;34m(self, input, config, stop, **kwargs)\u001b[0m\n\u001b[1;32m 266\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21minvoke\u001b[39m(\n\u001b[1;32m 267\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 268\u001b[0m \u001b[38;5;28minput\u001b[39m: LanguageModelInput,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 272\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any,\n\u001b[1;32m 273\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28mstr\u001b[39m:\n\u001b[1;32m 274\u001b[0m config \u001b[38;5;241m=\u001b[39m ensure_config(config)\n\u001b[1;32m 275\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m (\n\u001b[0;32m--> 276\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate_prompt\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 277\u001b[0m \u001b[43m \u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_convert_input\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 278\u001b[0m \u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 279\u001b[0m \u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mcallbacks\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 280\u001b[0m \u001b[43m \u001b[49m\u001b[43mtags\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mtags\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 281\u001b[0m \u001b[43m \u001b[49m\u001b[43mmetadata\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmetadata\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 282\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_name\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mrun_name\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 283\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_id\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconfig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpop\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mrun_id\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 284\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 285\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 286\u001b[0m \u001b[38;5;241m.\u001b[39mgenerations[\u001b[38;5;241m0\u001b[39m][\u001b[38;5;241m0\u001b[39m]\n\u001b[1;32m 287\u001b[0m \u001b[38;5;241m.\u001b[39mtext\n\u001b[1;32m 288\u001b[0m )\n", - "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/langchain_core/language_models/llms.py:633\u001b[0m, in \u001b[0;36mBaseLLM.generate_prompt\u001b[0;34m(self, prompts, stop, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m 625\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mgenerate_prompt\u001b[39m(\n\u001b[1;32m 626\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 627\u001b[0m prompts: List[PromptValue],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 630\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any,\n\u001b[1;32m 631\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m LLMResult:\n\u001b[1;32m 632\u001b[0m prompt_strings \u001b[38;5;241m=\u001b[39m [p\u001b[38;5;241m.\u001b[39mto_string() \u001b[38;5;28;01mfor\u001b[39;00m p \u001b[38;5;129;01min\u001b[39;00m prompts]\n\u001b[0;32m--> 633\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprompt_strings\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/langchain_core/language_models/llms.py:803\u001b[0m, in \u001b[0;36mBaseLLM.generate\u001b[0;34m(self, prompts, stop, callbacks, tags, metadata, run_name, run_id, **kwargs)\u001b[0m\n\u001b[1;32m 788\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcache \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m get_llm_cache() \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m) \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcache \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mFalse\u001b[39;00m:\n\u001b[1;32m 789\u001b[0m run_managers \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 790\u001b[0m callback_manager\u001b[38;5;241m.\u001b[39mon_llm_start(\n\u001b[1;32m 791\u001b[0m dumpd(\u001b[38;5;28mself\u001b[39m),\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 801\u001b[0m )\n\u001b[1;32m 802\u001b[0m ]\n\u001b[0;32m--> 803\u001b[0m output \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate_helper\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 804\u001b[0m \u001b[43m \u001b[49m\u001b[43mprompts\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_managers\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mbool\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mnew_arg_supported\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\n\u001b[1;32m 805\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 806\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m output\n\u001b[1;32m 807\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(missing_prompts) \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n", - "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/langchain_core/language_models/llms.py:670\u001b[0m, in \u001b[0;36mBaseLLM._generate_helper\u001b[0;34m(self, prompts, stop, run_managers, new_arg_supported, **kwargs)\u001b[0m\n\u001b[1;32m 668\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m run_manager \u001b[38;5;129;01min\u001b[39;00m run_managers:\n\u001b[1;32m 669\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_llm_error(e, response\u001b[38;5;241m=\u001b[39mLLMResult(generations\u001b[38;5;241m=\u001b[39m[]))\n\u001b[0;32m--> 670\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[1;32m 671\u001b[0m flattened_outputs \u001b[38;5;241m=\u001b[39m output\u001b[38;5;241m.\u001b[39mflatten()\n\u001b[1;32m 672\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m manager, flattened_output \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(run_managers, flattened_outputs):\n", - "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/langchain_core/language_models/llms.py:657\u001b[0m, in \u001b[0;36mBaseLLM._generate_helper\u001b[0;34m(self, prompts, stop, run_managers, new_arg_supported, **kwargs)\u001b[0m\n\u001b[1;32m 647\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_generate_helper\u001b[39m(\n\u001b[1;32m 648\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 649\u001b[0m prompts: List[\u001b[38;5;28mstr\u001b[39m],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 653\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any,\n\u001b[1;32m 654\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m LLMResult:\n\u001b[1;32m 655\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 656\u001b[0m output \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m--> 657\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 658\u001b[0m \u001b[43m \u001b[49m\u001b[43mprompts\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 659\u001b[0m \u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 660\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# TODO: support multiple run managers\u001b[39;49;00m\n\u001b[1;32m 661\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_managers\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mrun_managers\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 662\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 663\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 664\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[1;32m 665\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_generate(prompts, stop\u001b[38;5;241m=\u001b[39mstop)\n\u001b[1;32m 666\u001b[0m )\n\u001b[1;32m 667\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 668\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m run_manager \u001b[38;5;129;01min\u001b[39;00m run_managers:\n", - "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/langchain_core/language_models/llms.py:1317\u001b[0m, in \u001b[0;36mLLM._generate\u001b[0;34m(self, prompts, stop, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m 1314\u001b[0m new_arg_supported \u001b[38;5;241m=\u001b[39m inspect\u001b[38;5;241m.\u001b[39msignature(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call)\u001b[38;5;241m.\u001b[39mparameters\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrun_manager\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 1315\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m prompt \u001b[38;5;129;01min\u001b[39;00m prompts:\n\u001b[1;32m 1316\u001b[0m text \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m-> 1317\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1318\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[1;32m 1319\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call(prompt, stop\u001b[38;5;241m=\u001b[39mstop, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m 1320\u001b[0m )\n\u001b[1;32m 1321\u001b[0m generations\u001b[38;5;241m.\u001b[39mappend([Generation(text\u001b[38;5;241m=\u001b[39mtext)])\n\u001b[1;32m 1322\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m LLMResult(generations\u001b[38;5;241m=\u001b[39mgenerations)\n", - "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/langchain_community/llms/huggingface_text_gen_inference.py:202\u001b[0m, in \u001b[0;36mHuggingFaceTextGenInference._call\u001b[0;34m(self, prompt, stop, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m 199\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m completion\n\u001b[1;32m 201\u001b[0m invocation_params \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_invocation_params(stop, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m--> 202\u001b[0m res \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mclient\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43minvocation_params\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 203\u001b[0m \u001b[38;5;66;03m# remove stop sequences from the end of the generated text\u001b[39;00m\n\u001b[1;32m 204\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m stop_seq \u001b[38;5;129;01min\u001b[39;00m invocation_params[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mstop_sequences\u001b[39m\u001b[38;5;124m\"\u001b[39m]:\n", - "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/text_generation/client.py:275\u001b[0m, in \u001b[0;36mClient.generate\u001b[0;34m(self, prompt, do_sample, max_new_tokens, best_of, repetition_penalty, frequency_penalty, return_full_text, seed, stop_sequences, temperature, top_k, top_p, truncate, typical_p, watermark, decoder_input_details, top_n_tokens, grammar)\u001b[0m\n\u001b[1;32m 253\u001b[0m parameters \u001b[38;5;241m=\u001b[39m Parameters(\n\u001b[1;32m 254\u001b[0m best_of\u001b[38;5;241m=\u001b[39mbest_of,\n\u001b[1;32m 255\u001b[0m details\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 271\u001b[0m grammar\u001b[38;5;241m=\u001b[39mgrammar,\n\u001b[1;32m 272\u001b[0m )\n\u001b[1;32m 273\u001b[0m request \u001b[38;5;241m=\u001b[39m Request(inputs\u001b[38;5;241m=\u001b[39mprompt, stream\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m, parameters\u001b[38;5;241m=\u001b[39mparameters)\n\u001b[0;32m--> 275\u001b[0m resp \u001b[38;5;241m=\u001b[39m \u001b[43mrequests\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpost\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 276\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbase_url\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 277\u001b[0m \u001b[43m \u001b[49m\u001b[43mjson\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdict\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 278\u001b[0m \u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 279\u001b[0m \u001b[43m \u001b[49m\u001b[43mcookies\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcookies\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 280\u001b[0m \u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtimeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 281\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 282\u001b[0m payload \u001b[38;5;241m=\u001b[39m resp\u001b[38;5;241m.\u001b[39mjson()\n\u001b[1;32m 283\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m resp\u001b[38;5;241m.\u001b[39mstatus_code \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m200\u001b[39m:\n", - "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/requests/api.py:115\u001b[0m, in \u001b[0;36mpost\u001b[0;34m(url, data, json, **kwargs)\u001b[0m\n\u001b[1;32m 103\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mpost\u001b[39m(url, data\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, json\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 104\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124;03m\"\"\"Sends a POST request.\u001b[39;00m\n\u001b[1;32m 105\u001b[0m \n\u001b[1;32m 106\u001b[0m \u001b[38;5;124;03m :param url: URL for the new :class:`Request` object.\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 112\u001b[0m \u001b[38;5;124;03m :rtype: requests.Response\u001b[39;00m\n\u001b[1;32m 113\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 115\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mrequest\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mpost\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mjson\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mjson\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/requests/api.py:59\u001b[0m, in \u001b[0;36mrequest\u001b[0;34m(method, url, **kwargs)\u001b[0m\n\u001b[1;32m 55\u001b[0m \u001b[38;5;66;03m# By using the 'with' statement we are sure the session is closed, thus we\u001b[39;00m\n\u001b[1;32m 56\u001b[0m \u001b[38;5;66;03m# avoid leaving sockets open which can trigger a ResourceWarning in some\u001b[39;00m\n\u001b[1;32m 57\u001b[0m \u001b[38;5;66;03m# cases, and look like a memory leak in others.\u001b[39;00m\n\u001b[1;32m 58\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m sessions\u001b[38;5;241m.\u001b[39mSession() \u001b[38;5;28;01mas\u001b[39;00m session:\n\u001b[0;32m---> 59\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43msession\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmethod\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/requests/sessions.py:575\u001b[0m, in \u001b[0;36mSession.request\u001b[0;34m(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)\u001b[0m\n\u001b[1;32m 562\u001b[0m \u001b[38;5;66;03m# Create the Request.\u001b[39;00m\n\u001b[1;32m 563\u001b[0m req \u001b[38;5;241m=\u001b[39m Request(\n\u001b[1;32m 564\u001b[0m method\u001b[38;5;241m=\u001b[39mmethod\u001b[38;5;241m.\u001b[39mupper(),\n\u001b[1;32m 565\u001b[0m url\u001b[38;5;241m=\u001b[39murl,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 573\u001b[0m hooks\u001b[38;5;241m=\u001b[39mhooks,\n\u001b[1;32m 574\u001b[0m )\n\u001b[0;32m--> 575\u001b[0m prep \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mprepare_request\u001b[49m\u001b[43m(\u001b[49m\u001b[43mreq\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 577\u001b[0m proxies \u001b[38;5;241m=\u001b[39m proxies \u001b[38;5;129;01mor\u001b[39;00m {}\n\u001b[1;32m 579\u001b[0m settings \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmerge_environment_settings(\n\u001b[1;32m 580\u001b[0m prep\u001b[38;5;241m.\u001b[39murl, proxies, stream, verify, cert\n\u001b[1;32m 581\u001b[0m )\n", - "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/requests/sessions.py:486\u001b[0m, in \u001b[0;36mSession.prepare_request\u001b[0;34m(self, request)\u001b[0m\n\u001b[1;32m 483\u001b[0m auth \u001b[38;5;241m=\u001b[39m get_netrc_auth(request\u001b[38;5;241m.\u001b[39murl)\n\u001b[1;32m 485\u001b[0m p \u001b[38;5;241m=\u001b[39m PreparedRequest()\n\u001b[0;32m--> 486\u001b[0m \u001b[43mp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mprepare\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 487\u001b[0m \u001b[43m \u001b[49m\u001b[43mmethod\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmethod\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mupper\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 488\u001b[0m \u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 489\u001b[0m \u001b[43m \u001b[49m\u001b[43mfiles\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfiles\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 490\u001b[0m \u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 491\u001b[0m \u001b[43m \u001b[49m\u001b[43mjson\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mjson\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 492\u001b[0m \u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmerge_setting\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 493\u001b[0m \u001b[43m \u001b[49m\u001b[43mrequest\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdict_class\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mCaseInsensitiveDict\u001b[49m\n\u001b[1;32m 494\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 495\u001b[0m \u001b[43m \u001b[49m\u001b[43mparams\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmerge_setting\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrequest\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mparams\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mparams\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 496\u001b[0m \u001b[43m \u001b[49m\u001b[43mauth\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmerge_setting\u001b[49m\u001b[43m(\u001b[49m\u001b[43mauth\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mauth\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 497\u001b[0m \u001b[43m \u001b[49m\u001b[43mcookies\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmerged_cookies\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 498\u001b[0m \u001b[43m \u001b[49m\u001b[43mhooks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmerge_hooks\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrequest\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mhooks\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mhooks\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 499\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 500\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m p\n", - "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/requests/models.py:368\u001b[0m, in \u001b[0;36mPreparedRequest.prepare\u001b[0;34m(self, method, url, headers, files, data, params, auth, cookies, hooks, json)\u001b[0m\n\u001b[1;32m 365\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Prepares the entire request with the given parameters.\"\"\"\u001b[39;00m\n\u001b[1;32m 367\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprepare_method(method)\n\u001b[0;32m--> 368\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mprepare_url\u001b[49m\u001b[43m(\u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mparams\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 369\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprepare_headers(headers)\n\u001b[1;32m 370\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprepare_cookies(cookies)\n", - "File \u001b[0;32m/usr/local/lib/python3.11/dist-packages/requests/models.py:436\u001b[0m, in \u001b[0;36mPreparedRequest.prepare_url\u001b[0;34m(self, url, params)\u001b[0m\n\u001b[1;32m 434\u001b[0m scheme, auth, host, port, path, query, fragment \u001b[38;5;241m=\u001b[39m parse_url(url)\n\u001b[1;32m 435\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m LocationParseError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m--> 436\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m InvalidURL(\u001b[38;5;241m*\u001b[39me\u001b[38;5;241m.\u001b[39margs)\n\u001b[1;32m 438\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m scheme:\n\u001b[1;32m 439\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m MissingSchema(\n\u001b[1;32m 440\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid URL \u001b[39m\u001b[38;5;132;01m{\u001b[39;00murl\u001b[38;5;132;01m!r}\u001b[39;00m\u001b[38;5;124m: No scheme supplied. \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 441\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPerhaps you meant https://\u001b[39m\u001b[38;5;132;01m{\u001b[39;00murl\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m?\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 442\u001b[0m )\n", - "\u001b[0;31mInvalidURL\u001b[0m: Failed to parse: http://llm-service.llm:8000=" - ] - } - ], - "source": [ - "print(handle_query(\"Please calculate the total sum of all John transactions.\"))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "dfc72471-e4cf-4f42-9721-d22c5939a64a", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.0rc1" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/ai-ml/nl-to-sql/manifests/04-notebook/client.yaml b/ai-ml/nl-to-sql/manifests/04-notebook/client.yaml deleted file mode 100644 index e013159f28..0000000000 --- a/ai-ml/nl-to-sql/manifests/04-notebook/client.yaml +++ /dev/null @@ -1,30 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: client - annotations: - cluster-autoscaler.kubernetes.io/safe-to-evict: "true" -spec: - restartPolicy: Never - containers: - - name: client - image: python:3.11 - command: [ "/bin/bash", "-c", "--" ] - args: [ "while true; do sleep 30; done;" ] - env: - - name: OWNERPASSWORD - valueFrom: - secretKeyRef: - name: mydatabaseowner.my-cluster.credentials.postgresql.acid.zalan.do - key: password - - name: OWNERUSERNAME - valueFrom: - secretKeyRef: - name: mydatabaseowner.my-cluster.credentials.postgresql.acid.zalan.do - key: username - - name: POSTGRES_URL - value: my-cluster.postgres - - name: DATABASE_NAME - value: mydatabase - - name: LLM_ENDPOINT - value: http://llm-service.llm:8000/ diff --git a/ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb b/ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb new file mode 100644 index 0000000000..55ea218c0e --- /dev/null +++ b/ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb @@ -0,0 +1,606 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "source": [ + "Install **kubectl** and the **Google Cloud SDK** with the necessary authentication plugin for Google Kubernetes Engine (GKE)." + ], + "metadata": { + "id": "MJkq3GeyosAI" + }, + "id": "MJkq3GeyosAI" + }, + { + "cell_type": "code", + "source": [ + "%%bash\n", + "\n", + "curl -LO \"https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl\"\n", + "sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl\n", + "apt-get update && apt-get install apt-transport-https ca-certificates gnupg\n", + "curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg\n", + "echo \"deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main\" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list\n", + "apt-get update && sudo apt-get install google-cloud-cli-gke-gcloud-auth-plugin\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "collapsed": true, + "id": "tiGscdCpo2KC", + "executionInfo": { + "status": "ok", + "timestamp": 1716459651838, + "user_tz": -120, + "elapsed": 11442, + "user": { + "displayName": "", + "userId": "" + } + }, + "outputId": "ff824e08-14bf-4ffb-936e-fa586015fe81" + }, + "id": "tiGscdCpo2KC", + "execution_count": 60, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Hit:1 https://packages.cloud.google.com/apt cloud-sdk InRelease\n", + "Hit:2 https://cloud.r-project.org/bin/linux/ubuntu jammy-cran40/ InRelease\n", + "Get:3 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]\n", + "Hit:4 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64 InRelease\n", + "Hit:5 http://archive.ubuntu.com/ubuntu jammy InRelease\n", + "Get:6 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]\n", + "Hit:7 https://ppa.launchpadcontent.net/c2d4u.team/c2d4u4.0+/ubuntu jammy InRelease\n", + "Hit:8 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy InRelease\n", + "Hit:9 https://ppa.launchpadcontent.net/graphics-drivers/ppa/ubuntu jammy InRelease\n", + "Hit:10 https://ppa.launchpadcontent.net/ubuntugis/ppa/ubuntu jammy InRelease\n", + "Hit:11 http://archive.ubuntu.com/ubuntu jammy-backports InRelease\n", + "Fetched 229 kB in 1s (172 kB/s)\n", + "Reading package lists...\n", + "Reading package lists...\n", + "Building dependency tree...\n", + "Reading state information...\n", + "ca-certificates is already the newest version (20230311ubuntu0.22.04.1).\n", + "gnupg is already the newest version (2.2.27-3ubuntu2.1).\n", + "apt-transport-https is already the newest version (2.4.12).\n", + "0 upgraded, 0 newly installed, 0 to remove and 46 not upgraded.\n", + "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main\n", + "Hit:1 https://packages.cloud.google.com/apt cloud-sdk InRelease\n", + "Hit:2 https://cloud.r-project.org/bin/linux/ubuntu jammy-cran40/ InRelease\n", + "Hit:3 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64 InRelease\n", + "Hit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease\n", + "Hit:5 http://archive.ubuntu.com/ubuntu jammy InRelease\n", + "Hit:6 http://archive.ubuntu.com/ubuntu jammy-updates InRelease\n", + "Hit:7 http://archive.ubuntu.com/ubuntu jammy-backports InRelease\n", + "Hit:8 https://ppa.launchpadcontent.net/c2d4u.team/c2d4u4.0+/ubuntu jammy InRelease\n", + "Hit:9 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy InRelease\n", + "Hit:10 https://ppa.launchpadcontent.net/graphics-drivers/ppa/ubuntu jammy InRelease\n", + "Hit:11 https://ppa.launchpadcontent.net/ubuntugis/ppa/ubuntu jammy InRelease\n", + "Reading package lists...\n", + "Reading package lists...\n", + "Building dependency tree...\n", + "Reading state information...\n", + "google-cloud-cli-gke-gcloud-auth-plugin is already the newest version (477.0.0-0).\n", + "0 upgraded, 0 newly installed, 0 to remove and 46 not upgraded.\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + "\r 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\r100 138 100 138 0 0 2138 0 --:--:-- --:--:-- --:--:-- 2156\n", + "\r100 49.0M 100 49.0M 0 0 118M 0 --:--:-- --:--:-- --:--:-- 118M\n", + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + "\r 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0gpg: cannot open '/dev/tty': No such device or address\n", + "\r100 2659 100 2659 0 0 36694 0 --:--:-- --:--:-- --:--:-- 36930\n", + "curl: (23) Failed writing body\n", + "W: Target Packages (main/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list.d/google-cloud-sdk.list:1 and /etc/apt/sources.list.d/google-cloud-sdk.list:2\n", + "W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list.d/google-cloud-sdk.list:1 and /etc/apt/sources.list.d/google-cloud-sdk.list:2\n", + "W: Target Packages (main/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list.d/google-cloud-sdk.list:1 and /etc/apt/sources.list.d/google-cloud-sdk.list:2\n", + "W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list.d/google-cloud-sdk.list:1 and /etc/apt/sources.list.d/google-cloud-sdk.list:2\n", + "W: Target Packages (main/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list.d/google-cloud-sdk.list:1 and /etc/apt/sources.list.d/google-cloud-sdk.list:2\n", + "W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list.d/google-cloud-sdk.list:1 and /etc/apt/sources.list.d/google-cloud-sdk.list:2\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "Retrieves the GKE cluster's credentials using the **gcloud** command:" + ], + "metadata": { + "id": "Q8x_lxTXrZTi" + }, + "id": "Q8x_lxTXrZTi" + }, + { + "cell_type": "code", + "source": [ + "%%bash\n", + "\n", + "export KUBERNETES_CLUSTER_NAME=\"nltosql-dima\"\n", + "gcloud container clusters get-credentials $KUBERNETES_CLUSTER_NAME --region $GOOGLE_CLOUD_REGION" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "n1c8Fsk1rcrK", + "executionInfo": { + "status": "ok", + "timestamp": 1716458517839, + "user_tz": -120, + "elapsed": 1203, + "user": { + "displayName": "", + "userId": "" + } + }, + "outputId": "551cbaf9-0498-44fc-e0d0-688c41dc3d34" + }, + "id": "n1c8Fsk1rcrK", + "execution_count": 37, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": [ + "Fetching cluster endpoint and auth data.\n", + "kubeconfig entry generated for nltosql-dima.\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "Create an .env file with environment variables required for connecting to Postgresql and LLM runtime in a Kubernetes cluster." + ], + "metadata": { + "id": "USwAo2Nwr9wQ" + }, + "id": "USwAo2Nwr9wQ" + }, + { + "cell_type": "code", + "source": [ + "%%bash\n", + "\n", + "echo POSTGRES_ENDPOINT=$(kubectl get pod -l spilo-role=master -n postgres -o=jsonpath=\"{.items[0].status.podIP}\") > .env\n", + "echo LLM_ENDPOINT=http://$(kubectl get pod -l app=tgi-runtime -n llm -o=jsonpath=\"{.items[0].status.podIP}\"):8000 >> .env\n", + "echo DATABASE_NAME=mydatabase >> .env\n", + "echo DBUSERNAME=$(kubectl get secret mydatabaseowner.my-cluster.credentials.postgresql.acid.zalan.do -n postgres --template={{.data.username}} | base64 -d) >> .env\n", + "echo DBPASSWORD=$(kubectl get secret mydatabaseowner.my-cluster.credentials.postgresql.acid.zalan.do -n postgres --template={{.data.password}} | base64 -d) >> .env" + ], + "metadata": { + "id": "6lo6M4AqsAru", + "executionInfo": { + "status": "ok", + "timestamp": 1716460066445, + "user_tz": -120, + "elapsed": 1696, + "user": { + "displayName": "", + "userId": "" + } + } + }, + "id": "6lo6M4AqsAru", + "execution_count": 61, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "Install required python libraries:" + ], + "metadata": { + "id": "xX-aQbhl4g4C" + }, + "id": "xX-aQbhl4g4C" + }, + { + "cell_type": "code", + "source": [ + "! pip install python-dotenv psycopg-binary psycopg tabulate text-generation langchain langchain-community" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "uwspErB44izG", + "executionInfo": { + "status": "ok", + "timestamp": 1716458594128, + "user_tz": -120, + "elapsed": 19693, + "user": { + "displayName": "", + "userId": "" + } + }, + "outputId": "09fb9da5-c595-4db9-b9ca-3d26fa54d5b9" + }, + "id": "uwspErB44izG", + "execution_count": 39, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Requirement already satisfied: python-dotenv in /usr/local/lib/python3.10/dist-packages (1.0.1)\n", + "Collecting psycopg-binary\n", + " Downloading psycopg_binary-3.1.19-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.3/3.3 MB\u001b[0m \u001b[31m11.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting psycopg\n", + " Downloading psycopg-3.1.19-py3-none-any.whl (179 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m179.4/179.4 kB\u001b[0m \u001b[31m18.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: tabulate in /usr/local/lib/python3.10/dist-packages (0.9.0)\n", + "Collecting text-generation\n", + " Downloading text_generation-0.7.0-py3-none-any.whl (12 kB)\n", + "Collecting langchain\n", + " Downloading langchain-0.2.0-py3-none-any.whl (973 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m973.7/973.7 kB\u001b[0m \u001b[31m38.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting langchain-community\n", + " Downloading langchain_community-0.2.0-py3-none-any.whl (2.1 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.1/2.1 MB\u001b[0m \u001b[31m69.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: typing-extensions>=4.1 in /usr/local/lib/python3.10/dist-packages (from psycopg) (4.11.0)\n", + "Requirement already satisfied: aiohttp<4.0,>=3.8 in /usr/local/lib/python3.10/dist-packages (from text-generation) (3.9.5)\n", + "Requirement already satisfied: huggingface-hub<1.0,>=0.12 in /usr/local/lib/python3.10/dist-packages (from text-generation) (0.20.3)\n", + "Collecting pydantic<3,>2 (from text-generation)\n", + " Downloading pydantic-2.7.1-py3-none-any.whl (409 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m409.3/409.3 kB\u001b[0m \u001b[31m38.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: PyYAML>=5.3 in /usr/local/lib/python3.10/dist-packages (from langchain) (6.0.1)\n", + "Requirement already satisfied: SQLAlchemy<3,>=1.4 in /usr/local/lib/python3.10/dist-packages (from langchain) (2.0.30)\n", + "Requirement already satisfied: async-timeout<5.0.0,>=4.0.0 in /usr/local/lib/python3.10/dist-packages (from langchain) (4.0.3)\n", + "Collecting dataclasses-json<0.7,>=0.5.7 (from langchain)\n", + " Downloading dataclasses_json-0.6.6-py3-none-any.whl (28 kB)\n", + "Collecting langchain-core<0.3.0,>=0.2.0 (from langchain)\n", + " Downloading langchain_core-0.2.1-py3-none-any.whl (308 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m308.5/308.5 kB\u001b[0m \u001b[31m29.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting langchain-text-splitters<0.3.0,>=0.2.0 (from langchain)\n", + " Downloading langchain_text_splitters-0.2.0-py3-none-any.whl (23 kB)\n", + "Collecting langsmith<0.2.0,>=0.1.17 (from langchain)\n", + " Downloading langsmith-0.1.62-py3-none-any.whl (122 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m122.3/122.3 kB\u001b[0m \u001b[31m14.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: numpy<2,>=1 in /usr/local/lib/python3.10/dist-packages (from langchain) (1.25.2)\n", + "Requirement already satisfied: requests<3,>=2 in /usr/local/lib/python3.10/dist-packages (from langchain) (2.31.0)\n", + "Requirement already satisfied: tenacity<9.0.0,>=8.1.0 in /usr/local/lib/python3.10/dist-packages (from langchain) (8.3.0)\n", + "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0,>=3.8->text-generation) (1.3.1)\n", + "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0,>=3.8->text-generation) (23.2.0)\n", + "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0,>=3.8->text-generation) (1.4.1)\n", + "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0,>=3.8->text-generation) (6.0.5)\n", + "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0,>=3.8->text-generation) (1.9.4)\n", + "Collecting marshmallow<4.0.0,>=3.18.0 (from dataclasses-json<0.7,>=0.5.7->langchain)\n", + " Downloading marshmallow-3.21.2-py3-none-any.whl (49 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.3/49.3 kB\u001b[0m \u001b[31m8.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting typing-inspect<1,>=0.4.0 (from dataclasses-json<0.7,>=0.5.7->langchain)\n", + " Downloading typing_inspect-0.9.0-py3-none-any.whl (8.8 kB)\n", + "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.12->text-generation) (3.14.0)\n", + "Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.12->text-generation) (2023.6.0)\n", + "Requirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.12->text-generation) (4.66.4)\n", + "Requirement already satisfied: packaging>=20.9 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.12->text-generation) (24.0)\n", + "Collecting jsonpatch<2.0,>=1.33 (from langchain-core<0.3.0,>=0.2.0->langchain)\n", + " Downloading jsonpatch-1.33-py2.py3-none-any.whl (12 kB)\n", + "Collecting packaging>=20.9 (from huggingface-hub<1.0,>=0.12->text-generation)\n", + " Downloading packaging-23.2-py3-none-any.whl (53 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m53.0/53.0 kB\u001b[0m \u001b[31m7.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting orjson<4.0.0,>=3.9.14 (from langsmith<0.2.0,>=0.1.17->langchain)\n", + " Downloading orjson-3.10.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (142 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m142.5/142.5 kB\u001b[0m \u001b[31m17.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>2->text-generation) (0.6.0)\n", + "Requirement already satisfied: pydantic-core==2.18.2 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>2->text-generation) (2.18.2)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain) (3.3.2)\n", + "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain) (3.7)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain) (2.0.7)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain) (2024.2.2)\n", + "Requirement already satisfied: greenlet!=0.4.17 in /usr/local/lib/python3.10/dist-packages (from SQLAlchemy<3,>=1.4->langchain) (3.0.3)\n", + "Collecting jsonpointer>=1.9 (from jsonpatch<2.0,>=1.33->langchain-core<0.3.0,>=0.2.0->langchain)\n", + " Downloading jsonpointer-2.4-py2.py3-none-any.whl (7.8 kB)\n", + "Collecting mypy-extensions>=0.3.0 (from typing-inspect<1,>=0.4.0->dataclasses-json<0.7,>=0.5.7->langchain)\n", + " Downloading mypy_extensions-1.0.0-py3-none-any.whl (4.7 kB)\n", + "Installing collected packages: psycopg-binary, psycopg, packaging, orjson, mypy-extensions, jsonpointer, typing-inspect, pydantic, marshmallow, jsonpatch, text-generation, langsmith, dataclasses-json, langchain-core, langchain-text-splitters, langchain, langchain-community\n", + " Attempting uninstall: packaging\n", + " Found existing installation: packaging 24.0\n", + " Uninstalling packaging-24.0:\n", + " Successfully uninstalled packaging-24.0\n", + " Attempting uninstall: pydantic\n", + " Found existing installation: pydantic 1.10.15\n", + " Uninstalling pydantic-1.10.15:\n", + " Successfully uninstalled pydantic-1.10.15\n", + "Successfully installed dataclasses-json-0.6.6 jsonpatch-1.33 jsonpointer-2.4 langchain-0.2.0 langchain-community-0.2.0 langchain-core-0.2.1 langchain-text-splitters-0.2.0 langsmith-0.1.62 marshmallow-3.21.2 mypy-extensions-1.0.0 orjson-3.10.3 packaging-23.2 psycopg-3.1.19 psycopg-binary-3.1.19 pydantic-2.7.1 text-generation-0.7.0 typing-inspect-0.9.0\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "Import python libraries:" + ], + "metadata": { + "id": "9acUeBu15quS" + }, + "id": "9acUeBu15quS" + }, + { + "cell_type": "code", + "source": [ + "from dotenv import load_dotenv\n", + "import psycopg\n", + "import os\n", + "from tabulate import tabulate\n", + "from langchain_community.llms import HuggingFaceTextGenInference\n", + "from langchain_core.prompts import PromptTemplate" + ], + "metadata": { + "id": "oqq4NDgvt-XT", + "executionInfo": { + "status": "ok", + "timestamp": 1716458612004, + "user_tz": -120, + "elapsed": 1593, + "user": { + "displayName": "", + "userId": "" + } + } + }, + "id": "oqq4NDgvt-XT", + "execution_count": 40, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "Load environment variables from the .env file, establish a connection to a PostgreSQL database and retrieve information about the schema of the public tables." + ], + "metadata": { + "id": "Ef9FSgl55_MI" + }, + "id": "Ef9FSgl55_MI" + }, + { + "cell_type": "code", + "source": [ + "load_dotenv()\n", + "\n", + "conn = psycopg.connect(\n", + " dbname=os.environ.get(\"DATABASE_NAME\"),\n", + " host=os.environ.get(\"POSTGRES_ENDPOINT\"),\n", + " user=os.environ.get(\"DBUSERNAME\"),\n", + " password=os.environ.get(\"DBPASSWORD\"),\n", + " autocommit=True)\n", + "\n", + "db_schema = conn.execute(\"SELECT table_name, column_name as Columns, data_type as DataTypes FROM information_schema.columns where table_name NOT LIKE 'pg_stat%' AND table_schema='public' order by table_name,column_name;\")\n", + "colnames = [desc[0] for desc in db_schema.description]\n", + "db_schema_formatted=tabulate(db_schema.fetchall(), headers=colnames, tablefmt='psql')\n" + ], + "metadata": { + "id": "7M-IQwbM6AgY", + "executionInfo": { + "status": "ok", + "timestamp": 1716460212145, + "user_tz": -120, + "elapsed": 495, + "user": { + "displayName": "", + "userId": "" + } + } + }, + "id": "7M-IQwbM6AgY", + "execution_count": 62, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "Initializes the Hugging Face TGI connection for text generation.\n", + "\n", + "Set up two prompts: the first one is for generating SQL commands based on user queries, while the second prompt is for generating responses based on user queries and PostgreSQL replies." + ], + "metadata": { + "id": "9bLuIcNU6sz7" + }, + "id": "9bLuIcNU6sz7" + }, + { + "cell_type": "code", + "source": [ + "llm = HuggingFaceTextGenInference(\n", + " inference_server_url=os.environ.get(\"LLM_ENDPOINT\"),\n", + " temperature=0.5,\n", + " top_k=5,\n", + " top_p=0.5,\n", + " repetition_penalty=1.03,\n", + ")\n", + "\n", + "sql_prompt_template = PromptTemplate.from_template(\"\"\"\n", + " <|begin_of_text|><|start_header_id|>system<|end_header_id|>\n", + " You are a helpful AI assistant that can transform user queries into SQL commands to retrieve the data from the Postgresql database. The database has the next tables schema:\n", + " {db_schema}\n", + " Please prepare and return only the SQL command, based on the user query, without any formatting or newlines. The answer must contain only valid SQL command.<|eot_id|><|start_header_id|>user<|end_header_id|>\n", + " {query}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n", + "\"\"\")\n", + "\n", + "final_prompt_template = PromptTemplate.from_template(\"\"\"\n", + " <|begin_of_text|><|start_header_id|>system<|end_header_id|>\n", + " You are a helpful AI assistant that can understand Postgresql replies and explain this data to the user. The database has the next tables schema:\n", + " {db_schema}\n", + " User query: {query}\n", + " Postgresql reply:\n", + " {postgres_reply}\n", + " Base your answer on the provided user query and Postgresql reply.\n", + " Generate a draft response using the selected information.\n", + " It should be easy to understand your answer. Don't add any introductory words, start answering right away.\n", + " Keep your answer to a one or two sentences (if possible) that specifically answers the user's question. If not - try to keep the answer short, summarizing the returned data.\n", + " Generate your final response after adjusting it to increase accuracy and relevance.\n", + " Now only show your final response!\n", + " If you do not know the answer or context is not relevant, response with \"I don't know\".\n", + " <|eot_id|><|start_header_id|>assistant<|end_header_id|>\n", + "\"\"\")" + ], + "metadata": { + "id": "RKLr5riV6uZW", + "executionInfo": { + "status": "ok", + "timestamp": 1716460319140, + "user_tz": -120, + "elapsed": 1, + "user": { + "displayName": "", + "userId": "" + } + } + }, + "id": "RKLr5riV6uZW", + "execution_count": 63, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "Configure two functions to interacte with the PostgreSQL database and the TGI runtime." + ], + "metadata": { + "id": "vdtggWOO7Wef" + }, + "id": "vdtggWOO7Wef" + }, + { + "cell_type": "code", + "source": [ + "def postgres_query(query):\n", + " try:\n", + " postgres_reply = conn.execute(query)\n", + " except psycopg.Error as e:\n", + " print(\"Unable to process query\")\n", + " return False\n", + " colnames = [desc[0] for desc in postgres_reply.description]\n", + " postgres_reply_data = postgres_reply.fetchall()\n", + " if postgres_reply_data == []:\n", + " print(\"Received empty SQL answer\")\n", + " return False\n", + " postgres_reply_formatted=tabulate(postgres_reply_data, headers=colnames, tablefmt='psql')\n", + " return postgres_reply_formatted\n", + "\n", + "\n", + "def llm_query(query):\n", + " sql_prompt_value=sql_prompt_template.format(db_schema=db_schema_formatted, query=query)\n", + " sql_query=llm.invoke(sql_prompt_value)\n", + " # print(sql_query)\n", + " postgres_reply=postgres_query(sql_query)\n", + " if postgres_reply == False:\n", + " return \"Try another query\"\n", + " # print(postgres_reply)\n", + " final_prompt_value=final_prompt_template.format(db_schema=db_schema_formatted, query=query, postgres_reply=postgres_reply)\n", + " return llm.invoke(final_prompt_value)" + ], + "metadata": { + "id": "a_6XVEtH7dFv", + "executionInfo": { + "status": "ok", + "timestamp": 1716459014750, + "user_tz": -120, + "elapsed": 328, + "user": { + "displayName": "", + "userId": "" + } + } + }, + "id": "a_6XVEtH7dFv", + "execution_count": 52, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "Run some queries to demonstrate the moability to generate SQL commands from user queries and provide responses based on the PostgreSQL replies:" + ], + "metadata": { + "id": "LMMBr-gu7g0I" + }, + "id": "LMMBr-gu7g0I" + }, + { + "cell_type": "code", + "source": [ + "print(llm_query(\"Please calculate the total sum of all John transactions.\"))\n", + "print(llm_query(\"Which woman spent more money in 2023 and how much?\"))\n", + "print(llm_query(\"What is the capital of Great Britain?\"))\n", + "print(llm_query(\"Who spent more money on electronics in last month?\"))\n", + "print(llm_query(\"Who spent more money on electronics in 10 last months?\"))\n", + "print(llm_query(\"Give me top 3 buyers of clothing. How much money each person spent?\"))" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "HQZ1gUYY7iLn", + "executionInfo": { + "status": "ok", + "timestamp": 1716459463391, + "user_tz": -120, + "elapsed": 29595, + "user": { + "displayName": "", + "userId": "" + } + }, + "outputId": "b6dd1d33-dcbf-4bef-cb1f-304c31d6171e" + }, + "id": "HQZ1gUYY7iLn", + "execution_count": 59, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "The total sum of all John's transactions is 6210.\n", + "Elizabeth spent $15,950 in 2023.\n", + "Unable to process query\n", + "Try another query\n", + "Received empty SQL answer\n", + "Try another query\n", + "Elizabeth spent the most money on electronics in the last 10 months, with a total amount of $5750.\n", + "The top 3 buyers of clothing are Brenda, Melissa, and Sarah, who spent $7755, $7550, and $5775 respectively.\n" + ] + } + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.10" + }, + "colab": { + "provenance": [], + "name": "dmitrii_ganochenko (May 23, 2024, 10:47:16 AM)" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} \ No newline at end of file diff --git a/ai-ml/nl-to-sql/manifests/04-notebook/openai_script.py b/ai-ml/nl-to-sql/manifests/04-notebook/openai_script.py deleted file mode 100644 index f39117dd23..0000000000 --- a/ai-ml/nl-to-sql/manifests/04-notebook/openai_script.py +++ /dev/null @@ -1,84 +0,0 @@ -import psycopg -import os -from tabulate import tabulate -from langchain_core.prompts import ChatPromptTemplate -from langchain_openai import ChatOpenAI - -conn = psycopg.connect( - dbname=os.environ.get("DATABASE_NAME"), - host=os.environ.get("POSTGRES_URL"), - user=os.environ.get("OWNERUSERNAME"), - password=os.environ.get("OWNERPASSWORD"), - autocommit=True) - -db_schema = conn.execute("SELECT table_name, column_name as Columns, data_type as DataTypes FROM information_schema.columns where table_name NOT LIKE 'pg_stat%' AND table_schema='public' order by table_name,column_name;") -colnames = [desc[0] for desc in db_schema.description] -db_schema_formatted=tabulate(db_schema.fetchall(), headers=colnames, tablefmt='psql') - -llm = ChatOpenAI( - openai_api_base=os.environ.get("LLM_ENDPOINT"), - temperature=0.5, - openai_api_key="placeholder", - model="dganochenko/llama-3-8b-chat") - -sql_prompt_template = ChatPromptTemplate.from_messages( - [ - ("system", """ - You are a helpful AI assistant that can transform user queries into SQL commands to retrieve the data from the Postgresql database. The database has the next tables schema: - {db_schema} - Please prepare and return only the SQL command, based on the user query, without any formatting or newlines. The answer must contain only valid SQL command. - """), - ("human", "{query}"), - ] -) - -final_prompt_template = ChatPromptTemplate.from_messages( - [ - ("system", """ - You are a helpful AI assistant that can understand Postgresql replies and explain this data to the user. The database has the next tables schema: - {db_schema} - Postgresql reply: - {postgres_reply} - Base your answer on the provided user query and Postgresql reply. - Generate a draft response using the selected information. - It should be easy to understand your answer. Don't add any introductory words, start answering right away. - Keep your answer to a one or two sentences (if possible) that specifically answers the user's question. If not - try to keep the answer short, summarizing the returned data. - Generate your final response after adjusting it to increase accuracy and relevance. - Now only show your final response! - If you do not know the answer or context is not relevant, response with "I don't know". - """), - ("human", "{query}"), - ] -) - -def postgres_query(query): - try: - postgres_reply = conn.execute(query) - except psycopg.Error as e: - print("Unable to process query") - return False - colnames = [desc[0] for desc in postgres_reply.description] - postgres_reply_data = postgres_reply.fetchall() - if postgres_reply_data == []: - print("Received empty SQL answer") - return False - postgres_reply_formatted=tabulate(postgres_reply_data, headers=colnames, tablefmt='psql') - return postgres_reply_formatted - - -def handle_query(query): - sql_prompt_value=sql_prompt_template.format_messages(db_schema=db_schema_formatted, query=query) - sql_query=llm.invoke(sql_prompt_value).content - print(sql_query) - postgres_reply=postgres_query(sql_query) - if postgres_reply == False: - return "Try another query" - print(postgres_reply) - final_prompt_value=final_prompt_template.format_messages(db_schema=db_schema_formatted, query=query, postgres_reply=postgres_reply) - return llm.invoke(final_prompt_value).content - -print(handle_query("Please calculate the total sum of all John transactions.")) -print(handle_query("Which woman spent more money in 2023 and how much?")) -print(handle_query("Who let the dogs out?")) -print(handle_query("Who bought more electronics in last month?")) -print(handle_query("Who bought more electronics in 10 last months?")) diff --git a/ai-ml/nl-to-sql/manifests/04-notebook/script.py b/ai-ml/nl-to-sql/manifests/04-notebook/script.py index 5e086392e3..70e674dd46 100644 --- a/ai-ml/nl-to-sql/manifests/04-notebook/script.py +++ b/ai-ml/nl-to-sql/manifests/04-notebook/script.py @@ -6,9 +6,9 @@ conn = psycopg.connect( dbname=os.environ.get("DATABASE_NAME"), - host=os.environ.get("POSTGRES_URL"), - user=os.environ.get("OWNERUSERNAME"), - password=os.environ.get("OWNERPASSWORD"), + host=os.environ.get("POSTGRES_ENDPOINT"), + user=os.environ.get("DBUSERNAME"), + password=os.environ.get("DBPASSWORD"), autocommit=True) db_schema = conn.execute("SELECT table_name, column_name as Columns, data_type as DataTypes FROM information_schema.columns where table_name NOT LIKE 'pg_stat%' AND table_schema='public' order by table_name,column_name;") From fdc4d6a4d910ea880b5740343e73b7c7f6ba4538 Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Thu, 23 May 2024 13:23:30 +0200 Subject: [PATCH 12/28] update tags --- .../01-postgres-cluster/my-cluster.yaml | 6 +- ai-ml/nl-to-sql/manifests/02-dataset/job.yaml | 17 ++++ ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml | 4 +- .../manifests/04-notebook/jupyter.yaml | 79 ------------------- 4 files changed, 22 insertions(+), 84 deletions(-) delete mode 100644 ai-ml/nl-to-sql/manifests/04-notebook/jupyter.yaml diff --git a/ai-ml/nl-to-sql/manifests/01-postgres-cluster/my-cluster.yaml b/ai-ml/nl-to-sql/manifests/01-postgres-cluster/my-cluster.yaml index 081911321a..b26e6b7165 100644 --- a/ai-ml/nl-to-sql/manifests/01-postgres-cluster/my-cluster.yaml +++ b/ai-ml/nl-to-sql/manifests/01-postgres-cluster/my-cluster.yaml @@ -1,4 +1,4 @@ -# Copyright 2023 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# [START gke_databases_postgres_zalando_manifests_01_cluster] +# [START gke_ai_ml_nl_to_sql_manifests_01_postgres_cluster] apiVersion: "acid.zalan.do/v1" kind: postgresql metadata: @@ -84,4 +84,4 @@ spec: value: "$(POSTGRES_USER)" - name: "DATA_SOURCE_PASS" value: "$(POSTGRES_PASSWORD)" -# [END gke_databases_postgres_zalando_manifests_01_cluster] +# [END gke_ai_ml_nl_to_sql_manifests_01_postgres_cluster] diff --git a/ai-ml/nl-to-sql/manifests/02-dataset/job.yaml b/ai-ml/nl-to-sql/manifests/02-dataset/job.yaml index 96c3b10ee8..c896be5239 100644 --- a/ai-ml/nl-to-sql/manifests/02-dataset/job.yaml +++ b/ai-ml/nl-to-sql/manifests/02-dataset/job.yaml @@ -1,3 +1,18 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START gke_ai_ml_nl_to_sql_manifests_02_dataset] apiVersion: batch/v1 kind: Job metadata: @@ -35,3 +50,5 @@ spec: name: customers-dataset defaultMode: 0500 restartPolicy: Never +# [END gke_ai_ml_nl_to_sql_manifests_02_dataset] + diff --git a/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml b/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml index 3d9561665b..7b75f8c353 100644 --- a/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml +++ b/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# [START gke_ai_ml_llm_serving_gemma_tgi_2b_it_deployment] +# [START gke_ai_ml_nl_to_sql_manifests_03_llm] apiVersion: apps/v1 kind: Deployment metadata: @@ -80,4 +80,4 @@ spec: - protocol: TCP port: 8000 targetPort: 8000 -# [END gke_ai_ml_llm_serving_gemma_tgi_2b_it_deployment] +# [END gke_ai_ml_nl_to_sql_manifests_03_llm] diff --git a/ai-ml/nl-to-sql/manifests/04-notebook/jupyter.yaml b/ai-ml/nl-to-sql/manifests/04-notebook/jupyter.yaml deleted file mode 100644 index b29e9f040b..0000000000 --- a/ai-ml/nl-to-sql/manifests/04-notebook/jupyter.yaml +++ /dev/null @@ -1,79 +0,0 @@ -# Copyright 2024 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# [START gke_databases_postgres_pgvector_02_notebook] ---- -apiVersion: v1 -kind: Service -metadata: - labels: &labels - app: jupyter-notebook - name: notebook -spec: - ports: - - port: 8888 - selector: *labels - #type: LoadBalancer - type: ClusterIP ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: notebook - labels: &labels - app: jupyter-notebook -spec: - selector: - matchLabels: *labels - template: - metadata: - labels: *labels - spec: - containers: - - name: jupyter - image: tensorflow/tensorflow:2.15.0-jupyter - resources: - requests: - memory: "800Mi" - cpu: "1" - limits: - memory: "800Mi" - cpu: "1" - ports: - - containerPort: 8888 - env: - - name: OWNERPASSWORD - valueFrom: - secretKeyRef: - name: mydatabaseowner.my-cluster.credentials.postgresql.acid.zalan.do - key: password - - name: OWNERUSERNAME - valueFrom: - secretKeyRef: - name: mydatabaseowner.my-cluster.credentials.postgresql.acid.zalan.do - key: username - - name: POSTGRES_URL - value: my-cluster.postgres - - name: DATABASE_NAME - value: mydatabase - - name: LLM_ENDPOINT - value: http://llm-service.llm:8000/ -# volumeMounts: -# - name: notebook -# mountPath: /tf -# volumes: -# - name: notebook -# configMap: -# name: notebook - # [END gke_databases_postgres_pgvector_02_notebook] From a4f2a081d2f57fcde00566db37168243ea214d60 Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Thu, 23 May 2024 17:32:49 +0200 Subject: [PATCH 13/28] notebook update --- .../manifests/04-notebook/notebook.ipynb | 321 +++--------------- .../nl-to-sql/manifests/04-notebook/script.py | 84 ----- 2 files changed, 41 insertions(+), 364 deletions(-) delete mode 100644 ai-ml/nl-to-sql/manifests/04-notebook/script.py diff --git a/ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb b/ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb index 55ea218c0e..6afb698d49 100644 --- a/ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb +++ b/ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb @@ -23,97 +23,17 @@ "apt-get update && sudo apt-get install google-cloud-cli-gke-gcloud-auth-plugin\n" ], "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, "collapsed": true, - "id": "tiGscdCpo2KC", - "executionInfo": { - "status": "ok", - "timestamp": 1716459651838, - "user_tz": -120, - "elapsed": 11442, - "user": { - "displayName": "", - "userId": "" - } - }, - "outputId": "ff824e08-14bf-4ffb-936e-fa586015fe81" + "id": "tiGscdCpo2KC" }, "id": "tiGscdCpo2KC", - "execution_count": 60, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "Hit:1 https://packages.cloud.google.com/apt cloud-sdk InRelease\n", - "Hit:2 https://cloud.r-project.org/bin/linux/ubuntu jammy-cran40/ InRelease\n", - "Get:3 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]\n", - "Hit:4 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64 InRelease\n", - "Hit:5 http://archive.ubuntu.com/ubuntu jammy InRelease\n", - "Get:6 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]\n", - "Hit:7 https://ppa.launchpadcontent.net/c2d4u.team/c2d4u4.0+/ubuntu jammy InRelease\n", - "Hit:8 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy InRelease\n", - "Hit:9 https://ppa.launchpadcontent.net/graphics-drivers/ppa/ubuntu jammy InRelease\n", - "Hit:10 https://ppa.launchpadcontent.net/ubuntugis/ppa/ubuntu jammy InRelease\n", - "Hit:11 http://archive.ubuntu.com/ubuntu jammy-backports InRelease\n", - "Fetched 229 kB in 1s (172 kB/s)\n", - "Reading package lists...\n", - "Reading package lists...\n", - "Building dependency tree...\n", - "Reading state information...\n", - "ca-certificates is already the newest version (20230311ubuntu0.22.04.1).\n", - "gnupg is already the newest version (2.2.27-3ubuntu2.1).\n", - "apt-transport-https is already the newest version (2.4.12).\n", - "0 upgraded, 0 newly installed, 0 to remove and 46 not upgraded.\n", - "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main\n", - "Hit:1 https://packages.cloud.google.com/apt cloud-sdk InRelease\n", - "Hit:2 https://cloud.r-project.org/bin/linux/ubuntu jammy-cran40/ InRelease\n", - "Hit:3 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64 InRelease\n", - "Hit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease\n", - "Hit:5 http://archive.ubuntu.com/ubuntu jammy InRelease\n", - "Hit:6 http://archive.ubuntu.com/ubuntu jammy-updates InRelease\n", - "Hit:7 http://archive.ubuntu.com/ubuntu jammy-backports InRelease\n", - "Hit:8 https://ppa.launchpadcontent.net/c2d4u.team/c2d4u4.0+/ubuntu jammy InRelease\n", - "Hit:9 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy InRelease\n", - "Hit:10 https://ppa.launchpadcontent.net/graphics-drivers/ppa/ubuntu jammy InRelease\n", - "Hit:11 https://ppa.launchpadcontent.net/ubuntugis/ppa/ubuntu jammy InRelease\n", - "Reading package lists...\n", - "Reading package lists...\n", - "Building dependency tree...\n", - "Reading state information...\n", - "google-cloud-cli-gke-gcloud-auth-plugin is already the newest version (477.0.0-0).\n", - "0 upgraded, 0 newly installed, 0 to remove and 46 not upgraded.\n" - ] - }, - { - "output_type": "stream", - "name": "stderr", - "text": [ - " % Total % Received % Xferd Average Speed Time Time Time Current\n", - " Dload Upload Total Spent Left Speed\n", - "\r 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\r100 138 100 138 0 0 2138 0 --:--:-- --:--:-- --:--:-- 2156\n", - "\r100 49.0M 100 49.0M 0 0 118M 0 --:--:-- --:--:-- --:--:-- 118M\n", - " % Total % Received % Xferd Average Speed Time Time Time Current\n", - " Dload Upload Total Spent Left Speed\n", - "\r 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0gpg: cannot open '/dev/tty': No such device or address\n", - "\r100 2659 100 2659 0 0 36694 0 --:--:-- --:--:-- --:--:-- 36930\n", - "curl: (23) Failed writing body\n", - "W: Target Packages (main/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list.d/google-cloud-sdk.list:1 and /etc/apt/sources.list.d/google-cloud-sdk.list:2\n", - "W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list.d/google-cloud-sdk.list:1 and /etc/apt/sources.list.d/google-cloud-sdk.list:2\n", - "W: Target Packages (main/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list.d/google-cloud-sdk.list:1 and /etc/apt/sources.list.d/google-cloud-sdk.list:2\n", - "W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list.d/google-cloud-sdk.list:1 and /etc/apt/sources.list.d/google-cloud-sdk.list:2\n", - "W: Target Packages (main/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list.d/google-cloud-sdk.list:1 and /etc/apt/sources.list.d/google-cloud-sdk.list:2\n", - "W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list.d/google-cloud-sdk.list:1 and /etc/apt/sources.list.d/google-cloud-sdk.list:2\n" - ] - } - ] + "execution_count": null, + "outputs": [] }, { "cell_type": "markdown", "source": [ - "Retrieves the GKE cluster's credentials using the **gcloud** command:" + "**Replace** with your cluster name, e.g. postgres-cluster. Retrieve the GKE cluster's credentials using the **gcloud** command:" ], "metadata": { "id": "Q8x_lxTXrZTi" @@ -125,38 +45,15 @@ "source": [ "%%bash\n", "\n", - "export KUBERNETES_CLUSTER_NAME=\"nltosql-dima\"\n", + "export KUBERNETES_CLUSTER_NAME=\n", "gcloud container clusters get-credentials $KUBERNETES_CLUSTER_NAME --region $GOOGLE_CLOUD_REGION" ], "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "n1c8Fsk1rcrK", - "executionInfo": { - "status": "ok", - "timestamp": 1716458517839, - "user_tz": -120, - "elapsed": 1203, - "user": { - "displayName": "", - "userId": "" - } - }, - "outputId": "551cbaf9-0498-44fc-e0d0-688c41dc3d34" + "id": "n1c8Fsk1rcrK" }, "id": "n1c8Fsk1rcrK", - "execution_count": 37, - "outputs": [ - { - "output_type": "stream", - "name": "stderr", - "text": [ - "Fetching cluster endpoint and auth data.\n", - "kubeconfig entry generated for nltosql-dima.\n" - ] - } - ] + "execution_count": null, + "outputs": [] }, { "cell_type": "markdown", @@ -180,20 +77,10 @@ "echo DBPASSWORD=$(kubectl get secret mydatabaseowner.my-cluster.credentials.postgresql.acid.zalan.do -n postgres --template={{.data.password}} | base64 -d) >> .env" ], "metadata": { - "id": "6lo6M4AqsAru", - "executionInfo": { - "status": "ok", - "timestamp": 1716460066445, - "user_tz": -120, - "elapsed": 1696, - "user": { - "displayName": "", - "userId": "" - } - } + "id": "6lo6M4AqsAru" }, "id": "6lo6M4AqsAru", - "execution_count": 61, + "execution_count": null, "outputs": [] }, { @@ -212,113 +99,11 @@ "! pip install python-dotenv psycopg-binary psycopg tabulate text-generation langchain langchain-community" ], "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "uwspErB44izG", - "executionInfo": { - "status": "ok", - "timestamp": 1716458594128, - "user_tz": -120, - "elapsed": 19693, - "user": { - "displayName": "", - "userId": "" - } - }, - "outputId": "09fb9da5-c595-4db9-b9ca-3d26fa54d5b9" + "id": "uwspErB44izG" }, "id": "uwspErB44izG", - "execution_count": 39, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "Requirement already satisfied: python-dotenv in /usr/local/lib/python3.10/dist-packages (1.0.1)\n", - "Collecting psycopg-binary\n", - " Downloading psycopg_binary-3.1.19-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.3/3.3 MB\u001b[0m \u001b[31m11.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hCollecting psycopg\n", - " Downloading psycopg-3.1.19-py3-none-any.whl (179 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m179.4/179.4 kB\u001b[0m \u001b[31m18.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hRequirement already satisfied: tabulate in /usr/local/lib/python3.10/dist-packages (0.9.0)\n", - "Collecting text-generation\n", - " Downloading text_generation-0.7.0-py3-none-any.whl (12 kB)\n", - "Collecting langchain\n", - " Downloading langchain-0.2.0-py3-none-any.whl (973 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m973.7/973.7 kB\u001b[0m \u001b[31m38.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hCollecting langchain-community\n", - " Downloading langchain_community-0.2.0-py3-none-any.whl (2.1 MB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.1/2.1 MB\u001b[0m \u001b[31m69.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hRequirement already satisfied: typing-extensions>=4.1 in /usr/local/lib/python3.10/dist-packages (from psycopg) (4.11.0)\n", - "Requirement already satisfied: aiohttp<4.0,>=3.8 in /usr/local/lib/python3.10/dist-packages (from text-generation) (3.9.5)\n", - "Requirement already satisfied: huggingface-hub<1.0,>=0.12 in /usr/local/lib/python3.10/dist-packages (from text-generation) (0.20.3)\n", - "Collecting pydantic<3,>2 (from text-generation)\n", - " Downloading pydantic-2.7.1-py3-none-any.whl (409 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m409.3/409.3 kB\u001b[0m \u001b[31m38.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hRequirement already satisfied: PyYAML>=5.3 in /usr/local/lib/python3.10/dist-packages (from langchain) (6.0.1)\n", - "Requirement already satisfied: SQLAlchemy<3,>=1.4 in /usr/local/lib/python3.10/dist-packages (from langchain) (2.0.30)\n", - "Requirement already satisfied: async-timeout<5.0.0,>=4.0.0 in /usr/local/lib/python3.10/dist-packages (from langchain) (4.0.3)\n", - "Collecting dataclasses-json<0.7,>=0.5.7 (from langchain)\n", - " Downloading dataclasses_json-0.6.6-py3-none-any.whl (28 kB)\n", - "Collecting langchain-core<0.3.0,>=0.2.0 (from langchain)\n", - " Downloading langchain_core-0.2.1-py3-none-any.whl (308 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m308.5/308.5 kB\u001b[0m \u001b[31m29.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hCollecting langchain-text-splitters<0.3.0,>=0.2.0 (from langchain)\n", - " Downloading langchain_text_splitters-0.2.0-py3-none-any.whl (23 kB)\n", - "Collecting langsmith<0.2.0,>=0.1.17 (from langchain)\n", - " Downloading langsmith-0.1.62-py3-none-any.whl (122 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m122.3/122.3 kB\u001b[0m \u001b[31m14.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hRequirement already satisfied: numpy<2,>=1 in /usr/local/lib/python3.10/dist-packages (from langchain) (1.25.2)\n", - "Requirement already satisfied: requests<3,>=2 in /usr/local/lib/python3.10/dist-packages (from langchain) (2.31.0)\n", - "Requirement already satisfied: tenacity<9.0.0,>=8.1.0 in /usr/local/lib/python3.10/dist-packages (from langchain) (8.3.0)\n", - "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0,>=3.8->text-generation) (1.3.1)\n", - "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0,>=3.8->text-generation) (23.2.0)\n", - "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0,>=3.8->text-generation) (1.4.1)\n", - "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0,>=3.8->text-generation) (6.0.5)\n", - "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0,>=3.8->text-generation) (1.9.4)\n", - "Collecting marshmallow<4.0.0,>=3.18.0 (from dataclasses-json<0.7,>=0.5.7->langchain)\n", - " Downloading marshmallow-3.21.2-py3-none-any.whl (49 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.3/49.3 kB\u001b[0m \u001b[31m8.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hCollecting typing-inspect<1,>=0.4.0 (from dataclasses-json<0.7,>=0.5.7->langchain)\n", - " Downloading typing_inspect-0.9.0-py3-none-any.whl (8.8 kB)\n", - "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.12->text-generation) (3.14.0)\n", - "Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.12->text-generation) (2023.6.0)\n", - "Requirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.12->text-generation) (4.66.4)\n", - "Requirement already satisfied: packaging>=20.9 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.12->text-generation) (24.0)\n", - "Collecting jsonpatch<2.0,>=1.33 (from langchain-core<0.3.0,>=0.2.0->langchain)\n", - " Downloading jsonpatch-1.33-py2.py3-none-any.whl (12 kB)\n", - "Collecting packaging>=20.9 (from huggingface-hub<1.0,>=0.12->text-generation)\n", - " Downloading packaging-23.2-py3-none-any.whl (53 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m53.0/53.0 kB\u001b[0m \u001b[31m7.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hCollecting orjson<4.0.0,>=3.9.14 (from langsmith<0.2.0,>=0.1.17->langchain)\n", - " Downloading orjson-3.10.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (142 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m142.5/142.5 kB\u001b[0m \u001b[31m17.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hRequirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>2->text-generation) (0.6.0)\n", - "Requirement already satisfied: pydantic-core==2.18.2 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>2->text-generation) (2.18.2)\n", - "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain) (3.3.2)\n", - "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain) (3.7)\n", - "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain) (2.0.7)\n", - "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain) (2024.2.2)\n", - "Requirement already satisfied: greenlet!=0.4.17 in /usr/local/lib/python3.10/dist-packages (from SQLAlchemy<3,>=1.4->langchain) (3.0.3)\n", - "Collecting jsonpointer>=1.9 (from jsonpatch<2.0,>=1.33->langchain-core<0.3.0,>=0.2.0->langchain)\n", - " Downloading jsonpointer-2.4-py2.py3-none-any.whl (7.8 kB)\n", - "Collecting mypy-extensions>=0.3.0 (from typing-inspect<1,>=0.4.0->dataclasses-json<0.7,>=0.5.7->langchain)\n", - " Downloading mypy_extensions-1.0.0-py3-none-any.whl (4.7 kB)\n", - "Installing collected packages: psycopg-binary, psycopg, packaging, orjson, mypy-extensions, jsonpointer, typing-inspect, pydantic, marshmallow, jsonpatch, text-generation, langsmith, dataclasses-json, langchain-core, langchain-text-splitters, langchain, langchain-community\n", - " Attempting uninstall: packaging\n", - " Found existing installation: packaging 24.0\n", - " Uninstalling packaging-24.0:\n", - " Successfully uninstalled packaging-24.0\n", - " Attempting uninstall: pydantic\n", - " Found existing installation: pydantic 1.10.15\n", - " Uninstalling pydantic-1.10.15:\n", - " Successfully uninstalled pydantic-1.10.15\n", - "Successfully installed dataclasses-json-0.6.6 jsonpatch-1.33 jsonpointer-2.4 langchain-0.2.0 langchain-community-0.2.0 langchain-core-0.2.1 langchain-text-splitters-0.2.0 langsmith-0.1.62 marshmallow-3.21.2 mypy-extensions-1.0.0 orjson-3.10.3 packaging-23.2 psycopg-3.1.19 psycopg-binary-3.1.19 pydantic-2.7.1 text-generation-0.7.0 typing-inspect-0.9.0\n" - ] - } - ] + "execution_count": null, + "outputs": [] }, { "cell_type": "markdown", @@ -344,9 +129,9 @@ "id": "oqq4NDgvt-XT", "executionInfo": { "status": "ok", - "timestamp": 1716458612004, + "timestamp": 1716475532717, "user_tz": -120, - "elapsed": 1593, + "elapsed": 342, "user": { "displayName": "", "userId": "" @@ -354,7 +139,7 @@ } }, "id": "oqq4NDgvt-XT", - "execution_count": 40, + "execution_count": 70, "outputs": [] }, { @@ -387,9 +172,9 @@ "id": "7M-IQwbM6AgY", "executionInfo": { "status": "ok", - "timestamp": 1716460212145, + "timestamp": 1716475539251, "user_tz": -120, - "elapsed": 495, + "elapsed": 332, "user": { "displayName": "", "userId": "" @@ -397,7 +182,7 @@ } }, "id": "7M-IQwbM6AgY", - "execution_count": 62, + "execution_count": 71, "outputs": [] }, { @@ -452,9 +237,9 @@ "id": "RKLr5riV6uZW", "executionInfo": { "status": "ok", - "timestamp": 1716460319140, + "timestamp": 1716475853538, "user_tz": -120, - "elapsed": 1, + "elapsed": 399, "user": { "displayName": "", "userId": "" @@ -462,7 +247,7 @@ } }, "id": "RKLr5riV6uZW", - "execution_count": 63, + "execution_count": 74, "outputs": [] }, { @@ -487,7 +272,7 @@ " colnames = [desc[0] for desc in postgres_reply.description]\n", " postgres_reply_data = postgres_reply.fetchall()\n", " if postgres_reply_data == []:\n", - " print(\"Received empty SQL answer\")\n", + " print(\"Received empty SQL reply\")\n", " return False\n", " postgres_reply_formatted=tabulate(postgres_reply_data, headers=colnames, tablefmt='psql')\n", " return postgres_reply_formatted\n", @@ -495,22 +280,28 @@ "\n", "def llm_query(query):\n", " sql_prompt_value=sql_prompt_template.format(db_schema=db_schema_formatted, query=query)\n", + " #print(sql_prompt_value)\n", + " #print(\"-----\")\n", " sql_query=llm.invoke(sql_prompt_value)\n", - " # print(sql_query)\n", + " #print(sql_query)\n", + " #print(\"-----\")\n", " postgres_reply=postgres_query(sql_query)\n", " if postgres_reply == False:\n", " return \"Try another query\"\n", - " # print(postgres_reply)\n", + " #print(postgres_reply)\n", + " #print(\"-----\")\n", " final_prompt_value=final_prompt_template.format(db_schema=db_schema_formatted, query=query, postgres_reply=postgres_reply)\n", + " #print(final_prompt_value)\n", + " #print(\"----\")\n", " return llm.invoke(final_prompt_value)" ], "metadata": { "id": "a_6XVEtH7dFv", "executionInfo": { "status": "ok", - "timestamp": 1716459014750, + "timestamp": 1716476680742, "user_tz": -120, - "elapsed": 328, + "elapsed": 375, "user": { "displayName": "", "userId": "" @@ -518,13 +309,13 @@ } }, "id": "a_6XVEtH7dFv", - "execution_count": 52, + "execution_count": 81, "outputs": [] }, { "cell_type": "markdown", "source": [ - "Run some queries to demonstrate the moability to generate SQL commands from user queries and provide responses based on the PostgreSQL replies:" + "Run some queries to demonstrate the model's ability to generate SQL commands from user queries and provide responses based on the PostgreSQL replies:" ], "metadata": { "id": "LMMBr-gu7g0I" @@ -538,44 +329,15 @@ "print(llm_query(\"Which woman spent more money in 2023 and how much?\"))\n", "print(llm_query(\"What is the capital of Great Britain?\"))\n", "print(llm_query(\"Who spent more money on electronics in last month?\"))\n", - "print(llm_query(\"Who spent more money on electronics in 10 last months?\"))\n", + "print(llm_query(\"Who spent more money on electronics in last year?\"))\n", "print(llm_query(\"Give me top 3 buyers of clothing. How much money each person spent?\"))" ], "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "HQZ1gUYY7iLn", - "executionInfo": { - "status": "ok", - "timestamp": 1716459463391, - "user_tz": -120, - "elapsed": 29595, - "user": { - "displayName": "", - "userId": "" - } - }, - "outputId": "b6dd1d33-dcbf-4bef-cb1f-304c31d6171e" + "id": "HQZ1gUYY7iLn" }, "id": "HQZ1gUYY7iLn", - "execution_count": 59, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "The total sum of all John's transactions is 6210.\n", - "Elizabeth spent $15,950 in 2023.\n", - "Unable to process query\n", - "Try another query\n", - "Received empty SQL answer\n", - "Try another query\n", - "Elizabeth spent the most money on electronics in the last 10 months, with a total amount of $5750.\n", - "The top 3 buyers of clothing are Brenda, Melissa, and Sarah, who spent $7755, $7550, and $5775 respectively.\n" - ] - } - ] + "execution_count": null, + "outputs": [] } ], "metadata": { @@ -597,10 +359,9 @@ "version": "3.10.10" }, "colab": { - "provenance": [], - "name": "dmitrii_ganochenko (May 23, 2024, 10:47:16 AM)" + "provenance": [] } }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/ai-ml/nl-to-sql/manifests/04-notebook/script.py b/ai-ml/nl-to-sql/manifests/04-notebook/script.py deleted file mode 100644 index 70e674dd46..0000000000 --- a/ai-ml/nl-to-sql/manifests/04-notebook/script.py +++ /dev/null @@ -1,84 +0,0 @@ -import psycopg -import os -from tabulate import tabulate -from langchain_community.llms import HuggingFaceTextGenInference -from langchain_core.prompts import PromptTemplate - -conn = psycopg.connect( - dbname=os.environ.get("DATABASE_NAME"), - host=os.environ.get("POSTGRES_ENDPOINT"), - user=os.environ.get("DBUSERNAME"), - password=os.environ.get("DBPASSWORD"), - autocommit=True) - -db_schema = conn.execute("SELECT table_name, column_name as Columns, data_type as DataTypes FROM information_schema.columns where table_name NOT LIKE 'pg_stat%' AND table_schema='public' order by table_name,column_name;") -colnames = [desc[0] for desc in db_schema.description] -db_schema_formatted=tabulate(db_schema.fetchall(), headers=colnames, tablefmt='psql') - -llm = HuggingFaceTextGenInference( - inference_server_url=os.environ.get("LLM_ENDPOINT"), - temperature=0.5, - top_k=5, - top_p=0.5, - repetition_penalty=1.03, -) - -sql_prompt_template = PromptTemplate.from_template(""" - <|begin_of_text|><|start_header_id|>system<|end_header_id|> - You are a helpful AI assistant that can transform user queries into SQL commands to retrieve the data from the Postgresql database. The database has the next tables schema: - {db_schema} - Please prepare and return only the SQL command, based on the user query, without any formatting or newlines. The answer must contain only valid SQL command.<|eot_id|><|start_header_id|>user<|end_header_id|> - {query}<|eot_id|><|start_header_id|>assistant<|end_header_id|> -""") - -final_prompt_template = PromptTemplate.from_template(""" - <|begin_of_text|><|start_header_id|>system<|end_header_id|> - You are a helpful AI assistant that can understand Postgresql replies and explain this data to the user. The database has the next tables schema: - {db_schema} - User query: {query} - Postgresql reply: - {postgres_reply} - Base your answer on the provided user query and Postgresql reply. - Generate a draft response using the selected information. - It should be easy to understand your answer. Don't add any introductory words, start answering right away. - Keep your answer to a one or two sentences (if possible) that specifically answers the user's question. If not - try to keep the answer short, summarizing the returned data. - Generate your final response after adjusting it to increase accuracy and relevance. - Now only show your final response! - If you do not know the answer or context is not relevant, response with "I don't know". - <|eot_id|><|start_header_id|>assistant<|end_header_id|> -""") - - -def postgres_query(query): - try: - postgres_reply = conn.execute(query) - except psycopg.Error as e: - print("Unable to process query") - return False - colnames = [desc[0] for desc in postgres_reply.description] - postgres_reply_data = postgres_reply.fetchall() - if postgres_reply_data == []: - print("Received empty SQL answer") - return False - postgres_reply_formatted=tabulate(postgres_reply_data, headers=colnames, tablefmt='psql') - return postgres_reply_formatted - - -def llm_query(query): - sql_prompt_value=sql_prompt_template.format(db_schema=db_schema_formatted, query=query) - sql_query=llm.invoke(sql_prompt_value) - # print(sql_query) - postgres_reply=postgres_query(sql_query) - if postgres_reply == False: - return "Try another query" - # print(postgres_reply) - final_prompt_value=final_prompt_template.format(db_schema=db_schema_formatted, query=query, postgres_reply=postgres_reply) - return llm.invoke(final_prompt_value) - - -print(llm_query("Please calculate the total sum of all John transactions.")) -print(llm_query("Which woman spent more money in 2023 and how much?")) -print(llm_query("Who let the dogs out?")) -print(llm_query("Who bought more electronics in last month?")) -print(llm_query("Who bought more electronics in 10 last months?")) -print(llm_query("Give me top 3 buyers of clothing. How much money each person spent?")) From 437dcfae847b85df1447f59d597a0a5afffd38a4 Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Mon, 27 May 2024 10:56:31 +0200 Subject: [PATCH 14/28] notebook quickfix --- ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb b/ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb index 6afb698d49..e5b2d0adb2 100644 --- a/ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb +++ b/ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb @@ -33,7 +33,7 @@ { "cell_type": "markdown", "source": [ - "**Replace** with your cluster name, e.g. postgres-cluster. Retrieve the GKE cluster's credentials using the **gcloud** command:" + "**Replace** with your cluster name, e.g. sqlgen-cluster. Retrieve the GKE cluster's credentials using the **gcloud** command:" ], "metadata": { "id": "Q8x_lxTXrZTi" From c2964ca3cf57313196cbeffcb3194028e2384717 Mon Sep 17 00:00:00 2001 From: BRV158 Date: Tue, 28 May 2024 13:09:03 +0300 Subject: [PATCH 15/28] terraform added --- .../nl-to-sql/terraform/gke-autopilot/main.tf | 37 +++++++++ .../terraform/gke-autopilot/variables.tf | 27 ++++++ .../terraform/gke-autopilot/versions.tf | 23 ++++++ .../terraform/gke-standard/README.md | 26 ++++++ .../nl-to-sql/terraform/gke-standard/main.tf | 82 +++++++++++++++++++ .../terraform/gke-standard/variables.tf | 61 ++++++++++++++ .../terraform/gke-standard/versions.tf | 23 ++++++ .../modules/cluster-autopilot/main.tf | 39 +++++++++ .../modules/cluster-autopilot/variables.tf | 34 ++++++++ .../modules/cluster-autopilot/versions.tf | 23 ++++++ .../terraform/modules/cluster/main.tf | 54 ++++++++++++ .../terraform/modules/cluster/variables.tf | 49 +++++++++++ .../terraform/modules/cluster/versions.tf | 31 +++++++ .../terraform/modules/network/main.tf | 68 +++++++++++++++ .../terraform/modules/network/variables.tf | 26 ++++++ .../terraform/modules/network/versions.tf | 23 ++++++ 16 files changed, 626 insertions(+) create mode 100644 ai-ml/nl-to-sql/terraform/gke-autopilot/main.tf create mode 100644 ai-ml/nl-to-sql/terraform/gke-autopilot/variables.tf create mode 100644 ai-ml/nl-to-sql/terraform/gke-autopilot/versions.tf create mode 100644 ai-ml/nl-to-sql/terraform/gke-standard/README.md create mode 100644 ai-ml/nl-to-sql/terraform/gke-standard/main.tf create mode 100644 ai-ml/nl-to-sql/terraform/gke-standard/variables.tf create mode 100644 ai-ml/nl-to-sql/terraform/gke-standard/versions.tf create mode 100644 ai-ml/nl-to-sql/terraform/modules/cluster-autopilot/main.tf create mode 100644 ai-ml/nl-to-sql/terraform/modules/cluster-autopilot/variables.tf create mode 100644 ai-ml/nl-to-sql/terraform/modules/cluster-autopilot/versions.tf create mode 100644 ai-ml/nl-to-sql/terraform/modules/cluster/main.tf create mode 100644 ai-ml/nl-to-sql/terraform/modules/cluster/variables.tf create mode 100644 ai-ml/nl-to-sql/terraform/modules/cluster/versions.tf create mode 100644 ai-ml/nl-to-sql/terraform/modules/network/main.tf create mode 100644 ai-ml/nl-to-sql/terraform/modules/network/variables.tf create mode 100644 ai-ml/nl-to-sql/terraform/modules/network/versions.tf diff --git a/ai-ml/nl-to-sql/terraform/gke-autopilot/main.tf b/ai-ml/nl-to-sql/terraform/gke-autopilot/main.tf new file mode 100644 index 0000000000..415f2e5035 --- /dev/null +++ b/ai-ml/nl-to-sql/terraform/gke-autopilot/main.tf @@ -0,0 +1,37 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# create private subnet +module "network" { + source = "../modules/network" + project_id = var.project_id + region = var.region + cluster_prefix = var.cluster_prefix +} + +# [START gke_aiml_sqlgen_autopilot_private_regional_cluster] +module "sqlgen_cluster" { + source = "../modules/cluster-autopilot" + project_id = var.project_id + region = var.region + cluster_prefix = var.cluster_prefix + network = module.network.network_name + subnetwork = module.network.subnet_name +} + +output "kubectl_connection_command" { + value = "gcloud container clusters get-credentials ${var.cluster_prefix}-cluster --region ${var.region}" + description = "Connection command" +} +# [END gke_aiml_sqlgen_autopilot_private_regional_cluster] \ No newline at end of file diff --git a/ai-ml/nl-to-sql/terraform/gke-autopilot/variables.tf b/ai-ml/nl-to-sql/terraform/gke-autopilot/variables.tf new file mode 100644 index 0000000000..6aa3802142 --- /dev/null +++ b/ai-ml/nl-to-sql/terraform/gke-autopilot/variables.tf @@ -0,0 +1,27 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +variable "project_id" { + description = "The project ID to host the cluster in" + default = "" +} + +variable "region" { + description = "The region to host the cluster in" +} + +variable "cluster_prefix" { + description = "The prefix for all cluster resources" + default = "sqlgen" +} \ No newline at end of file diff --git a/ai-ml/nl-to-sql/terraform/gke-autopilot/versions.tf b/ai-ml/nl-to-sql/terraform/gke-autopilot/versions.tf new file mode 100644 index 0000000000..f8bded9171 --- /dev/null +++ b/ai-ml/nl-to-sql/terraform/gke-autopilot/versions.tf @@ -0,0 +1,23 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +terraform { + required_providers { + google = { + source = "hashicorp/google" + version = "~> 5.0" + } + } + required_version = ">= 1.3" +} diff --git a/ai-ml/nl-to-sql/terraform/gke-standard/README.md b/ai-ml/nl-to-sql/terraform/gke-standard/README.md new file mode 100644 index 0000000000..d4a5626735 --- /dev/null +++ b/ai-ml/nl-to-sql/terraform/gke-standard/README.md @@ -0,0 +1,26 @@ +# Terraform to provision GKE Standard + +## Prerequisites and Assumptions +* Done initialization of the project and gcloud CLI following the instructions in `{ROOT}/README.md` +* VPC network, refer to `gke` folder for the details + +## Usage +``` +export GOOGLE_OAUTH_ACCESS_TOKEN=$(gcloud auth print-access-token) +export PROJECT_ID="your project" +export REGION="us-central1" +export CLUSTER_PREFIX="sqlgen" + +terraform init +terraform plan -var project_id=$PROJECT_ID -var region=${REGION} -var cluster_prefix=${CLUSTER_PREFIX} +terraform apply -var project_id=$PROJECT_ID -var region=${REGION} -var cluster_prefix=${CLUSTER_PREFIX} +``` +## Clean up +**NOTE:** Be very careful when destroying any resource, not recommended for production! +``` +# Destroy everything +terraform destroy \ +-var project_id=$PROJECT_ID \ +-var region=${REGION} \ +-var cluster_prefix=${CLUSTER_PREFIX} + diff --git a/ai-ml/nl-to-sql/terraform/gke-standard/main.tf b/ai-ml/nl-to-sql/terraform/gke-standard/main.tf new file mode 100644 index 0000000000..df435c91af --- /dev/null +++ b/ai-ml/nl-to-sql/terraform/gke-standard/main.tf @@ -0,0 +1,82 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# create private subnet +module "network" { + source = "../modules/network" + project_id = var.project_id + region = var.region + cluster_prefix = var.cluster_prefix +} + +# [START gke_aiml_sqlgen_private_regional_cluster] +module "sqlgen_cluster" { + source = "../modules/cluster" + project_id = var.project_id + region = var.region + cluster_prefix = var.cluster_prefix + network = module.network.network_name + subnetwork = module.network.subnet_name + + + node_pools = [ + { + name = "postgres-pool" + disk_size_gb = var.node_disk_size + disk_type = var.node_disk_type + autoscaling = true + min_count = 1 + max_count = var.autoscaling_max_count + max_surge = 1 + max_unavailable = 0 + machine_type = var.node_machine_type + auto_repair = true + }, + { + name = "gpu-pool" + disk_size_gb = var.node_disk_size + disk_type = "pd-balanced" + node_locations = var.node_location + autoscaling = true + min_count = 0 + max_count = var.autoscaling_max_count + max_surge = 1 + max_unavailable = 0 + machine_type = "g2-standard-4" + auto_repair = true + } + ] + node_pools_labels = { + all = {} + postgres-pool = { + "app.stateful/component" = "postgres" + } + } + node_pools_taints = { + all = [] + postgres-pool = [ + { + key = "app.stateful/component" + value = "postgres" + effect = "NO_SCHEDULE" + } + ] + } +} + +output "kubectl_connection_command" { + value = "gcloud container clusters get-credentials ${var.cluster_prefix}-cluster --region ${var.region}" + description = "Connection command" +} +# [END gke_aiml_sqlgen_private_regional_cluster] \ No newline at end of file diff --git a/ai-ml/nl-to-sql/terraform/gke-standard/variables.tf b/ai-ml/nl-to-sql/terraform/gke-standard/variables.tf new file mode 100644 index 0000000000..012acb75d5 --- /dev/null +++ b/ai-ml/nl-to-sql/terraform/gke-standard/variables.tf @@ -0,0 +1,61 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +variable "project_id" { + description = "The project ID to host the cluster in" + default = "" + type = string +} + +variable "region" { + description = "The region to host the cluster in" + type = string +} + +variable "node_location" { + description = "Node location for GPU node pool - please check GPUs node availability in official documentation: https://cloud.google.com/compute/docs/regions-zones" + type = string + default = "us-central1-a,us-central1-b" + +} +variable "cluster_prefix" { + description = "The prefix for all cluster resources" + default = "sqlgen" + type = string +} + +variable "node_machine_type" { + description = "The machine type for node instances" + default = "e2-standard-2" + type = string +} + +variable "node_disk_type" { + description = "The persistent disk type for node instances" + default = "pd-standard" + type = string +} + +variable "node_disk_size" { + description = "The persistent disk size for node instances" + default = 20 + type = number +} + +variable "autoscaling_max_count" { + description = "Maximum node counts per zone" + default = 2 + type = number +} + diff --git a/ai-ml/nl-to-sql/terraform/gke-standard/versions.tf b/ai-ml/nl-to-sql/terraform/gke-standard/versions.tf new file mode 100644 index 0000000000..f8bded9171 --- /dev/null +++ b/ai-ml/nl-to-sql/terraform/gke-standard/versions.tf @@ -0,0 +1,23 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +terraform { + required_providers { + google = { + source = "hashicorp/google" + version = "~> 5.0" + } + } + required_version = ">= 1.3" +} diff --git a/ai-ml/nl-to-sql/terraform/modules/cluster-autopilot/main.tf b/ai-ml/nl-to-sql/terraform/modules/cluster-autopilot/main.tf new file mode 100644 index 0000000000..262258cd65 --- /dev/null +++ b/ai-ml/nl-to-sql/terraform/modules/cluster-autopilot/main.tf @@ -0,0 +1,39 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START gke_aiml_sqlgen_autopilot_private_regional_cluster] +module "sqlgen_cluster" { + source = "terraform-google-modules/kubernetes-engine/google//modules/beta-autopilot-private-cluster" + version = "~> 29.0" + project_id = var.project_id + name = "${var.cluster_prefix}-cluster" + regional = true + region = var.region + network = var.network + subnetwork = var.subnetwork + ip_range_pods = "k8s-pod-range" + ip_range_services = "k8s-service-range" + create_service_account = true + enable_private_endpoint = false + enable_private_nodes = true + master_ipv4_cidr_block = "172.16.0.0/28" + enable_cost_allocation = true + deletion_protection = false + + cluster_resource_labels = { + name = "${var.cluster_prefix}-cluster" + component = "${var.cluster_prefix}-operator" + } +} +# [END gke_aiml_sqlgen_autopilot_private_regional_cluster] \ No newline at end of file diff --git a/ai-ml/nl-to-sql/terraform/modules/cluster-autopilot/variables.tf b/ai-ml/nl-to-sql/terraform/modules/cluster-autopilot/variables.tf new file mode 100644 index 0000000000..ac6a50dae5 --- /dev/null +++ b/ai-ml/nl-to-sql/terraform/modules/cluster-autopilot/variables.tf @@ -0,0 +1,34 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +variable "project_id" { + description = "The project ID to host the cluster in" +} + +variable "region" { + description = "The region to host the cluster in" +} + +variable "network" { + description = "The VPC network to host the cluster in" +} + +variable "subnetwork" { + description = "The subnetwork to host the cluster in" +} + +variable "cluster_prefix" { + description = "The prefix for all cluster resources" +} + diff --git a/ai-ml/nl-to-sql/terraform/modules/cluster-autopilot/versions.tf b/ai-ml/nl-to-sql/terraform/modules/cluster-autopilot/versions.tf new file mode 100644 index 0000000000..f8bded9171 --- /dev/null +++ b/ai-ml/nl-to-sql/terraform/modules/cluster-autopilot/versions.tf @@ -0,0 +1,23 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +terraform { + required_providers { + google = { + source = "hashicorp/google" + version = "~> 5.0" + } + } + required_version = ">= 1.3" +} diff --git a/ai-ml/nl-to-sql/terraform/modules/cluster/main.tf b/ai-ml/nl-to-sql/terraform/modules/cluster/main.tf new file mode 100644 index 0000000000..19f8ab11f0 --- /dev/null +++ b/ai-ml/nl-to-sql/terraform/modules/cluster/main.tf @@ -0,0 +1,54 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START gke_standard_private_regional_cluster] +module "sqlgen_cluster" { + source = "terraform-google-modules/kubernetes-engine/google//modules/private-cluster" + version = "~> 29.0" + project_id = var.project_id + name = "${var.cluster_prefix}-cluster" + regional = true + region = var.region + network = var.network + subnetwork = var.subnetwork + ip_range_pods = "k8s-pod-range" + ip_range_services = "k8s-service-range" + create_service_account = true + enable_private_endpoint = false + enable_private_nodes = true + master_ipv4_cidr_block = "172.16.0.0/28" + network_policy = true + logging_enabled_components = ["SYSTEM_COMPONENTS","WORKLOADS"] + monitoring_enabled_components = ["SYSTEM_COMPONENTS"] + enable_cost_allocation = true + deletion_protection = false + initial_node_count = 1 + kubernetes_version = "1.28" + + + cluster_resource_labels = { + name = "${var.cluster_prefix}-cluster" + component = "${var.cluster_prefix}-operator" + } + + monitoring_enable_managed_prometheus = true + gke_backup_agent_config = true + + node_pools = var.node_pools + node_pools_labels = var.node_pools_labels + node_pools_taints = var.node_pools_taints + gce_pd_csi_driver = true +} +# [END gke_standard_private_regional_cluster] + diff --git a/ai-ml/nl-to-sql/terraform/modules/cluster/variables.tf b/ai-ml/nl-to-sql/terraform/modules/cluster/variables.tf new file mode 100644 index 0000000000..f619fdb7eb --- /dev/null +++ b/ai-ml/nl-to-sql/terraform/modules/cluster/variables.tf @@ -0,0 +1,49 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +variable "project_id" { + description = "The project ID to host the cluster in" +} + +variable "region" { + description = "The region to host the cluster in" +} + +variable "network" { + description = "The VPC network to host the cluster in" +} + +variable "subnetwork" { + description = "The subnetwork to host the cluster in" +} + +variable "cluster_prefix" { + description = "The prefix for all cluster resources" +} + +variable "node_pools" { + type = list(map(any)) + description = "List of maps containing node pools" +} + +variable "node_pools_labels" { + type = map(map(string)) + description = "Map of maps containing node labels by node-pool name" +} + +variable "node_pools_taints" { + type = map(list(object({ key = string, value = string, effect = string }))) + description = "Map of lists containing node taints by node-pool name" +} + diff --git a/ai-ml/nl-to-sql/terraform/modules/cluster/versions.tf b/ai-ml/nl-to-sql/terraform/modules/cluster/versions.tf new file mode 100644 index 0000000000..0acd8476f8 --- /dev/null +++ b/ai-ml/nl-to-sql/terraform/modules/cluster/versions.tf @@ -0,0 +1,31 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +terraform { + required_providers { + google = { + source = "hashicorp/google" + version = ">= 5.9.0, < 6" + } + kubernetes = { + source = "hashicorp/kubernetes" + version = "~> 2.10" + } + random = { + source = "hashicorp/random" + version = ">= 2.1" + } + } + required_version = ">= 1.3" +} diff --git a/ai-ml/nl-to-sql/terraform/modules/network/main.tf b/ai-ml/nl-to-sql/terraform/modules/network/main.tf new file mode 100644 index 0000000000..1d83f5d715 --- /dev/null +++ b/ai-ml/nl-to-sql/terraform/modules/network/main.tf @@ -0,0 +1,68 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START gke_vpc_multi_region_network] +module "gcp-network" { + source = "terraform-google-modules/network/google" + version = "~> 8.1.0" + + project_id = var.project_id + network_name = "${var.cluster_prefix}-vpc" + + subnets = [ + { + subnet_name = "${var.cluster_prefix}-private-subnet" + subnet_ip = "10.10.0.0/24" + subnet_region = var.region + subnet_private_access = true + subnet_flow_logs = "true" + } + ] + + secondary_ranges = { + ("${var.cluster_prefix}-private-subnet") = [ + { + range_name = "k8s-pod-range" + ip_cidr_range = "10.48.0.0/20" + }, + { + range_name = "k8s-service-range" + ip_cidr_range = "10.52.0.0/20" + }, + ] + } +} + +output "network_name" { + value = module.gcp-network.network_name +} + +output "subnet_name" { + value = module.gcp-network.subnets_names[0] +} +# [END gke_databases_elasticsearch_vpc_multi_region_network] + +# [START gke_databases_elasticsearch_cloudnat_simple_create] +module "cloud_router" { + source = "terraform-google-modules/cloud-router/google" + version = "~> 6.0" + project = var.project_id + name = "${var.cluster_prefix}-nat-router" + network = module.gcp-network.network_name + region = var.region + nats = [{ + name = "${var.cluster_prefix}-nat" + }] +} +# [END gke_vpc_multi_region_network] \ No newline at end of file diff --git a/ai-ml/nl-to-sql/terraform/modules/network/variables.tf b/ai-ml/nl-to-sql/terraform/modules/network/variables.tf new file mode 100644 index 0000000000..9126a4c71f --- /dev/null +++ b/ai-ml/nl-to-sql/terraform/modules/network/variables.tf @@ -0,0 +1,26 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +variable "project_id" { + description = "The project ID to host the cluster in" +} + +variable "region" { + description = "The region to host the cluster in" +} + +variable "cluster_prefix" { + description = "The prefix for all cluster resources" +} + diff --git a/ai-ml/nl-to-sql/terraform/modules/network/versions.tf b/ai-ml/nl-to-sql/terraform/modules/network/versions.tf new file mode 100644 index 0000000000..f8bded9171 --- /dev/null +++ b/ai-ml/nl-to-sql/terraform/modules/network/versions.tf @@ -0,0 +1,23 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +terraform { + required_providers { + google = { + source = "hashicorp/google" + version = "~> 5.0" + } + } + required_version = ">= 1.3" +} From 9ba74293667f0b1dba388f662700f71ae3ebbf24 Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Tue, 28 May 2024 16:14:58 +0200 Subject: [PATCH 16/28] remove debug lines from notebook --- ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb b/ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb index e5b2d0adb2..a2188aa263 100644 --- a/ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb +++ b/ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb @@ -280,19 +280,11 @@ "\n", "def llm_query(query):\n", " sql_prompt_value=sql_prompt_template.format(db_schema=db_schema_formatted, query=query)\n", - " #print(sql_prompt_value)\n", - " #print(\"-----\")\n", " sql_query=llm.invoke(sql_prompt_value)\n", - " #print(sql_query)\n", - " #print(\"-----\")\n", " postgres_reply=postgres_query(sql_query)\n", " if postgres_reply == False:\n", " return \"Try another query\"\n", - " #print(postgres_reply)\n", - " #print(\"-----\")\n", " final_prompt_value=final_prompt_template.format(db_schema=db_schema_formatted, query=query, postgres_reply=postgres_reply)\n", - " #print(final_prompt_value)\n", - " #print(\"----\")\n", " return llm.invoke(final_prompt_value)" ], "metadata": { From 0cdaf9b3d86ffb248d6d34c43efbdac7388cb596 Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Wed, 29 May 2024 15:11:02 +0200 Subject: [PATCH 17/28] fix ci checks --- ai-ml/nl-to-sql/manifests/02-dataset/dataset.sh | 14 ++++++++++++++ ai-ml/nl-to-sql/terraform/modules/network/main.tf | 8 ++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ai-ml/nl-to-sql/manifests/02-dataset/dataset.sh b/ai-ml/nl-to-sql/manifests/02-dataset/dataset.sh index 2bcac97ef6..0e45259b8e 100755 --- a/ai-ml/nl-to-sql/manifests/02-dataset/dataset.sh +++ b/ai-ml/nl-to-sql/manifests/02-dataset/dataset.sh @@ -1,3 +1,17 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + #!/bin/bash PGPASSWORD=$OWNERPASSWORD psql -U $OWNERUSERNAME -d $DATABASE_NAME -h $POSTGRES_URL -c \ diff --git a/ai-ml/nl-to-sql/terraform/modules/network/main.tf b/ai-ml/nl-to-sql/terraform/modules/network/main.tf index 1d83f5d715..e39db1b3d7 100644 --- a/ai-ml/nl-to-sql/terraform/modules/network/main.tf +++ b/ai-ml/nl-to-sql/terraform/modules/network/main.tf @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# [START gke_vpc_multi_region_network] +# [START gke_sqlgen_vpc_multi_region_network] module "gcp-network" { source = "terraform-google-modules/network/google" version = "~> 8.1.0" @@ -51,9 +51,9 @@ output "network_name" { output "subnet_name" { value = module.gcp-network.subnets_names[0] } -# [END gke_databases_elasticsearch_vpc_multi_region_network] +# [END gke_sqlgen_vpc_multi_region_network] -# [START gke_databases_elasticsearch_cloudnat_simple_create] +# [START gke_sqlgen_cloudnat_simple_create] module "cloud_router" { source = "terraform-google-modules/cloud-router/google" version = "~> 6.0" @@ -65,4 +65,4 @@ module "cloud_router" { name = "${var.cluster_prefix}-nat" }] } -# [END gke_vpc_multi_region_network] \ No newline at end of file +# [END gke_sqlgen_cloudnat_simple_create] From be60bc4cf9db770b7d2bf2bdd90561038e168780 Mon Sep 17 00:00:00 2001 From: BRV158 Date: Mon, 3 Jun 2024 09:56:59 +0300 Subject: [PATCH 18/28] terraform edits --- ai-ml/nl-to-sql/terraform/gke-standard/main.tf | 10 ---------- ai-ml/nl-to-sql/terraform/gke-standard/variables.tf | 2 +- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/ai-ml/nl-to-sql/terraform/gke-standard/main.tf b/ai-ml/nl-to-sql/terraform/gke-standard/main.tf index df435c91af..b94e799ae7 100644 --- a/ai-ml/nl-to-sql/terraform/gke-standard/main.tf +++ b/ai-ml/nl-to-sql/terraform/gke-standard/main.tf @@ -63,16 +63,6 @@ module "sqlgen_cluster" { "app.stateful/component" = "postgres" } } - node_pools_taints = { - all = [] - postgres-pool = [ - { - key = "app.stateful/component" - value = "postgres" - effect = "NO_SCHEDULE" - } - ] - } } output "kubectl_connection_command" { diff --git a/ai-ml/nl-to-sql/terraform/gke-standard/variables.tf b/ai-ml/nl-to-sql/terraform/gke-standard/variables.tf index 012acb75d5..1f887a7ca7 100644 --- a/ai-ml/nl-to-sql/terraform/gke-standard/variables.tf +++ b/ai-ml/nl-to-sql/terraform/gke-standard/variables.tf @@ -26,7 +26,7 @@ variable "region" { variable "node_location" { description = "Node location for GPU node pool - please check GPUs node availability in official documentation: https://cloud.google.com/compute/docs/regions-zones" type = string - default = "us-central1-a,us-central1-b" + default = "" } variable "cluster_prefix" { From 3bf9a56e44518edc40b8918cc3f568aa61bb3ebd Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Mon, 3 Jun 2024 10:45:23 +0200 Subject: [PATCH 19/28] update postgres yaml --- ai-ml/nl-to-sql/manifests/01-postgres-cluster/my-cluster.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ai-ml/nl-to-sql/manifests/01-postgres-cluster/my-cluster.yaml b/ai-ml/nl-to-sql/manifests/01-postgres-cluster/my-cluster.yaml index b26e6b7165..ee49fec9ce 100644 --- a/ai-ml/nl-to-sql/manifests/01-postgres-cluster/my-cluster.yaml +++ b/ai-ml/nl-to-sql/manifests/01-postgres-cluster/my-cluster.yaml @@ -44,7 +44,7 @@ spec: tolerations: - key: "app.stateful/component" operator: "Equal" - value: "postgres-operator" + value: "postgres" effect: NoSchedule nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: @@ -53,7 +53,7 @@ spec: - key: "app.stateful/component" operator: In values: - - "postgres-operator" + - "postgres" resources: requests: cpu: "1" From f4b0bbb34bb516e6486225798cdba4ed56727675 Mon Sep 17 00:00:00 2001 From: BRV158 Date: Mon, 3 Jun 2024 14:54:32 +0300 Subject: [PATCH 20/28] GPU pool fix --- ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml | 9 ++++- .../nl-to-sql/terraform/gke-standard/main.tf | 38 +++++++++++++------ .../terraform/gke-standard/variables.tf | 2 +- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml b/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml index 7b75f8c353..895620f9ee 100644 --- a/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml +++ b/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml @@ -37,12 +37,12 @@ spec: requests: cpu: "2" memory: "7Gi" - ephemeral-storage: "20Gi" + ephemeral-storage: "100Gi" nvidia.com/gpu: 1 limits: cpu: "2" memory: "7Gi" - ephemeral-storage: "20Gi" + ephemeral-storage: "100Gi" nvidia.com/gpu: 1 args: - --model-id=$(MODEL_ID) @@ -65,6 +65,11 @@ spec: - name: dshm emptyDir: medium: Memory + tolerations: + - key: "nvidia.com/gpu" + operator: "Equal" + value: "present" + effect: NoSchedule nodeSelector: cloud.google.com/gke-accelerator: nvidia-l4 --- diff --git a/ai-ml/nl-to-sql/terraform/gke-standard/main.tf b/ai-ml/nl-to-sql/terraform/gke-standard/main.tf index b94e799ae7..354fdc26de 100644 --- a/ai-ml/nl-to-sql/terraform/gke-standard/main.tf +++ b/ai-ml/nl-to-sql/terraform/gke-standard/main.tf @@ -44,17 +44,22 @@ module "sqlgen_cluster" { auto_repair = true }, { - name = "gpu-pool" - disk_size_gb = var.node_disk_size - disk_type = "pd-balanced" - node_locations = var.node_location - autoscaling = true - min_count = 0 - max_count = var.autoscaling_max_count - max_surge = 1 - max_unavailable = 0 - machine_type = "g2-standard-4" - auto_repair = true + name = "gpu-pool" + disk_size_gb = var.node_disk_size + disk_type = "pd-balanced" + node_locations = var.node_location + autoscaling = true + min_count = 0 + max_count = var.autoscaling_max_count + max_surge = 1 + max_unavailable = 0 + machine_type = "g2-standard-4" + auto_repair = true + accelerator_count = 1 + accelerator_type = "nvidia-l4" + gpu_driver_version = "LATEST" + + } ] node_pools_labels = { @@ -63,6 +68,17 @@ module "sqlgen_cluster" { "app.stateful/component" = "postgres" } } + + node_pools_taints = { + all = [] + postgres-pool = [ + { + key = "app.stateful/component" + value = "postgres" + effect = "NO_SCHEDULE" + } + ] + } } output "kubectl_connection_command" { diff --git a/ai-ml/nl-to-sql/terraform/gke-standard/variables.tf b/ai-ml/nl-to-sql/terraform/gke-standard/variables.tf index 1f887a7ca7..5e98b5758e 100644 --- a/ai-ml/nl-to-sql/terraform/gke-standard/variables.tf +++ b/ai-ml/nl-to-sql/terraform/gke-standard/variables.tf @@ -49,7 +49,7 @@ variable "node_disk_type" { variable "node_disk_size" { description = "The persistent disk size for node instances" - default = 20 + default = 100 type = number } From fc62d440186aa613b0cfc0b56c1db3ae0fa2deaa Mon Sep 17 00:00:00 2001 From: BRV158 Date: Mon, 3 Jun 2024 15:10:03 +0300 Subject: [PATCH 21/28] ephemeral storage limits edited --- ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml b/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml index 895620f9ee..af02c19c70 100644 --- a/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml +++ b/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml @@ -37,12 +37,12 @@ spec: requests: cpu: "2" memory: "7Gi" - ephemeral-storage: "100Gi" + ephemeral-storage: "40Gi" nvidia.com/gpu: 1 limits: cpu: "2" memory: "7Gi" - ephemeral-storage: "100Gi" + ephemeral-storage: "40Gi" nvidia.com/gpu: 1 args: - --model-id=$(MODEL_ID) From 288f570ac47930560820e50100361f749c95485d Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Mon, 3 Jun 2024 16:23:00 +0200 Subject: [PATCH 22/28] update tgi deployment strategy --- ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml b/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml index af02c19c70..4a38c4403f 100644 --- a/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml +++ b/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml @@ -19,6 +19,8 @@ metadata: name: tgi spec: replicas: 1 + strategy: + type: Recreate selector: matchLabels: app: tgi-runtime From 892576e5f4ab6b060145e220312c1d21a7a97cbe Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Thu, 13 Jun 2024 03:03:17 +0200 Subject: [PATCH 23/28] add terraforkm ci --- .github/workflows/ai-ml-nl-to-sql-ci.yaml | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/ai-ml-nl-to-sql-ci.yaml diff --git a/.github/workflows/ai-ml-nl-to-sql-ci.yaml b/.github/workflows/ai-ml-nl-to-sql-ci.yaml new file mode 100644 index 0000000000..d1afd1d3ac --- /dev/null +++ b/.github/workflows/ai-ml-nl-to-sql-ci.yaml @@ -0,0 +1,28 @@ +name: ai-ml-nl-to-sql-ci +on: + push: + branches: + - main + paths: + - '.github/workflows/ai-ml-nl-to-sql-ci.yml' + - 'ai-ml/nl-to-sql/**' + pull_request: + paths: + - '.github/workflows/ai-ml-nl-to-sql-ci.yml' + - 'ai-ml/nl-to-sql/**' +jobs: + job: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - name: Validate terraform autopilot + run: | + cd ai-ml/nl-to-sql/terraform/gke-autopilot + terraform init + terraform validate + - name: Validate terraform standard + run: | + cd ai-ml/nl-to-sql/terraform/gke-standard + terraform init + terraform validate + From 9bb94e215d0b22ba33a4652ab175565f75e3825e Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Fri, 19 Jul 2024 18:05:27 +0200 Subject: [PATCH 24/28] updates --- ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml | 26 ++++++++++++------- .../nl-to-sql/terraform/gke-standard/main.tf | 4 +-- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml b/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml index 4a38c4403f..f25d9d5bb2 100644 --- a/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml +++ b/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml @@ -39,34 +39,42 @@ spec: requests: cpu: "2" memory: "7Gi" - ephemeral-storage: "40Gi" + ephemeral-storage: "5Gi" nvidia.com/gpu: 1 limits: cpu: "2" memory: "7Gi" - ephemeral-storage: "40Gi" + ephemeral-storage: "5Gi" nvidia.com/gpu: 1 args: - --model-id=$(MODEL_ID) - --num-shard=1 env: - name: MODEL_ID - #value: google/gemma-2b-it - value: dganochenko/llama-3-8b-chat + value: /models/llama3/llama3-8b-chat-hf + - name: HUGGINGFACE_OFFLINE + value: "1" - name: PORT value: "8000" - - name: HUGGING_FACE_HUB_TOKEN - valueFrom: - secretKeyRef: - name: hf-secret - key: hf_api_token +# - name: HUGGING_FACE_HUB_TOKEN +# valueFrom: +# secretKeyRef: +# name: hf-secret +# key: hf_api_token volumeMounts: - mountPath: /dev/shm name: dshm + - name: gcs-fuse-csi-ephemeral + mountPath: /models volumes: - name: dshm emptyDir: medium: Memory + - name: gcs-fuse-csi-ephemeral + csi: + driver: gcsfuse.csi.storage.gke.io + volumeAttributes: + bucketName: vertex-model-garden-public-us tolerations: - key: "nvidia.com/gpu" operator: "Equal" diff --git a/ai-ml/nl-to-sql/terraform/gke-standard/main.tf b/ai-ml/nl-to-sql/terraform/gke-standard/main.tf index 354fdc26de..d17f641522 100644 --- a/ai-ml/nl-to-sql/terraform/gke-standard/main.tf +++ b/ai-ml/nl-to-sql/terraform/gke-standard/main.tf @@ -49,7 +49,7 @@ module "sqlgen_cluster" { disk_type = "pd-balanced" node_locations = var.node_location autoscaling = true - min_count = 0 + min_count = 1 max_count = var.autoscaling_max_count max_surge = 1 max_unavailable = 0 @@ -85,4 +85,4 @@ output "kubectl_connection_command" { value = "gcloud container clusters get-credentials ${var.cluster_prefix}-cluster --region ${var.region}" description = "Connection command" } -# [END gke_aiml_sqlgen_private_regional_cluster] \ No newline at end of file +# [END gke_aiml_sqlgen_private_regional_cluster] From a4354337444a297f25645d7ee08750a76b6bea0c Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Tue, 23 Jul 2024 12:01:00 +0200 Subject: [PATCH 25/28] updates --- ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml | 2 ++ ai-ml/nl-to-sql/terraform/modules/cluster/main.tf | 1 + 2 files changed, 3 insertions(+) diff --git a/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml b/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml index f25d9d5bb2..daacca5c8e 100644 --- a/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml +++ b/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml @@ -26,6 +26,8 @@ spec: app: tgi-runtime template: metadata: + annotations: + gke-gcsfuse/volumes: "true" labels: app: tgi-runtime ai.gke.io/model: llama-3-8b diff --git a/ai-ml/nl-to-sql/terraform/modules/cluster/main.tf b/ai-ml/nl-to-sql/terraform/modules/cluster/main.tf index 19f8ab11f0..686ba90a3b 100644 --- a/ai-ml/nl-to-sql/terraform/modules/cluster/main.tf +++ b/ai-ml/nl-to-sql/terraform/modules/cluster/main.tf @@ -35,6 +35,7 @@ module "sqlgen_cluster" { deletion_protection = false initial_node_count = 1 kubernetes_version = "1.28" + gcs_fuse_csi_driver = true cluster_resource_labels = { From 7c0bad3ca5821dd83f32a51eafa43dfd2a92de97 Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Wed, 24 Jul 2024 11:08:27 +0200 Subject: [PATCH 26/28] finish the update --- .../01-postgres-cluster/my-cluster.yaml | 17 +++++ ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml | 12 +++- .../manifests/04-notebook/notebook.ipynb | 65 ++++--------------- 3 files changed, 39 insertions(+), 55 deletions(-) diff --git a/ai-ml/nl-to-sql/manifests/01-postgres-cluster/my-cluster.yaml b/ai-ml/nl-to-sql/manifests/01-postgres-cluster/my-cluster.yaml index ee49fec9ce..bf7b848f55 100644 --- a/ai-ml/nl-to-sql/manifests/01-postgres-cluster/my-cluster.yaml +++ b/ai-ml/nl-to-sql/manifests/01-postgres-cluster/my-cluster.yaml @@ -13,6 +13,7 @@ # limitations under the License. # [START gke_ai_ml_nl_to_sql_manifests_01_postgres_cluster] +--- apiVersion: "acid.zalan.do/v1" kind: postgresql metadata: @@ -84,4 +85,20 @@ spec: value: "$(POSTGRES_USER)" - name: "DATA_SOURCE_PASS" value: "$(POSTGRES_PASSWORD)" +--- +apiVersion: v1 +kind: Service +metadata: + name: postgres-ilb + annotations: + networking.gke.io/load-balancer-type: "Internal" +spec: + selector: + spilo-role: master + type: LoadBalancer + ports: + - name: postgresql + port: 5432 + protocol: TCP + targetPort: 5432 # [END gke_ai_ml_nl_to_sql_manifests_01_postgres_cluster] diff --git a/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml b/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml index daacca5c8e..b18bd17475 100644 --- a/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml +++ b/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml @@ -36,7 +36,7 @@ spec: spec: containers: - name: inference-server - image: ghcr.io/huggingface/text-generation-inference:2.0.2 + image: ghcr.io/huggingface/text-generation-inference:2.1.1 resources: requests: cpu: "2" @@ -54,6 +54,7 @@ spec: env: - name: MODEL_ID value: /models/llama3/llama3-8b-chat-hf + #value: dganochenko/llama-3-8b-chat - name: HUGGINGFACE_OFFLINE value: "1" - name: PORT @@ -77,6 +78,9 @@ spec: driver: gcsfuse.csi.storage.gke.io volumeAttributes: bucketName: vertex-model-garden-public-us + mountOptions: "implicit-dirs" + fileCacheCapacity: 5Gi + fileCacheForRangeRead: "true" tolerations: - key: "nvidia.com/gpu" operator: "Equal" @@ -88,11 +92,13 @@ spec: apiVersion: v1 kind: Service metadata: - name: llm-service + name: llm-ilb + annotations: + networking.gke.io/load-balancer-type: "Internal" spec: selector: app: tgi-runtime - type: ClusterIP + type: LoadBalancer ports: - protocol: TCP port: 8000 diff --git a/ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb b/ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb index a2188aa263..a51e44430f 100644 --- a/ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb +++ b/ai-ml/nl-to-sql/manifests/04-notebook/notebook.ipynb @@ -70,8 +70,8 @@ "source": [ "%%bash\n", "\n", - "echo POSTGRES_ENDPOINT=$(kubectl get pod -l spilo-role=master -n postgres -o=jsonpath=\"{.items[0].status.podIP}\") > .env\n", - "echo LLM_ENDPOINT=http://$(kubectl get pod -l app=tgi-runtime -n llm -o=jsonpath=\"{.items[0].status.podIP}\"):8000 >> .env\n", + "echo POSTGRES_ENDPOINT=$(kubectl get svc postgres-ilb -n postgres --output jsonpath=\"{.status.loadBalancer.ingress[0].ip}\") > .env\n", + "echo LLM_ENDPOINT=http://$(kubectl get svc llm-ilb -n llm --output jsonpath=\"{.status.loadBalancer.ingress[0].ip}\"):8000 >> .env\n", "echo DATABASE_NAME=mydatabase >> .env\n", "echo DBUSERNAME=$(kubectl get secret mydatabaseowner.my-cluster.credentials.postgresql.acid.zalan.do -n postgres --template={{.data.username}} | base64 -d) >> .env\n", "echo DBPASSWORD=$(kubectl get secret mydatabaseowner.my-cluster.credentials.postgresql.acid.zalan.do -n postgres --template={{.data.password}} | base64 -d) >> .env" @@ -126,20 +126,10 @@ "from langchain_core.prompts import PromptTemplate" ], "metadata": { - "id": "oqq4NDgvt-XT", - "executionInfo": { - "status": "ok", - "timestamp": 1716475532717, - "user_tz": -120, - "elapsed": 342, - "user": { - "displayName": "", - "userId": "" - } - } + "id": "oqq4NDgvt-XT" }, "id": "oqq4NDgvt-XT", - "execution_count": 70, + "execution_count": null, "outputs": [] }, { @@ -169,20 +159,10 @@ "db_schema_formatted=tabulate(db_schema.fetchall(), headers=colnames, tablefmt='psql')\n" ], "metadata": { - "id": "7M-IQwbM6AgY", - "executionInfo": { - "status": "ok", - "timestamp": 1716475539251, - "user_tz": -120, - "elapsed": 332, - "user": { - "displayName": "", - "userId": "" - } - } + "id": "7M-IQwbM6AgY" }, "id": "7M-IQwbM6AgY", - "execution_count": 71, + "execution_count": null, "outputs": [] }, { @@ -234,20 +214,10 @@ "\"\"\")" ], "metadata": { - "id": "RKLr5riV6uZW", - "executionInfo": { - "status": "ok", - "timestamp": 1716475853538, - "user_tz": -120, - "elapsed": 399, - "user": { - "displayName": "", - "userId": "" - } - } + "id": "RKLr5riV6uZW" }, "id": "RKLr5riV6uZW", - "execution_count": 74, + "execution_count": null, "outputs": [] }, { @@ -288,20 +258,10 @@ " return llm.invoke(final_prompt_value)" ], "metadata": { - "id": "a_6XVEtH7dFv", - "executionInfo": { - "status": "ok", - "timestamp": 1716476680742, - "user_tz": -120, - "elapsed": 375, - "user": { - "displayName": "", - "userId": "" - } - } + "id": "a_6XVEtH7dFv" }, "id": "a_6XVEtH7dFv", - "execution_count": 81, + "execution_count": null, "outputs": [] }, { @@ -351,9 +311,10 @@ "version": "3.10.10" }, "colab": { - "provenance": [] + "provenance": [], + "name": "notebook.ipynb" } }, "nbformat": 4, "nbformat_minor": 5 -} +} \ No newline at end of file From fa24d4be7ff7ee5b7528ac2db1914fe512b92414 Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Wed, 24 Jul 2024 11:09:07 +0200 Subject: [PATCH 27/28] cleanup --- ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml b/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml index b18bd17475..3d2fb5f556 100644 --- a/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml +++ b/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml @@ -54,16 +54,10 @@ spec: env: - name: MODEL_ID value: /models/llama3/llama3-8b-chat-hf - #value: dganochenko/llama-3-8b-chat - name: HUGGINGFACE_OFFLINE value: "1" - name: PORT value: "8000" -# - name: HUGGING_FACE_HUB_TOKEN -# valueFrom: -# secretKeyRef: -# name: hf-secret -# key: hf_api_token volumeMounts: - mountPath: /dev/shm name: dshm From 9ea9679da5c000ef3e2276f341c37d1387135d16 Mon Sep 17 00:00:00 2001 From: Dmitrii Ganochenko Date: Thu, 25 Jul 2024 12:20:23 +0200 Subject: [PATCH 28/28] small update --- ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml b/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml index 3d2fb5f556..ed4e384885 100644 --- a/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml +++ b/ai-ml/nl-to-sql/manifests/03-llm/tgi.yaml @@ -13,6 +13,7 @@ # limitations under the License. # [START gke_ai_ml_nl_to_sql_manifests_03_llm] +--- apiVersion: apps/v1 kind: Deployment metadata: