diff --git a/notebooks/codeio/PreprocessCode.ipynb b/notebooks/codeio/PreprocessCode.ipynb index 8b583d79..6d13c298 100644 --- a/notebooks/codeio/PreprocessCode.ipynb +++ b/notebooks/codeio/PreprocessCode.ipynb @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -33,7 +33,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -91,13 +91,13 @@ "\n", "{0}\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", + "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. Respond only with the four components, no prefix or additional text.\n", "\"\"\"" ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -139,7 +139,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -147,10 +147,12 @@ "output_type": "stream", "text": [ "def main(word1, word2):\n", - " dp = [[0 for _ in range(len(word2) + 1)] for _ in range(len(word1) + 1)]\n", - " \n", - " for i in range(len(word1) + 1):\n", - " for j in range(len(word2) + 1):\n", + " m = len(word1)\n", + " n = len(word2)\n", + " dp = [[0 for _ in range(n + 1)] for _ in range(m + 1)]\n", + "\n", + " for i in range(m + 1):\n", + " for j in range(n + 1):\n", " if i == 0:\n", " dp[i][j] = j\n", " elif j == 0:\n", @@ -163,27 +165,26 @@ " replace = dp[i - 1][j - 1]\n", " dp[i][j] = 1 + min(insert, delete, replace)\n", " \n", - " return {\"minimum_edit_distance\": dp[len(word1)][len(word2)]}\n", + " return {\"min_edit_distance\": dp[m][n]}\n", "\n", "\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 compute 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 to achieve the transformation.\n", "\n", "\n", "Input:\n", - " word1 (str): The first string.\n", - " word2 (str): The second string.\n", + " word1 (str): The first string to be transformed.\n", + " word2 (str): The second string to be matched.\n", "\n", "Output:\n", " return (dict): A dictionary with one key:\n", - " - minimum_edit_distance (int): The minimum number of operations required to transform `word1` into `word2`.\n", + " - min_edit_distance (int): The minimum number of operations required to transform `word1` into `word2`.\n", "\n", "\n", "def input_generator():\n", " import random\n", " import string\n", - " \n", - " word1 = ''.join(random.choice(string.ascii_lowercase) for _ in range(random.randint(5, 10)))\n", - " word2 = ''.join(random.choice(string.ascii_lowercase) for _ in range(random.randint(5, 10)))\n", + " word1 = ''.join(random.choice(string.ascii_lowercase) for _ in range(random.randint(5, 15)))\n", + " word2 = ''.join(random.choice(string.ascii_lowercase) for _ in range(random.randint(5, 15)))\n", " return {\"word1\": word1, \"word2\": word2}\n" ] } @@ -202,6 +203,15 @@ "print(response.choices[0].message.content)" ] }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "code, query, parameters, generator = response.choices[0].message.content.split(\"\\n\\n\\n\")" + ] + }, { "cell_type": "code", "execution_count": null,