diff --git a/Src/Kernel/FormulaPy/formula.ipynb b/Src/Kernel/FormulaPy/formula.ipynb
index 32511b0..ef5a93f 100644
--- a/Src/Kernel/FormulaPy/formula.ipynb
+++ b/Src/Kernel/FormulaPy/formula.ipynb
@@ -29,7 +29,7 @@
"output_type": "stream",
"text": [
"(Compiled) InvalidBatteryChecker.4ml\r\n",
- "0.59s.\r\n",
+ "0.50s.\r\n",
"[]> \n"
]
}
@@ -51,7 +51,7 @@
"Parsing text took: 0\r\n",
"Visiting text took: 0\r\n",
"Started solve task with Id 0.\r\n",
- "0.32s.\r\n",
+ "0.29s.\r\n",
"[]> \n"
]
}
@@ -63,7 +63,7 @@
{
"cell_type": "code",
"execution_count": 4,
- "id": "32107a2e",
+ "id": "a8fecdce",
"metadata": {},
"outputs": [
{
@@ -87,10 +87,7 @@
"metadata": {},
"outputs": [],
"source": [
- "explain_prompt = \"Given the following Formula DSL program modeling a physical drone,\\\n",
- " explain what the invalidBatteryPartialModel partial model is modeling \\\n",
- " and give detailed solutions that would decrease the battery consumption in the invalidBatteryPartialModel.\\\n",
- " Put the solutions in a list.\""
+ "explain_prompt = \"Given the following Formula DSL program modeling a physical drone, explain what the invalidBatteryPartialModel partial model is modeling. Give a detailed list of solutions, without specific values, that can be made to the payload and mission items in partial model invalidBatteryPartialModel which decrease values and will give a high enough battery capacity for the mission.\""
]
},
{
@@ -121,22 +118,30 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "\u001b[32;1m\u001b[1;3mThe invalidBatteryPartialModel is modeling a drone mission with a battery that has an unknown capacity (represented by the variable x). The model includes the components of the drone (payload and body) and the locations for each mission item. It also includes the mission items themselves, which consist of a label, source and destination locations, distance, and velocity.\n",
+ "\u001b[32;1m\u001b[1;3mThe invalidBatteryPartialModel partial model is modeling a drone with a battery that has an insufficient capacity to complete the mission. The model includes the drone's components (payload and body), the battery with its weight and capacity, and the locations and details of each mission item.\n",
"\n",
- "The problem with the invalidBatteryPartialModel is that it does not specify a valid battery capacity. This makes it impossible to calculate the energy consumption and check if the battery capacity is exceeded. To fix this, we need to provide a valid battery capacity value.\n",
+ "To fix the issue of the battery capacity being insufficient for the mission, we can make the following changes to decrease the energy consumption:\n",
"\n",
- "Solutions to decrease battery consumption in the invalidBatteryPartialModel:\n",
- "1. Optimize the drone's flight path: By optimizing the flight path, the drone can minimize the distance traveled and reduce the overall energy consumption.\n",
- "2. Reduce the payload weight: The payload weight directly affects the energy consumption of the drone. By reducing the payload weight, the battery consumption can be decreased.\n",
- "3. Improve the drone's efficiency: This can be achieved by using more efficient components and technologies, such as lightweight materials, efficient motors, and aerodynamic designs.\n",
- "4. Adjust the drone's velocity: By adjusting the drone's velocity based on the mission requirements, the energy consumption can be optimized. Slower velocities generally result in lower energy consumption.\n",
- "5. Implement energy-saving algorithms: Use algorithms that optimize the drone's flight path and energy consumption, taking into account factors such as wind conditions, altitude, and mission requirements.\n",
- "6. Increase the battery capacity: If the current battery capacity is insufficient for the mission, consider upgrading to a higher capacity battery to ensure sufficient power for the entire mission.\n",
+ "1. Decrease the weight of the payload component: By reducing the weight of the payload, the overall energy consumption of the drone will decrease, allowing it to complete the mission with a lower battery capacity.\n",
"\n",
- "Note: The specific solutions may vary depending on the requirements and constraints of the drone mission.\u001b[0m\n",
+ "2. Decrease the velocity of the drone: By reducing the velocity at which the drone moves between mission items, the energy consumption will decrease. This can be achieved by adjusting the velocity value in each MissionItem.\n",
+ "\n",
+ "3. Optimize the mission route: By optimizing the route of the mission items, the total distance traveled by the drone can be reduced, resulting in lower energy consumption. This can be done by rearranging the order of the mission items or finding a more efficient path between them.\n",
+ "\n",
+ "4. Increase the battery capacity: If the above solutions are not sufficient to decrease the energy consumption to a level that can be supported by the current battery capacity, the battery capacity can be increased. This can be done by replacing the current battery with one that has a higher capacity.\n",
+ "\n",
+ "By implementing these solutions, the energy consumption of the drone can be reduced, allowing it to complete the mission with a high enough battery capacity.\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
]
+ },
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "Failed to patch https://api.smith.langchain.com/runs/7ae29509-d555-4107-93ee-1b53606cfd79 in LangSmith API. 401 Client Error: Unauthorized for url: https://api.smith.langchain.com/runs/7ae29509-d555-4107-93ee-1b53606cfd79\n",
+ "{\"detail\":\"Invalid auth\"}\n"
+ ]
}
],
"source": [
@@ -145,18 +150,17 @@
},
{
"cell_type": "code",
- "execution_count": 13,
+ "execution_count": 7,
"id": "ac31c0b2",
"metadata": {},
"outputs": [],
"source": [
- "repair_prompt = \"Repair the invalidBatteryPartialModel by reducing the payload1 and body component weights \\\n",
- " so that the sum of the missionConsumptions will be below the batteryCapacity. Edit the code and enclose in triple backticks.\""
+ "repair_prompt = \"Repair the invalidBatteryPartialModel by reducing the payload1 and body component weights so that the sum of the missionConsumptions will be below the batteryCapacity. Do not shorten or comment that the code remains the same in the edited code.\""
]
},
{
"cell_type": "code",
- "execution_count": 14,
+ "execution_count": 8,
"id": "50f00b79",
"metadata": {},
"outputs": [
@@ -168,38 +172,256 @@
"\n",
"\n",
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
- "\u001b[32;1m\u001b[1;3mThe invalidBatteryPartialModel is not solvable because the sum of the missionConsumptions exceeds the batteryCapacity. To fix this, we need to reduce the weights of the payload1 and body components so that the sum of the missionConsumptions will be below the batteryCapacity.\n",
+ "\u001b[32;1m\u001b[1;3mThe invalidBatteryPartialModel is not solvable because the sum of the missionConsumptions exceeds the batteryCapacity. To fix this, we need to reduce the payload1 and body component weights so that the sum of the missionConsumptions will be below the batteryCapacity.\n",
"\n",
- "Here is the corrected code:\n",
+ "Here is the modified code:\n",
"\n",
- "```formula\n",
+ "```python\n",
"partial model invalidBatteryPartialModel of BatteryChecker\n",
"[solver_RecursionBound = 200]\n",
"{\n",
- " Component(\"payload1\", 5). // Reduce the weight of payload1 to 5\n",
- " Component(\"body\", 5). // Reduce the weight of body to 5\n",
+ " Component(\"payload1\", 10). // reduce the weight of payload1 to 10\n",
+ " Component(\"body\", 10). // reduce the weight of body to 10\n",
" Battery(\"battery1\", 10, x).\n",
"\n",
- " // Rest of the code remains the same\n",
- " ...\n",
+ " // rest of the code remains the same\n",
"}\n",
"```\n",
"\n",
- "By reducing the weights of the payload1 and body components to 5, the sum of the missionConsumptions will be below the batteryCapacity and the model will be solvable.\u001b[0m\n",
+ "In this modified code, we have reduced the weights of payload1 and body components to 10 each. This will decrease the total weight and ensure that the sum of the missionConsumptions is below the batteryCapacity.\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
]
}
],
"source": [
- "%repair --repair-prompt \"$repair_prompt\""
+ "%repair --repair-prompt \"$repair_prompt\" --save \"C:\\Users\\sajtt\\Documents\\IBC_Repaired.4ml\""
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 9,
"id": "031a42f0",
"metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "(Uninstalled) InvalidBatteryChecker.4ml\r\n",
+ "0.02s.\r\n",
+ "[]> \n"
+ ]
+ }
+ ],
+ "source": [
+ "unload *"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "id": "a1fa598c",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "(Compiled) IBC_Repaired.4ml\r\n",
+ "0.10s.\r\n",
+ "[]> \n"
+ ]
+ }
+ ],
+ "source": [
+ "%load C:\\Users\\sajtt\\Documents\\IBC_Repaired.4ml"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "id": "6430f895",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Parsing text took: 0\r\n",
+ "Visiting text took: 0\r\n",
+ "Started solve task with Id 1.\r\n",
+ "0.15s.\r\n",
+ "[]> \n"
+ ]
+ }
+ ],
+ "source": [
+ "%solve invalidBatteryPartialModel 1 BatteryChecker.conforms"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "id": "f4bcaa54",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\r\n",
+ "Environment variables\r\n",
+ "\r\n",
+ "Programs in file root\r\n",
+ " +-- /\r\n",
+ " +-- C:\r\n",
+ " +-- Users\r\n",
+ " +-- sajtt\r\n",
+ " +-- Documents [1 file(s)]\r\n",
+ " | IBC_Repaired.4ml\r\n",
+ "\r\n",
+ "Programs in env root\r\n",
+ " +-- /\r\n",
+ "\r\n",
+ "All tasks\r\n",
+ " Id | Kind | Status | Result | Started | Duration \r\n",
+ "----|-------|--------|--------|--------------------|----------\r\n",
+ " 0 | Solve | Done | false | 10/11/2023 3:11 PM | 0.23s \r\n",
+ " 1 | Solve | Done | true | 10/11/2023 3:12 PM | 0.12s \r\n",
+ "0.02s.\r\n",
+ "[]> \n"
+ ]
+ }
+ ],
+ "source": [
+ "%ls"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "id": "af6d5430",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Solution number 0\r\n",
+ "Loc(348359939289367/500000000, 3042259730971371/500000000)\r\n",
+ "Loc(6966679095079647/10000000000, 6084604057664893/1000000000)\r\n",
+ "MissionItem(\"task1\", Loc(348359939289367/500000000, 3042259730971371/500000000), Loc(6966679095079647/10000000000, 6084604057664893/1000000000), 2482/25, 20)\r\n",
+ "Loc(696461285074487/1000000000, 6084542540980599/1000000000)\r\n",
+ "MissionItem(\"task2\", Loc(6966679095079647/10000000000, 6084604057664893/1000000000), Loc(696461285074487/1000000000, 6084542540980599/1000000000), 21559/100, 20)\r\n",
+ "Loc(174120966433329/250000000, 12169662311817959/2000000000)\r\n",
+ "MissionItem(\"task3\", Loc(696461285074487/1000000000, 6084542540980599/1000000000), Loc(174120966433329/250000000, 12169662311817959/2000000000), 579/2, 20)\r\n",
+ "Loc(6967682301751517/10000000000, 3042419349416769/500000000)\r\n",
+ "MissionItem(\"task4\", Loc(174120966433329/250000000, 12169662311817959/2000000000), Loc(6967682301751517/10000000000, 3042419349416769/500000000), 14223/50, 20)\r\n",
+ "Loc(6970660425451219/10000000000, 3042416698520287/500000000)\r\n",
+ "MissionItem(\"task5\", Loc(6967682301751517/10000000000, 3042419349416769/500000000), Loc(6970660425451219/10000000000, 3042416698520287/500000000), 14893/50, 20)\r\n",
+ "Loc(1742667670507127/2500000000, 3042126967169119/500000000)\r\n",
+ "MissionItem(\"task6\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20)\r\n",
+ "Loc(435450719207871/625000000, 1521129858526317/250000000)\r\n",
+ "MissionItem(\"task7\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20)\r\n",
+ "MissionItem(\"task8\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20)\r\n",
+ "MissionItem(\"task9\", Loc(348359939289367/500000000, 3042259730971371/500000000), Loc(6966679095079647/10000000000, 6084604057664893/1000000000), 2482/25, 20)\r\n",
+ "MissionItem(\"task10\", Loc(6966679095079647/10000000000, 6084604057664893/1000000000), Loc(696461285074487/1000000000, 6084542540980599/1000000000), 21559/100, 20)\r\n",
+ "MissionItem(\"task11\", Loc(696461285074487/1000000000, 6084542540980599/1000000000), Loc(174120966433329/250000000, 12169662311817959/2000000000), 579/2, 20)\r\n",
+ "MissionItem(\"task12\", Loc(174120966433329/250000000, 12169662311817959/2000000000), Loc(6967682301751517/10000000000, 3042419349416769/500000000), 14223/50, 20)\r\n",
+ "MissionItem(\"task13\", Loc(6967682301751517/10000000000, 3042419349416769/500000000), Loc(6970660425451219/10000000000, 3042416698520287/500000000), 14893/50, 20)\r\n",
+ "MissionItem(\"task14\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20)\r\n",
+ "MissionItem(\"task15\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20)\r\n",
+ "MissionItem(\"task16\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20)\r\n",
+ "Mission(MissionItem(\"task16\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), NIL)\r\n",
+ "Mission(MissionItem(\"task15\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task16\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), NIL))\r\n",
+ "Mission(MissionItem(\"task14\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20), Mission(MissionItem(\"task15\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task16\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), NIL)))\r\n",
+ "Mission(MissionItem(\"task13\", Loc(6967682301751517/10000000000, 3042419349416769/500000000), Loc(6970660425451219/10000000000, 3042416698520287/500000000), 14893/50, 20), Mission(MissionItem(\"task14\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20), Mission(MissionItem(\"task15\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task16\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), NIL))))\r\n",
+ "Mission(MissionItem(\"task12\", Loc(174120966433329/250000000, 12169662311817959/2000000000), Loc(6967682301751517/10000000000, 3042419349416769/500000000), 14223/50, 20), Mission(MissionItem(\"task13\", Loc(6967682301751517/10000000000, 3042419349416769/500000000), Loc(6970660425451219/10000000000, 3042416698520287/500000000), 14893/50, 20), Mission(MissionItem(\"task14\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20), Mission(MissionItem(\"task15\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task16\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), NIL)))))\r\n",
+ "Mission(MissionItem(\"task11\", Loc(696461285074487/1000000000, 6084542540980599/1000000000), Loc(174120966433329/250000000, 12169662311817959/2000000000), 579/2, 20), Mission(MissionItem(\"task12\", Loc(174120966433329/250000000, 12169662311817959/2000000000), Loc(6967682301751517/10000000000, 3042419349416769/500000000), 14223/50, 20), Mission(MissionItem(\"task13\", Loc(6967682301751517/10000000000, 3042419349416769/500000000), Loc(6970660425451219/10000000000, 3042416698520287/500000000), 14893/50, 20), Mission(MissionItem(\"task14\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20), Mission(MissionItem(\"task15\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task16\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), NIL))))))\r\n",
+ "Mission(MissionItem(\"task10\", Loc(6966679095079647/10000000000, 6084604057664893/1000000000), Loc(696461285074487/1000000000, 6084542540980599/1000000000), 21559/100, 20), Mission(MissionItem(\"task11\", Loc(696461285074487/1000000000, 6084542540980599/1000000000), Loc(174120966433329/250000000, 12169662311817959/2000000000), 579/2, 20), Mission(MissionItem(\"task12\", Loc(174120966433329/250000000, 12169662311817959/2000000000), Loc(6967682301751517/10000000000, 3042419349416769/500000000), 14223/50, 20), Mission(MissionItem(\"task13\", Loc(6967682301751517/10000000000, 3042419349416769/500000000), Loc(6970660425451219/10000000000, 3042416698520287/500000000), 14893/50, 20), Mission(MissionItem(\"task14\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20), Mission(MissionItem(\"task15\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task16\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), NIL)))))))\r\n",
+ "Mission(MissionItem(\"task9\", Loc(348359939289367/500000000, 3042259730971371/500000000), Loc(6966679095079647/10000000000, 6084604057664893/1000000000), 2482/25, 20), Mission(MissionItem(\"task10\", Loc(6966679095079647/10000000000, 6084604057664893/1000000000), Loc(696461285074487/1000000000, 6084542540980599/1000000000), 21559/100, 20), Mission(MissionItem(\"task11\", Loc(696461285074487/1000000000, 6084542540980599/1000000000), Loc(174120966433329/250000000, 12169662311817959/2000000000), 579/2, 20), Mission(MissionItem(\"task12\", Loc(174120966433329/250000000, 12169662311817959/2000000000), Loc(6967682301751517/10000000000, 3042419349416769/500000000), 14223/50, 20), Mission(MissionItem(\"task13\", Loc(6967682301751517/10000000000, 3042419349416769/500000000), Loc(6970660425451219/10000000000, 3042416698520287/500000000), 14893/50, 20), Mission(MissionItem(\"task14\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20), Mission(MissionItem(\"task15\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task16\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), NIL))))))))\r\n",
+ "Mission(MissionItem(\"task8\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), Mission(MissionItem(\"task9\", Loc(348359939289367/500000000, 3042259730971371/500000000), Loc(6966679095079647/10000000000, 6084604057664893/1000000000), 2482/25, 20), Mission(MissionItem(\"task10\", Loc(6966679095079647/10000000000, 6084604057664893/1000000000), Loc(696461285074487/1000000000, 6084542540980599/1000000000), 21559/100, 20), Mission(MissionItem(\"task11\", Loc(696461285074487/1000000000, 6084542540980599/1000000000), Loc(174120966433329/250000000, 12169662311817959/2000000000), 579/2, 20), Mission(MissionItem(\"task12\", Loc(174120966433329/250000000, 12169662311817959/2000000000), Loc(6967682301751517/10000000000, 3042419349416769/500000000), 14223/50, 20), Mission(MissionItem(\"task13\", Loc(6967682301751517/10000000000, 3042419349416769/500000000), Loc(6970660425451219/10000000000, 3042416698520287/500000000), 14893/50, 20), Mission(MissionItem(\"task14\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20), Mission(MissionItem(\"task15\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task16\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), NIL)))))))))\r\n",
+ "Mission(MissionItem(\"task7\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task8\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), Mission(MissionItem(\"task9\", Loc(348359939289367/500000000, 3042259730971371/500000000), Loc(6966679095079647/10000000000, 6084604057664893/1000000000), 2482/25, 20), Mission(MissionItem(\"task10\", Loc(6966679095079647/10000000000, 6084604057664893/1000000000), Loc(696461285074487/1000000000, 6084542540980599/1000000000), 21559/100, 20), Mission(MissionItem(\"task11\", Loc(696461285074487/1000000000, 6084542540980599/1000000000), Loc(174120966433329/250000000, 12169662311817959/2000000000), 579/2, 20), Mission(MissionItem(\"task12\", Loc(174120966433329/250000000, 12169662311817959/2000000000), Loc(6967682301751517/10000000000, 3042419349416769/500000000), 14223/50, 20), Mission(MissionItem(\"task13\", Loc(6967682301751517/10000000000, 3042419349416769/500000000), Loc(6970660425451219/10000000000, 3042416698520287/500000000), 14893/50, 20), Mission(MissionItem(\"task14\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20), Mission(MissionItem(\"task15\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task16\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), NIL))))))))))\r\n",
+ "Mission(MissionItem(\"task6\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20), Mission(MissionItem(\"task7\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task8\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), Mission(MissionItem(\"task9\", Loc(348359939289367/500000000, 3042259730971371/500000000), Loc(6966679095079647/10000000000, 6084604057664893/1000000000), 2482/25, 20), Mission(MissionItem(\"task10\", Loc(6966679095079647/10000000000, 6084604057664893/1000000000), Loc(696461285074487/1000000000, 6084542540980599/1000000000), 21559/100, 20), Mission(MissionItem(\"task11\", Loc(696461285074487/1000000000, 6084542540980599/1000000000), Loc(174120966433329/250000000, 12169662311817959/2000000000), 579/2, 20), Mission(MissionItem(\"task12\", Loc(174120966433329/250000000, 12169662311817959/2000000000), Loc(6967682301751517/10000000000, 3042419349416769/500000000), 14223/50, 20), Mission(MissionItem(\"task13\", Loc(6967682301751517/10000000000, 3042419349416769/500000000), Loc(6970660425451219/10000000000, 3042416698520287/500000000), 14893/50, 20), Mission(MissionItem(\"task14\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20), Mission(MissionItem(\"task15\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task16\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), NIL)))))))))))\r\n",
+ "Mission(MissionItem(\"task5\", Loc(6967682301751517/10000000000, 3042419349416769/500000000), Loc(6970660425451219/10000000000, 3042416698520287/500000000), 14893/50, 20), Mission(MissionItem(\"task6\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20), Mission(MissionItem(\"task7\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task8\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), Mission(MissionItem(\"task9\", Loc(348359939289367/500000000, 3042259730971371/500000000), Loc(6966679095079647/10000000000, 6084604057664893/1000000000), 2482/25, 20), Mission(MissionItem(\"task10\", Loc(6966679095079647/10000000000, 6084604057664893/1000000000), Loc(696461285074487/1000000000, 6084542540980599/1000000000), 21559/100, 20), Mission(MissionItem(\"task11\", Loc(696461285074487/1000000000, 6084542540980599/1000000000), Loc(174120966433329/250000000, 12169662311817959/2000000000), 579/2, 20), Mission(MissionItem(\"task12\", Loc(174120966433329/250000000, 12169662311817959/2000000000), Loc(6967682301751517/10000000000, 3042419349416769/500000000), 14223/50, 20), Mission(MissionItem(\"task13\", Loc(6967682301751517/10000000000, 3042419349416769/500000000), Loc(6970660425451219/10000000000, 3042416698520287/500000000), 14893/50, 20), Mission(MissionItem(\"task14\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20), Mission(MissionItem(\"task15\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task16\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), NIL))))))))))))\r\n",
+ "Mission(MissionItem(\"task4\", Loc(174120966433329/250000000, 12169662311817959/2000000000), Loc(6967682301751517/10000000000, 3042419349416769/500000000), 14223/50, 20), Mission(MissionItem(\"task5\", Loc(6967682301751517/10000000000, 3042419349416769/500000000), Loc(6970660425451219/10000000000, 3042416698520287/500000000), 14893/50, 20), Mission(MissionItem(\"task6\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20), Mission(MissionItem(\"task7\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task8\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), Mission(MissionItem(\"task9\", Loc(348359939289367/500000000, 3042259730971371/500000000), Loc(6966679095079647/10000000000, 6084604057664893/1000000000), 2482/25, 20), Mission(MissionItem(\"task10\", Loc(6966679095079647/10000000000, 6084604057664893/1000000000), Loc(696461285074487/1000000000, 6084542540980599/1000000000), 21559/100, 20), Mission(MissionItem(\"task11\", Loc(696461285074487/1000000000, 6084542540980599/1000000000), Loc(174120966433329/250000000, 12169662311817959/2000000000), 579/2, 20), Mission(MissionItem(\"task12\", Loc(174120966433329/250000000, 12169662311817959/2000000000), Loc(6967682301751517/10000000000, 3042419349416769/500000000), 14223/50, 20), Mission(MissionItem(\"task13\", Loc(6967682301751517/10000000000, 3042419349416769/500000000), Loc(6970660425451219/10000000000, 3042416698520287/500000000), 14893/50, 20), Mission(MissionItem(\"task14\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20), Mission(MissionItem(\"task15\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task16\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), NIL)))))))))))))\r\n",
+ "Mission(MissionItem(\"task3\", Loc(696461285074487/1000000000, 6084542540980599/1000000000), Loc(174120966433329/250000000, 12169662311817959/2000000000), 579/2, 20), Mission(MissionItem(\"task4\", Loc(174120966433329/250000000, 12169662311817959/2000000000), Loc(6967682301751517/10000000000, 3042419349416769/500000000), 14223/50, 20), Mission(MissionItem(\"task5\", Loc(6967682301751517/10000000000, 3042419349416769/500000000), Loc(6970660425451219/10000000000, 3042416698520287/500000000), 14893/50, 20), Mission(MissionItem(\"task6\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20), Mission(MissionItem(\"task7\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task8\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), Mission(MissionItem(\"task9\", Loc(348359939289367/500000000, 3042259730971371/500000000), Loc(6966679095079647/10000000000, 6084604057664893/1000000000), 2482/25, 20), Mission(MissionItem(\"task10\", Loc(6966679095079647/10000000000, 6084604057664893/1000000000), Loc(696461285074487/1000000000, 6084542540980599/1000000000), 21559/100, 20), Mission(MissionItem(\"task11\", Loc(696461285074487/1000000000, 6084542540980599/1000000000), Loc(174120966433329/250000000, 12169662311817959/2000000000), 579/2, 20), Mission(MissionItem(\"task12\", Loc(174120966433329/250000000, 12169662311817959/2000000000), Loc(6967682301751517/10000000000, 3042419349416769/500000000), 14223/50, 20), Mission(MissionItem(\"task13\", Loc(6967682301751517/10000000000, 3042419349416769/500000000), Loc(6970660425451219/10000000000, 3042416698520287/500000000), 14893/50, 20), Mission(MissionItem(\"task14\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20), Mission(MissionItem(\"task15\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task16\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), NIL))))))))))))))\r\n",
+ "Mission(MissionItem(\"task2\", Loc(6966679095079647/10000000000, 6084604057664893/1000000000), Loc(696461285074487/1000000000, 6084542540980599/1000000000), 21559/100, 20), Mission(MissionItem(\"task3\", Loc(696461285074487/1000000000, 6084542540980599/1000000000), Loc(174120966433329/250000000, 12169662311817959/2000000000), 579/2, 20), Mission(MissionItem(\"task4\", Loc(174120966433329/250000000, 12169662311817959/2000000000), Loc(6967682301751517/10000000000, 3042419349416769/500000000), 14223/50, 20), Mission(MissionItem(\"task5\", Loc(6967682301751517/10000000000, 3042419349416769/500000000), Loc(6970660425451219/10000000000, 3042416698520287/500000000), 14893/50, 20), Mission(MissionItem(\"task6\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20), Mission(MissionItem(\"task7\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task8\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), Mission(MissionItem(\"task9\", Loc(348359939289367/500000000, 3042259730971371/500000000), Loc(6966679095079647/10000000000, 6084604057664893/1000000000), 2482/25, 20), Mission(MissionItem(\"task10\", Loc(6966679095079647/10000000000, 6084604057664893/1000000000), Loc(696461285074487/1000000000, 6084542540980599/1000000000), 21559/100, 20), Mission(MissionItem(\"task11\", Loc(696461285074487/1000000000, 6084542540980599/1000000000), Loc(174120966433329/250000000, 12169662311817959/2000000000), 579/2, 20), Mission(MissionItem(\"task12\", Loc(174120966433329/250000000, 12169662311817959/2000000000), Loc(6967682301751517/10000000000, 3042419349416769/500000000), 14223/50, 20), Mission(MissionItem(\"task13\", Loc(6967682301751517/10000000000, 3042419349416769/500000000), Loc(6970660425451219/10000000000, 3042416698520287/500000000), 14893/50, 20), Mission(MissionItem(\"task14\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20), Mission(MissionItem(\"task15\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task16\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), NIL)))))))))))))))\r\n",
+ "Mission(MissionItem(\"task1\", Loc(348359939289367/500000000, 3042259730971371/500000000), Loc(6966679095079647/10000000000, 6084604057664893/1000000000), 2482/25, 20), Mission(MissionItem(\"task2\", Loc(6966679095079647/10000000000, 6084604057664893/1000000000), Loc(696461285074487/1000000000, 6084542540980599/1000000000), 21559/100, 20), Mission(MissionItem(\"task3\", Loc(696461285074487/1000000000, 6084542540980599/1000000000), Loc(174120966433329/250000000, 12169662311817959/2000000000), 579/2, 20), Mission(MissionItem(\"task4\", Loc(174120966433329/250000000, 12169662311817959/2000000000), Loc(6967682301751517/10000000000, 3042419349416769/500000000), 14223/50, 20), Mission(MissionItem(\"task5\", Loc(6967682301751517/10000000000, 3042419349416769/500000000), Loc(6970660425451219/10000000000, 3042416698520287/500000000), 14893/50, 20), Mission(MissionItem(\"task6\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20), Mission(MissionItem(\"task7\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task8\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), Mission(MissionItem(\"task9\", Loc(348359939289367/500000000, 3042259730971371/500000000), Loc(6966679095079647/10000000000, 6084604057664893/1000000000), 2482/25, 20), Mission(MissionItem(\"task10\", Loc(6966679095079647/10000000000, 6084604057664893/1000000000), Loc(696461285074487/1000000000, 6084542540980599/1000000000), 21559/100, 20), Mission(MissionItem(\"task11\", Loc(696461285074487/1000000000, 6084542540980599/1000000000), Loc(174120966433329/250000000, 12169662311817959/2000000000), 579/2, 20), Mission(MissionItem(\"task12\", Loc(174120966433329/250000000, 12169662311817959/2000000000), Loc(6967682301751517/10000000000, 3042419349416769/500000000), 14223/50, 20), Mission(MissionItem(\"task13\", Loc(6967682301751517/10000000000, 3042419349416769/500000000), Loc(6970660425451219/10000000000, 3042416698520287/500000000), 14893/50, 20), Mission(MissionItem(\"task14\", Loc(6970660425451219/10000000000, 3042416698520287/500000000), Loc(1742667670507127/2500000000, 3042126967169119/500000000), 28973/50, 20), Mission(MissionItem(\"task15\", Loc(1742667670507127/2500000000, 3042126967169119/500000000), Loc(435450719207871/625000000, 1521129858526317/250000000), 21803/50, 20), Mission(MissionItem(\"task16\", Loc(435450719207871/625000000, 1521129858526317/250000000), Loc(348359939289367/500000000, 3042259730971371/500000000), 127/100, 20), NIL))))))))))))))))\r\n",
+ "Component(\"payload1\", 10)\r\n",
+ "Component(\"body\", 10)\r\n",
+ "Battery(\"battery1\", 10, 13565627/75)\r\n",
+ "itemDuration(\"task10\", 21559/2000)\r\n",
+ "itemDuration(\"task9\", 1241/250)\r\n",
+ "itemDuration(\"task8\", 127/2000)\r\n",
+ "itemDuration(\"task7\", 21803/1000)\r\n",
+ "itemDuration(\"task6\", 28973/1000)\r\n",
+ "itemDuration(\"task5\", 14893/1000)\r\n",
+ "itemDuration(\"task15\", 21803/1000)\r\n",
+ "itemDuration(\"task14\", 28973/1000)\r\n",
+ "itemDuration(\"task13\", 14893/1000)\r\n",
+ "itemDuration(\"task12\", 14223/1000)\r\n",
+ "itemDuration(\"task11\", 579/40)\r\n",
+ "itemDuration(\"task16\", 127/2000)\r\n",
+ "itemDuration(\"task4\", 14223/1000)\r\n",
+ "itemDuration(\"task3\", 579/40)\r\n",
+ "itemDuration(\"task2\", 21559/2000)\r\n",
+ "itemDuration(\"task1\", 1241/250)\r\n",
+ "rate(280/3)\r\n",
+ "batteryCapacity(13565627/75)\r\n",
+ "missionConsumption(\"task16\", 889/150)\r\n",
+ "missionConsumption(\"task15\", 306131/150)\r\n",
+ "missionConsumption(\"task14\", 237251/50)\r\n",
+ "missionConsumption(\"task13\", 184051/30)\r\n",
+ "missionConsumption(\"task12\", 1119377/150)\r\n",
+ "missionConsumption(\"task11\", 1322027/150)\r\n",
+ "missionConsumption(\"task10\", 49098/5)\r\n",
+ "missionConsumption(\"task9\", 771218/75)\r\n",
+ "missionConsumption(\"task8\", 61733/6)\r\n",
+ "missionConsumption(\"task7\", 616189/50)\r\n",
+ "missionConsumption(\"task6\", 2254189/150)\r\n",
+ "missionConsumption(\"task5\", 820897/50)\r\n",
+ "missionConsumption(\"task4\", 887271/50)\r\n",
+ "missionConsumption(\"task3\", 954821/50)\r\n",
+ "missionConsumption(\"task2\", 1507688/75)\r\n",
+ "missionConsumption(\"task1\", 1542436/75)\r\n",
+ "invalidBattery(13565552/75)\r\n",
+ "requiredCapacity(13565552/75)\r\n",
+ "\r\n",
+ "\r\n",
+ "0.00s.\r\n",
+ "[]> \n"
+ ]
+ }
+ ],
+ "source": [
+ "%extract 1 0 0"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "id": "57224346",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "180875.02666666667\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(13565627/75.0)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "e0ee776c",
+ "metadata": {},
"outputs": [],
"source": []
}
diff --git a/Src/Kernel/FormulaPy/formula/formula_agent.py b/Src/Kernel/FormulaPy/formula/formula_agent.py
index 5b54835..ba2e4ae 100644
--- a/Src/Kernel/FormulaPy/formula/formula_agent.py
+++ b/Src/Kernel/FormulaPy/formula/formula_agent.py
@@ -6,7 +6,7 @@
from langchain.memory import ConversationBufferMemory
from .formula_tools import FormulaCodeLLM, RepairFormulaCodeLLM
from .config import cfg
-from .prompts import FIX_CODE_PREFIX, REPAIR_CODE_PREFIX
+from .prompts import FIX_CODE_PREFIX, REPAIR_CODE_PREFIX, REPAIR_QUERY_PROMPT, EXPLAIN_QUERY_PROMPT
os.environ["OPENAI_API_KEY"] = cfg["OPENAI_API_KEY"]
#os.environ["OPENAI_API_TYPE"] = "azure"
@@ -22,7 +22,7 @@
os.environ["LANGCHAIN_PROJECT"] ="pt-oily-sultan-99"
-llm = ChatOpenAI(temperature=0, model_name="gpt-3.5-turbo-16k")
+llm = ChatOpenAI(temperature=0.0, model_name="gpt-3.5-turbo")
system_message = SystemMessage(content=FIX_CODE_PREFIX)
@@ -58,15 +58,15 @@
agent_executor_repair = AgentExecutor.from_agent_and_tools(
agent=agent_repair,
tools=repair_tools,
- verbose=True,
+ verbose=True
)
def run_agent_executor(code, output, explain_prompt):
- prompts = "{explain_prompt}\n\n{code}\n\n{output}".format(code=code, output=output, explain_prompt=explain_prompt)
+ prompts = EXPLAIN_QUERY_PROMPT.format(code=code, output=output, prompt=explain_prompt)
prompts.encode('unicode_escape')
agent_executor.run(prompts)
def run_agent_executor_repair(code, output, repair_prompt):
- prompts = "{repair_prompt}\n\n{code}\n\n{output}".format(code=code, output=output, repair_prompt=repair_prompt)
+ prompts = REPAIR_QUERY_PROMPT.format(code=code, output=output, prompt=repair_prompt)
prompts.encode('unicode_escape')
- agent_executor_repair.run(prompts)
\ No newline at end of file
+ return agent_executor_repair.run(prompts)
\ No newline at end of file
diff --git a/Src/Kernel/FormulaPy/formula/formula_magic.py b/Src/Kernel/FormulaPy/formula/formula_magic.py
index 6758cbd..10945a1 100644
--- a/Src/Kernel/FormulaPy/formula/formula_magic.py
+++ b/Src/Kernel/FormulaPy/formula/formula_magic.py
@@ -21,9 +21,6 @@ def __init__(self, shell, data=None):
Console.SetOut(self.sw)
Console.SetError(self.sw)
self.file_txt = None
- self.explain_ran = False
- self.solve_ran = False
- self.repair_ran = False
sink = CommandLineProgram.ConsoleSink()
chooser = CommandLineProgram.ConsoleChooser()
@@ -83,10 +80,6 @@ def run_command(self, cmd, args=None):
@line_magic
def load(self, line):
- if self.file_txt != None:
- print("A Formula DSL program is already loaded.")
- return
-
file = os.path.abspath(line)
if os.path.isfile(file):
f = open(file, 'r')
@@ -117,7 +110,7 @@ def extract(self, line):
@line_magic
def ex(self, line):
- self.extract_ran(line)
+ self.extract(line)
@line_magic
def query(self, line):
@@ -133,7 +126,6 @@ def solve(self, line):
print("Load 4ml file to proceed.")
return
self.run_command("solve", line)
- self.solve_ran = True
@line_magic
def sl(self, line):
@@ -156,7 +148,6 @@ def explain(self, line):
print('Running executor...')
run_agent_executor(self.file_txt, self.total_sw_output, args.explain_prompt)
- self.explain_ran = True
@line_magic
def exp(self, line):
@@ -169,17 +160,45 @@ def exp(self, line):
required=True,
help=("Input repair prompt."),
)
+ @argument(
+ "--save",
+ "-s",
+ required=False,
+ help=("Save repair code."),
+ )
@line_magic
def repair(self, line):
- if self.explain_ran:
- print('Running repair...')
+ print('Running repair...')
- args = parse_argstring(self.repair, line)
+ args = parse_argstring(self.repair, line)
- run_agent_executor_repair(self.file_txt, self.total_sw_output, args.repair_prompt)
- else:
- print("Run explain magic function first.")
-
+ out = run_agent_executor_repair(self.file_txt, self.total_sw_output, args.repair_prompt)
+
+ if args.save:
+ m = re.search('\`\`\`(code|formula|python)?.+\{(.+)\}', out, re.DOTALL)
+ if m:
+ capt = m.group(2)
+ m2 = re.findall('(.+)\s\/\/.+', capt)
+ if len(m2) > 0:
+ new_txt = self.file_txt
+ for l in m2:
+ temp = re.sub(r'\s\d+', r'\\s\\d+', l)
+ temp = temp.removesuffix('.')
+ temp = temp.replace("(", "\(")
+ temp = temp.replace(")", "\)")
+ l = l.removesuffix('.')
+ new_txt = re.sub(temp, l, new_txt)
+
+ f = open(args.save, 'w')
+ try:
+ f.write(new_txt)
+ finally:
+ f.close()
+ else:
+ print('No match found in partial model. Unable to save.')
+ else:
+ print('No match found in GPT generated code. Unable to save.')
+
@line_magic
def rep(self, line):
self.repair(line)
diff --git a/Src/Kernel/FormulaPy/formula/formula_tools.py b/Src/Kernel/FormulaPy/formula/formula_tools.py
index 67b1e68..e9b4b85 100644
--- a/Src/Kernel/FormulaPy/formula/formula_tools.py
+++ b/Src/Kernel/FormulaPy/formula/formula_tools.py
@@ -22,17 +22,15 @@ class FormulaCodeLLM(BaseTool):
description = FORMULA_CODE_LLM_DESC
llm: BaseChatModel
- def _run(self, **kwargs) -> Any:
- explain_prompt = kwargs["explain_prompt"]
+ def _run(self, arg, **kwargs) -> Any:
+ explain_prompt = kwargs["prompt"]
code = kwargs["code"]
output = kwargs["output"]
explain_template = EXPLAIN_QUERY_PROMPT
-
- solutions_template = SOLUTIONS_QUERY_PROMPT
prompt_template = PromptTemplate(
- input_variables=["explain_prompt", "code", "output"],
+ input_variables=["prompt", "code", "output"],
template=explain_template,
)
@@ -56,15 +54,15 @@ class RepairFormulaCodeLLM(BaseTool):
description = REPAIR_FORMULA_CODE_LLM_DESC
llm: BaseChatModel
- def _run(self, **kwargs) -> Any:
- repair_prompt = kwargs["repair_prompt"]
+ def _run(self, arg, **kwargs) -> Any:
+ repair_prompt = kwargs["prompt"]
code = kwargs["code"]
output = kwargs["output"]
repair_template = REPAIR_QUERY_PROMPT
prompt_template = PromptTemplate(
- input_variables=["repair_prompt", "code", "output"],
+ input_variables=["prompt", "code", "output"],
template=repair_template,
)
diff --git a/Src/Kernel/FormulaPy/formula/prompts.py b/Src/Kernel/FormulaPy/formula/prompts.py
index 004f6fd..6cf40a3 100644
--- a/Src/Kernel/FormulaPy/formula/prompts.py
+++ b/Src/Kernel/FormulaPy/formula/prompts.py
@@ -1,31 +1,31 @@
FIX_CODE_PREFIX = """ \
SYSTEM MESSAGE:
-You will be provided a Formula DSL program and unsat core (delimited with XML tags labelled code). You will explain why the program is broken and give solutions to fixing it.
+You will be provided a Formula DSL program and unsat core. You will explain why the program is broken and give solutions to fixing it.
END OF SYSTEM MESSAGE"""
REPAIR_CODE_PREFIX = """ \
SYSTEM MESSAGE:
-You will be provided a Formula DSL program and unsat core (delimited with XML tags labelled code). You will give repairs of the code in the Formula DSL language enclosed in triple backticks.
+You will be provided a Formula DSL program and unsat core. You will give repairs of the code in the Formula DSL language enclosed in code labelled triple backticks. Give the line numbers of the code in the triple backticks.
END OF SYSTEM MESSAGE"""
EXPLAIN_QUERY_PROMPT = """ \
-{explain_prompt}
+{prompt}
-{code}
+{code}
-{output}
+{output}
"""
REPAIR_QUERY_PROMPT = """ \
-{repair_prompt}
+{prompt}
-{code}
+{code}
-{output}
+{output}
"""
OUTPUT_RETURN = """ \