Skip to content

Commit

Permalink
Update natural language SQL example for workshop
Browse files Browse the repository at this point in the history
  • Loading branch information
sroecker committed Nov 28, 2023
1 parent a3b2f0e commit d7d93de
Showing 1 changed file with 107 additions and 14 deletions.
121 changes: 107 additions & 14 deletions notebooks/03_simple_naturalsql_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"outputs": [],
"source": [
"OLLAMA_HOST = 'localhost'\n",
"OLLAMA_HOST = 'ollama.darmstadt-workshop.svc.cluster.local'\n",
"OLLAMA_MODEL = 'mistral-openorca'"
]
},
Expand All @@ -39,18 +39,111 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"id": "88a51e7e-d469-4f8d-83f2-05f2850b5fb6",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5074d697f40d44d79ec70dbdf91d24bf",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"config.json: 0%| | 0.00/684 [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "51e2e70237e44b68b4db6ec5478a0ac4",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"model.safetensors: 0%| | 0.00/133M [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "eef183fadb9a40379871fa5b87df2272",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"tokenizer_config.json: 0%| | 0.00/366 [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f815774f32a747b0acdbf24eac5a12f7",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"vocab.txt: 0%| | 0.00/232k [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6f81c669914c45b9b31646f1227eb2ae",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"tokenizer.json: 0%| | 0.00/711k [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "50c67d734d364b9382e4e3142d35096b",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"special_tokens_map.json: 0%| | 0.00/125 [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"[nltk_data] Downloading package punkt to /tmp/llama_index...\n",
"[nltk_data] Unzipping tokenizers/punkt.zip.\n"
]
}
],
"source": [
"from llama_index import ServiceContext\n",
"service_context = ServiceContext.from_defaults(llm=llm, embed_model=\"local\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"id": "40a3d582-24fe-42c5-8854-37a889152fa8",
"metadata": {
"tags": []
Expand All @@ -60,7 +153,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
" As of October 2021, the average price for a liter of gasoline in Germany is around 1.80 EUR (including taxes). This price may vary depending on location and retailer. The prices have been rising due to global supply chain issues and increased demand. It is essential to keep an eye on the market trends and local rates while driving through Germany.\n"
" As of my last knowledge update in November 2021, gas prices in Germany have been significantly affected by the global energy crisis and rising inflation. The prices can vary depending on the region and provider, but on average, a kilowatt-hour (kWh) of electricity costs around €0.35 to €0.45. Please note that this information may not be up-to-date, so it's best to check the current prices directly from your local utility provider or an online price comparison tool."
]
}
],
Expand All @@ -72,7 +165,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"id": "125be39b-dcfa-475d-9f15-695045ca021b",
"metadata": {
"tags": []
Expand All @@ -96,7 +189,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"id": "21117b06-2fcf-4512-a91b-f5ccf1fa468a",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -540,7 +633,7 @@
"\n",
"Read NLStructStoreQueryEngine's docstring for more info on NL SQL.\n",
"\u001b[0;31mInit docstring:\u001b[0m Initialize params.\n",
"\u001b[0;31mFile:\u001b[0m ~/miniconda3/lib/python3.9/site-packages/llama_index/indices/struct_store/sql_query.py\n",
"\u001b[0;31mFile:\u001b[0m /opt/app-root/lib64/python3.9/site-packages/llama_index/indices/struct_store/sql_query.py\n",
"\u001b[0;31mType:\u001b[0m ABCMeta\n",
"\u001b[0;31mSubclasses:\u001b[0m "
]
Expand All @@ -560,7 +653,7 @@
"metadata": {},
"outputs": [],
"source": [
"# TODO set up text2SQL prompt\n",
"# TODO set up custom text2SQL prompt\n",
"sql_query_engine = NLSQLTableQueryEngine(\n",
" sql_database=sql_database,\n",
" tables=[\"tankerkoenig_prices\"],\n",
Expand All @@ -570,35 +663,35 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 18,
"id": "ebc0508b-54f9-49c3-a8e0-f154cce69cca",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" E10 gas was most expensive on November 21, 2023 at 1.849 per liter.\n"
" E10 gas was most expensive first on November 21, 2023 at 1:05 PM.\n"
]
}
],
"source": [
"response = sql_query_engine.query(\"At wich date was E10 gas most expensive?\")\n",
"response = sql_query_engine.query(\"At which time was E10 gas the most expensive first?\")\n",
"print(str(response))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "27cec63d-b0a9-42d7-806d-3be75960cae3",
"id": "54e337ac-0ff2-468a-b87f-f8971a312a95",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3.9",
"language": "python",
"name": "python3"
},
Expand Down

0 comments on commit d7d93de

Please sign in to comment.