Prompt tweak for code preprocessing

This commit is contained in:
Oliver 2025-02-20 20:07:32 +00:00
parent 6f9b81b879
commit b7ee70995e

View file

@ -33,14 +33,13 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"prompt_template = \"\"\"\n", "prompt_template = \"\"\"\n",
"You are tasked with preprocessing a raw file of Python code into a standard format. The format is made up of several components. Here is a very simple example of a raw code file:\n", "You are tasked with preprocessing a raw file of Python code into a standard format. The format is made up of several components. Here is a very simple example of a raw code file:\n",
"\n", "\n",
"```python\n",
"def kg_to_pounds(weights):\n", "def kg_to_pounds(weights):\n",
" return [w * 2.20462 for w in weights]\n", " return [w * 2.20462 for w in weights]\n",
"\n", "\n",
@ -52,7 +51,6 @@
"\n", "\n",
" for measurement in filter_weekly(lbs, days):\n", " for measurement in filter_weekly(lbs, days):\n",
" print(measurement)\n", " print(measurement)\n",
"```\n",
"\n", "\n",
"1. Cleaned reference code, with a main entrypoint function that takes all required arguments as parameters and returns all outputs.\n", "1. Cleaned reference code, with a main entrypoint function that takes all required arguments as parameters and returns all outputs.\n",
"\n", "\n",
@ -70,7 +68,6 @@
"\n", "\n",
"Example description:\n", "Example description:\n",
"\n", "\n",
"```plaintext\n",
"Input:\n", "Input:\n",
" weights_kg (list of int): List of weight values in kilograms.\n", " weights_kg (list of int): List of weight values in kilograms.\n",
" days (list of int): List of integers representing the number of days passed, starting from zero.\n", " days (list of int): List of integers representing the number of days passed, starting from zero.\n",
@ -78,7 +75,6 @@
"Output:\n", "Output:\n",
" return (dict): A dictionary with one key:\n", " return (dict): A dictionary with one key:\n",
" - weights_lb (list of int): List of filtered weight values in pounds.\n", " - weights_lb (list of int): List of filtered weight values in pounds.\n",
"```\n",
"\n", "\n",
"4. Python 3.11 code for an input generator, which randomly generates valid sets of inputs for the functions.\n", "4. Python 3.11 code for an input generator, which randomly generates valid sets of inputs for the functions.\n",
"\n", "\n",
@ -86,24 +82,22 @@
"\n", "\n",
"Example input generator:\n", "Example input generator:\n",
"\n", "\n",
"```python\n",
"def input_generator():\n", "def input_generator():\n",
" weights = [np.random.uniform(0, 100) for _ in range(40)]\n", " weights = [np.random.uniform(0, 100) for _ in range(40)]\n",
" days = list(range(40))\n", " days = list(range(40))\n",
" return {{\"weights_kg\": weights, \"days\": days}}\n", " return {{\"weights_kg\": weights, \"days\": days}}\n",
"```\n",
"\n", "\n",
"Using the guidelines and example above, preprocess the following raw code file into the standard format:\n", "Using the guidelines and example above, preprocess the following raw code file into the standard format:\n",
"\n", "\n",
"{0}\n", "{0}\n",
"\n", "\n",
"Output the components (reference code, query, description, input generator) in order. Separate each component with a triple newline (\\n\\n\\n).\n", "Output the components (reference code, query, description, input generator) in order. Separate each component with a triple newline (\\n\\n\\n). Avoid code blocks and do not output any Markdown formatting.\n",
"\"\"\"" "\"\"\""
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -145,21 +139,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"### Reference Code\n", "def main(word1, word2):\n",
"```python\n", " dp = [[0 for _ in range(len(word2) + 1)] for _ in range(len(word1) + 1)]\n",
"def main(word1: str, word2: str) -> dict:\n", " \n",
" m, n = len(word1), len(word2)\n", " for i in range(len(word1) + 1):\n",
" dp = [[0] * (n + 1) for _ in range(m + 1)]\n", " for j in range(len(word2) + 1):\n",
"\n",
" for i in range(m + 1):\n",
" for j in range(n + 1):\n",
" if i == 0:\n", " if i == 0:\n",
" dp[i][j] = j\n", " dp[i][j] = j\n",
" elif j == 0:\n", " elif j == 0:\n",
@ -171,39 +162,29 @@
" delete = dp[i - 1][j]\n", " delete = dp[i - 1][j]\n",
" replace = dp[i - 1][j - 1]\n", " replace = dp[i - 1][j - 1]\n",
" dp[i][j] = 1 + min(insert, delete, replace)\n", " dp[i][j] = 1 + min(insert, delete, replace)\n",
" \n",
" return {\"minimum_edit_distance\": dp[len(word1)][len(word2)]}\n",
"\n", "\n",
" return {\"min_edit_distance\": dp[m][n]}\n",
"```\n",
"\n", "\n",
"### Query\n", "You are given two strings, `word1` and `word2`. Your task is to find the minimum number of operations required to transform `word1` into `word2`. The permitted operations are insertion, deletion, and substitution of a single character. Return the minimum number of operations as an integer.\n",
"You are given two strings, `word1` and `word2`. Your task is to calculate the minimum number of operations required to transform `word1` into `word2`. The permitted operations are insertion, deletion, and substitution of a single character. Return the minimum number of operations needed.\n", "\n",
"\n", "\n",
"### Description\n",
"```plaintext\n",
"Input:\n", "Input:\n",
" word1 (str): The first string.\n", " word1 (str): The first string.\n",
" word2 (str): The second string.\n", " word2 (str): The second string.\n",
"\n", "\n",
"Output:\n", "Output:\n",
" return (dict): A dictionary with one key:\n", " return (dict): A dictionary with one key:\n",
" - min_edit_distance (int): The minimum number of operations required to transform `word1` into `word2`.\n", " - minimum_edit_distance (int): The minimum number of operations required to transform `word1` into `word2`.\n",
"```\n",
"\n", "\n",
"### Input Generator\n",
"```python\n",
"import random\n",
"import string\n",
"\n", "\n",
"def input_generator():\n", "def input_generator():\n",
" def random_string(length):\n", " import random\n",
" letters = string.ascii_lowercase\n", " import string\n",
" return ''.join(random.choice(letters) for _ in range(length))\n",
"\n",
" word1 = random_string(random.randint(5, 15))\n",
" word2 = random_string(random.randint(5, 15))\n",
" \n", " \n",
" return {\"word1\": word1, \"word2\": word2}\n", " word1 = ''.join(random.choice(string.ascii_lowercase) for _ in range(random.randint(5, 10)))\n",
"```\n" " word2 = ''.join(random.choice(string.ascii_lowercase) for _ in range(random.randint(5, 10)))\n",
" return {\"word1\": word1, \"word2\": word2}\n"
] ]
} }
], ],