Skip to content

Commit

Permalink
Merge pull request #213 from defog-ai/abdullah/extend-instructions-tr…
Browse files Browse the repository at this point in the history
…anslation-for-mysql

Extended instructions translation functionality for mysql and validated mysql files
  • Loading branch information
Muhammad18557 committed Aug 21, 2024
2 parents a575d45 + 39e250d commit 236e8b4
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 41 deletions.
31 changes: 29 additions & 2 deletions correct_sql_instructions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -478,33 +478,50 @@
"source": [
"# Feel free to modify this cell for future dialects\n",
"\n",
"from utils.dialects import instructions_to_sqlite, instructions_to_tsql\n",
"from utils.dialects import instructions_to_sqlite, instructions_to_tsql, instructions_to_mysql\n",
"\n",
"if \"instructions\" in df.columns:\n",
" if dialect == \"sqlite\":\n",
" df['instructions'] = df['instructions'].fillna(\"\")\n",
" df[\"instructions\"] = df.progress_apply(\n",
" lambda x: instructions_to_sqlite(x[\"instructions\"]), axis=1\n",
" )\n",
" elif dialect == \"tsql\":\n",
" df['instructions'] = df['instructions'].fillna(\"\")\n",
" df[\"instructions\"] = df.progress_apply(\n",
" lambda x: instructions_to_tsql(x[\"instructions\"]), axis=1\n",
" )\n",
" elif dialect == \"mysql\":\n",
" print(df['instructions'].nunique())\n",
" df['instructions'] = df['instructions'].fillna(\"\")\n",
" df[\"instructions\"] = df.progress_apply(\n",
" lambda x: instructions_to_mysql(x[\"instructions\"]), axis=1\n",
" )\n",
" else:\n",
" raise ValueError(f\"Dialect not yet supported for instructions translation. Please add an instructions_to_{dialect} function in utils/dialects.py\")\n",
"else:\n",
" print(\"No instructions column in the dataframe\")\n",
" \n",
"if \"full_instructions\" in df.columns:\n",
" if dialect == \"sqlite\":\n",
" df['full_instructions'] = df['full_instructions'].fillna(\"\")\n",
" df[\"full_instructions\"] = df.progress_apply(\n",
" lambda x: instructions_to_sqlite(x[\"full_instructions\"]), axis=1\n",
" )\n",
" elif dialect == \"tsql\":\n",
" df['full_instructions'] = df['full_instructions'].fillna(\"\")\n",
" df[\"full_instructions\"] = df.progress_apply(\n",
" lambda x: instructions_to_tsql(x[\"full_instructions\"]), axis=1\n",
" )\n",
" elif dialect == \"mysql\":\n",
" df['full_instructions'] = df['full_instructions'].fillna(\"\")\n",
" df[\"full_instructions\"] = df.progress_apply(\n",
" lambda x: instructions_to_mysql(x[\"full_instructions\"]), axis=1\n",
" )\n",
" else:\n",
" raise ValueError(f\"Dialect not yet supported for instructions translation. Please add an instructions_to_{dialect} function in utils/dialects.py\")\n",
"else:\n",
" print(\"No instructions column in the dataframe\")"
" print(\"No full_instructions column in the dataframe\")"
]
},
{
Expand Down Expand Up @@ -542,6 +559,16 @@
" for i in full_instructions:\n",
" print(i, \"\\n\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Update the csv file with the new translated instructions\n",
"df.to_csv(csv_file, index=False)"
]
}
],
"metadata": {
Expand Down
Loading

0 comments on commit 236e8b4

Please sign in to comment.