Skip to content

Commit 6007dbc

Browse files
committed
Refactor code generation examples: simplify Fibonacci and palindrome functions, and enhance flatten function implementation
1 parent c62f6f1 commit 6007dbc

1 file changed

Lines changed: 45 additions & 18 deletions

File tree

notebooks/01_evaluation_and_tuning.ipynb

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,47 +1087,71 @@
10871087
"name": "stdout",
10881088
"output_type": "stream",
10891089
"text": [
1090+
"⚠️ Für diesen Test nutzen wir absichtlich ein kleineres Modell: github_copilot/gpt-4o-mini\n",
1091+
"\n",
10901092
"📋 Task: Code Generation\n",
10911093
" Metrik: Echte Ausführung mit Testdaten!\n",
10921094
"\n",
10931095
"📝 Aufgabe: Write a function that returns the nth Fibonacci number using iteration.\n",
10941096
" Generierter Code:\n",
1095-
" │ def fibonacci(n: int) -> int:\n",
1096-
"\"\"\"\n",
1097-
"Return the nth Fibonacci number using iteration.\n",
1098-
"\n",
1099-
"The sequence is defined as:\n",
1100-
"F(0) = 0\n",
1101-
" F(1) = 1\n",
1102-
" F(n) = F(n-1) + F(n-2) for n >= 2\n",
1103-
" │ ... (47 Zeilen)\n",
1097+
" │ def fibonacci(n):\n",
1098+
"if n <= 0:\n",
1099+
" return 0\n",
1100+
" elif n == 1:\n",
1101+
" return 1\n",
1102+
"\n",
1103+
"a, b = 0, 1\n",
1104+
"for _ in range(2, n + 1):\n",
1105+
" │ ... (10 Zeilen)\n",
11041106
" ✅ fibonacci(0) → 0\n",
11051107
" ✅ fibonacci(1) → 1\n",
11061108
" ✅ fibonacci(10) → 55\n",
11071109
" ✅ fibonacci(20) → 6765\n",
11081110
"\n",
11091111
"📝 Aufgabe: Write a function that checks if a string is a palindrome, ignoring case and non-\n",
11101112
" Generierter Code:\n",
1111-
" │ def is_palindrome(s: str) -> bool:\n",
1112-
"\"\"\"\n",
1113-
" │ Check if the given string is a palindrome, ignoring case and non-alphanumeric characters.\n",
1113+
" │ import re\n",
11141114
"\n",
1115-
" │ Args:\n",
1116-
" │ s (str): The input string to check.\n",
1115+
" │ def is_palindrome(s: str) -> bool:\n",
1116+
" │ # Remove non-alphanumeric characters and convert to lower case\n",
1117+
" │ cleaned_string = re.sub(r'[^a-zA-Z0-9]', '', s).lower()\n",
1118+
" │ # Check if the cleaned string is the same as its reverse\n",
1119+
" │ return cleaned_string == cleaned_string[::-1]\n",
11171120
"\n",
1118-
" │ Returns:\n",
1119-
" │ ... (28 Zeilen)\n",
1121+
" │ ... (11 Zeilen)\n",
11201122
" ✅ is_palindrome('racecar') → True\n",
11211123
" ✅ is_palindrome('hello') → False\n",
11221124
" ✅ is_palindrome('A man a plan a canal Panama') → True\n",
11231125
"\n",
1124-
"📝 Aufgabe: Write a function that flattens a nested list of arbitrary depth into a single li\n"
1126+
"📝 Aufgabe: Write a function that flattens a nested list of arbitrary depth into a single li\n",
1127+
" Generierter Code:\n",
1128+
" │ def flatten(nested_list):\n",
1129+
" │ flat_list = []\n",
1130+
" │ for element in nested_list:\n",
1131+
" │ if isinstance(element, list):\n",
1132+
" │ flat_list.extend(flatten(element)) # Recursively flatten the sublist\n",
1133+
" │ else:\n",
1134+
" │ flat_list.append(element) # Add the non-list element to the flat list\n",
1135+
" │ return flat_list\n",
1136+
" │ ... (13 Zeilen)\n",
1137+
"[1, 2, 3, 4, 5, 6, 7, 8]\n",
1138+
" ✅ flatten([1, [2], 3]) → [1, 2, 3]\n",
1139+
" ✅ flatten([1, [2, [3, [4]]]]) → [1, 2, 3, 4]\n",
1140+
"\n",
1141+
"📝 Aufgabe: Write a function that counts the frequency of each word in a string and returns \n"
11251142
]
11261143
}
11271144
],
11281145
"source": [
11291146
"import re\n",
11301147
"\n",
1148+
"# Für Code-Generierung testen wir absichtlich ein KLEINERES Modell\n",
1149+
"# um zu zeigen dass nicht jedes Modell alles kann\n",
1150+
"SMALL_MODEL = \"github_copilot/gpt-4o-mini\"\n",
1151+
"configure_dspy(SMALL_MODEL)\n",
1152+
"print(f\"⚠️ Für diesen Test nutzen wir absichtlich ein kleineres Modell: {SMALL_MODEL}\")\n",
1153+
"print()\n",
1154+
"\n",
11311155
"task = get_task(\"code_generation\")\n",
11321156
"print(f\"📋 Task: {task.name}\")\n",
11331157
"print(f\" Metrik: Echte Ausführung mit Testdaten!\")\n",
@@ -1265,7 +1289,10 @@
12651289
"print(\" Ob er die RICHTIGEN ERGEBNISSE liefert — das zählt!\")\n",
12661290
"print()\n",
12671291
"print(\" Das ist wie bei Software-Tests:\")\n",
1268-
"print(\" Ein Programm das startet aber falsch rechnet ist wertlos.\")"
1292+
"print(\" Ein Programm das startet aber falsch rechnet ist wertlos.\")\n",
1293+
"\n",
1294+
"# Zurück zum Haupt-Modell für die nächsten Zellen\n",
1295+
"configure_dspy(MODEL)"
12691296
]
12701297
},
12711298
{

0 commit comments

Comments
 (0)