mito-ai 0.1.55__py3-none-any.whl → 0.1.56__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. mito_ai/_version.py +1 -1
  2. mito_ai/anthropic_client.py +7 -6
  3. mito_ai/completions/models.py +1 -1
  4. mito_ai/completions/prompt_builders/agent_execution_prompt.py +18 -50
  5. mito_ai/completions/prompt_builders/agent_smart_debug_prompt.py +77 -92
  6. mito_ai/completions/prompt_builders/agent_system_message.py +211 -275
  7. mito_ai/completions/prompt_builders/chat_prompt.py +15 -100
  8. mito_ai/completions/prompt_builders/chat_system_message.py +96 -72
  9. mito_ai/completions/prompt_builders/explain_code_prompt.py +22 -24
  10. mito_ai/completions/prompt_builders/inline_completer_prompt.py +78 -107
  11. mito_ai/completions/prompt_builders/prompt_constants.py +10 -48
  12. mito_ai/completions/prompt_builders/prompt_section_registry/__init__.py +70 -0
  13. mito_ai/completions/prompt_builders/prompt_section_registry/active_cell_code.py +15 -0
  14. mito_ai/completions/prompt_builders/prompt_section_registry/active_cell_id.py +10 -0
  15. mito_ai/completions/prompt_builders/prompt_section_registry/active_cell_output.py +20 -0
  16. mito_ai/completions/prompt_builders/prompt_section_registry/base.py +37 -0
  17. mito_ai/completions/prompt_builders/prompt_section_registry/error_traceback.py +17 -0
  18. mito_ai/completions/prompt_builders/prompt_section_registry/example.py +19 -0
  19. mito_ai/completions/prompt_builders/prompt_section_registry/files.py +17 -0
  20. mito_ai/completions/prompt_builders/prompt_section_registry/generic.py +15 -0
  21. mito_ai/completions/prompt_builders/prompt_section_registry/get_cell_output_tool_response.py +21 -0
  22. mito_ai/completions/prompt_builders/prompt_section_registry/notebook.py +19 -0
  23. mito_ai/completions/prompt_builders/prompt_section_registry/rules.py +39 -0
  24. mito_ai/completions/prompt_builders/{utils.py → prompt_section_registry/selected_context.py} +51 -42
  25. mito_ai/completions/prompt_builders/prompt_section_registry/streamlit_app_status.py +25 -0
  26. mito_ai/completions/prompt_builders/prompt_section_registry/task.py +12 -0
  27. mito_ai/completions/prompt_builders/prompt_section_registry/variables.py +18 -0
  28. mito_ai/completions/prompt_builders/smart_debug_prompt.py +48 -63
  29. mito_ai/constants.py +0 -3
  30. mito_ai/tests/completions/test_prompt_section_registry.py +44 -0
  31. mito_ai/tests/message_history/test_message_history_utils.py +273 -340
  32. mito_ai/tests/providers/test_anthropic_client.py +7 -3
  33. mito_ai/utils/message_history_utils.py +68 -44
  34. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/build_log.json +1 -1
  35. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/package.json +2 -2
  36. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/schemas/mito_ai/package.json.orig +1 -1
  37. mito_ai-0.1.55.data/data/share/jupyter/labextensions/mito_ai/static/lib_index_js.49c79c62671528877c61.js → mito_ai-0.1.56.data/data/share/jupyter/labextensions/mito_ai/static/lib_index_js.dfd7975de75d64db80d6.js +487 -120
  38. mito_ai-0.1.56.data/data/share/jupyter/labextensions/mito_ai/static/lib_index_js.dfd7975de75d64db80d6.js.map +1 -0
  39. mito_ai-0.1.55.data/data/share/jupyter/labextensions/mito_ai/static/remoteEntry.9dfbffc3592eb6f0aef9.js → mito_ai-0.1.56.data/data/share/jupyter/labextensions/mito_ai/static/remoteEntry.1e7b5cf362385f109883.js +3 -3
  40. mito_ai-0.1.55.data/data/share/jupyter/labextensions/mito_ai/static/remoteEntry.9dfbffc3592eb6f0aef9.js.map → mito_ai-0.1.56.data/data/share/jupyter/labextensions/mito_ai/static/remoteEntry.1e7b5cf362385f109883.js.map +1 -1
  41. {mito_ai-0.1.55.dist-info → mito_ai-0.1.56.dist-info}/METADATA +5 -1
  42. {mito_ai-0.1.55.dist-info → mito_ai-0.1.56.dist-info}/RECORD +68 -52
  43. mito_ai-0.1.55.data/data/share/jupyter/labextensions/mito_ai/static/lib_index_js.49c79c62671528877c61.js.map +0 -1
  44. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/etc/jupyter/jupyter_server_config.d/mito_ai.json +0 -0
  45. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/schemas/mito_ai/toolbar-buttons.json +0 -0
  46. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/node_modules_process_browser_js.4b128e94d31a81ebd209.js +0 -0
  47. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/node_modules_process_browser_js.4b128e94d31a81ebd209.js.map +0 -0
  48. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/style.js +0 -0
  49. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/style_index_js.f5d476ac514294615881.js +0 -0
  50. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/style_index_js.f5d476ac514294615881.js.map +0 -0
  51. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_auth_dist_esm_providers_cognito_apis_signOut_mjs-node_module-75790d.688c25857e7b81b1740f.js +0 -0
  52. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_auth_dist_esm_providers_cognito_apis_signOut_mjs-node_module-75790d.688c25857e7b81b1740f.js.map +0 -0
  53. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_auth_dist_esm_providers_cognito_tokenProvider_tokenProvider_-72f1c8.a917210f057fcfe224ad.js +0 -0
  54. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_auth_dist_esm_providers_cognito_tokenProvider_tokenProvider_-72f1c8.a917210f057fcfe224ad.js.map +0 -0
  55. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_dist_esm_index_mjs.6bac1a8c4cc93f15f6b7.js +0 -0
  56. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_dist_esm_index_mjs.6bac1a8c4cc93f15f6b7.js.map +0 -0
  57. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_ui-react_dist_esm_index_mjs.4fcecd65bef9e9847609.js +0 -0
  58. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_ui-react_dist_esm_index_mjs.4fcecd65bef9e9847609.js.map +0 -0
  59. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_react-dom_client_js-node_modules_aws-amplify_ui-react_dist_styles_css.b43d4249e4d3dac9ad7b.js +0 -0
  60. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_react-dom_client_js-node_modules_aws-amplify_ui-react_dist_styles_css.b43d4249e4d3dac9ad7b.js.map +0 -0
  61. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_semver_index_js.3f6754ac5116d47de76b.js +0 -0
  62. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_semver_index_js.3f6754ac5116d47de76b.js.map +0 -0
  63. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_vscode-diff_dist_index_js.ea55f1f9346638aafbcf.js +0 -0
  64. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_vscode-diff_dist_index_js.ea55f1f9346638aafbcf.js.map +0 -0
  65. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/themes/mito_ai/index.css +0 -0
  66. {mito_ai-0.1.55.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/themes/mito_ai/index.js +0 -0
  67. {mito_ai-0.1.55.dist-info → mito_ai-0.1.56.dist-info}/WHEEL +0 -0
  68. {mito_ai-0.1.55.dist-info → mito_ai-0.1.56.dist-info}/entry_points.txt +0 -0
  69. {mito_ai-0.1.55.dist-info → mito_ai-0.1.56.dist-info}/licenses/LICENSE +0 -0
mito_ai/_version.py CHANGED
@@ -1,4 +1,4 @@
1
1
  # This file is auto-generated by Hatchling. As such, do not:
2
2
  # - modify
3
3
  # - track in version control e.g. be sure to add to .gitignore
4
- __version__ = VERSION = '0.1.55'
4
+ __version__ = VERSION = '0.1.56'
@@ -7,7 +7,7 @@ from typing import Dict, Any, Optional, Tuple, Union, Callable, List, cast
7
7
 
8
8
  from anthropic.types import Message, MessageParam, TextBlockParam
9
9
  from mito_ai.completions.models import ResponseFormatInfo, CompletionReply, CompletionStreamChunk, CompletionItem, MessageType
10
- from mito_ai.constants import MESSAGE_HISTORY_TRIM_THRESHOLD
10
+ from mito_ai.completions.prompt_builders.prompt_section_registry import get_max_trim_after_messages
11
11
  from openai.types.chat import ChatCompletionMessageParam
12
12
  from mito_ai.utils.anthropic_utils import get_anthropic_completion_from_mito_server, select_correct_model, stream_anthropic_completion_from_mito_server, get_anthropic_completion_function_params
13
13
 
@@ -15,6 +15,10 @@ from mito_ai.utils.anthropic_utils import get_anthropic_completion_from_mito_ser
15
15
  # We set it to a high number so that we can edit large code cells
16
16
  MAX_TOKENS = 64_000
17
17
 
18
+ # Calculate the max trim threshold once at module load time.
19
+ # This is used for cache boundary calculation - messages older than this threshold are stable.
20
+ MAX_TRIM_THRESHOLD = get_max_trim_after_messages()
21
+
18
22
  def extract_and_parse_anthropic_json_response(response: Message) -> Union[object, Any]:
19
23
  """
20
24
  Extracts and parses the JSON response from the Claude API.
@@ -170,9 +174,6 @@ def get_anthropic_system_prompt_and_messages_with_caching(messages: List[ChatCom
170
174
  1. System prompt (static) → Always cached
171
175
  2. Stable conversation history → Cache at keep_recent boundary
172
176
  3. Recent messages → Never cached (always fresh)
173
-
174
- The keep_recent parameter determines which messages are stable and won't be trimmed.
175
- We cache at the keep_recent boundary because those messages are guaranteed to be stable.
176
177
  """
177
178
 
178
179
  # Get the base system prompt and messages
@@ -189,14 +190,14 @@ def get_anthropic_system_prompt_and_messages_with_caching(messages: List[ChatCom
189
190
  }]
190
191
 
191
192
  # 2. Cache conversation history at the boundary where the messages are stable.
192
- # Messages are stable after they are more than MESSAGE_HISTORY_TRIM_THRESHOLD old.
193
+ # Messages are stable after they are older than the max trim_after_messages threshold.
193
194
  # At this point, the messages are not edited anymore, so they will not invalidate the cache.
194
195
  # If we included the messages before the boundary in the cache, then every time we send a new
195
196
  # message, we would invalidate the cache and we would never get a cache hit except for the system prompt.
196
197
  messages_with_cache = []
197
198
 
198
199
  if len(anthropic_messages) > 0:
199
- cache_boundary = len(anthropic_messages) - MESSAGE_HISTORY_TRIM_THRESHOLD - 1
200
+ cache_boundary = len(anthropic_messages) - MAX_TRIM_THRESHOLD - 1
200
201
 
201
202
  # Add all messages, but only add cache_control to the message at the boundary
202
203
  for i, msg in enumerate(anthropic_messages):
@@ -17,7 +17,7 @@ ThreadID = NewType('ThreadID', str)
17
17
 
18
18
  class CellUpdate(BaseModel):
19
19
  type: Literal['modification', 'new']
20
- index: Optional[int]
20
+ after_cell_id: Optional[str]
21
21
  id: Optional[str]
22
22
  code: str
23
23
  code_summary: str
@@ -1,57 +1,25 @@
1
1
  # Copyright (c) Saga Inc.
2
2
  # Distributed under the terms of the GNU Affero General Public License v3.0 License.
3
3
 
4
+ from typing import List
4
5
  from mito_ai.completions.models import AgentExecutionMetadata
5
- from mito_ai.completions.prompt_builders.prompt_constants import (
6
- ACTIVE_CELL_ID_SECTION_HEADING,
7
- FILES_SECTION_HEADING,
8
- JUPYTER_NOTEBOOK_SECTION_HEADING,
9
- STREAMLIT_APP_STATUS_SECTION_HEADING,
10
- VARIABLES_SECTION_HEADING,
11
- cell_update_output_str
12
- )
13
- from mito_ai.completions.prompt_builders.utils import (
14
- get_rules_str,
15
- get_selected_context_str,
16
- get_streamlit_app_status_str
17
- )
6
+ from mito_ai.completions.prompt_builders.prompt_section_registry import SG, Prompt
7
+ from mito_ai.completions.prompt_builders.prompt_section_registry.base import PromptSection
18
8
 
19
9
 
20
10
  def create_agent_execution_prompt(md: AgentExecutionMetadata) -> str:
21
- variables_str = '\n'.join([f"{variable}" for variable in md.variables or []])
22
- files_str = '\n'.join([f"{file}" for file in md.files or []])
23
- ai_optimized_cells_str = '\n'.join([f"{cell}" for cell in md.aiOptimizedCells or []])
24
- rules_str = get_rules_str(md.additionalContext)
25
- selected_context_str = get_selected_context_str(md.additionalContext)
26
-
27
-
28
- streamlit_status_str = get_streamlit_app_status_str(md.notebookID, md.notebookPath)
29
-
30
- context_str = f"""Remember to choose the correct tool to respond with.
31
-
32
- {rules_str}
33
-
34
-
35
- {JUPYTER_NOTEBOOK_SECTION_HEADING}
36
- {ai_optimized_cells_str}
37
-
38
- {VARIABLES_SECTION_HEADING}
39
- {variables_str}
40
-
41
- {FILES_SECTION_HEADING}
42
- {files_str}
43
-
44
- {STREAMLIT_APP_STATUS_SECTION_HEADING}
45
- {streamlit_status_str}
46
-
47
- {ACTIVE_CELL_ID_SECTION_HEADING}
48
- {md.activeCellId}
49
-
50
- {selected_context_str}
51
-
52
- {cell_update_output_str(md.base64EncodedActiveCellOutput is not None)}"""
53
-
54
- task_str = '' if md.input == '' else f"""Your task:
55
- {md.input}"""
56
-
57
- return '\n\n'.join([context_str, task_str]).strip()
11
+ sections: List[PromptSection] = [
12
+ SG.Generic("Reminder", "Remember to choose the correct tool to respond with."),
13
+ SG.Rules(md.additionalContext),
14
+ SG.StreamlitAppStatus(md.notebookID, md.notebookPath),
15
+ SG.Files(md.files),
16
+ SG.Variables(md.variables),
17
+ SG.SelectedContext(md.additionalContext),
18
+ SG.ActiveCellId(md.activeCellId),
19
+ SG.Notebook(md.aiOptimizedCells),
20
+ SG.GetCellOutputToolResponse(md.base64EncodedActiveCellOutput),
21
+ SG.Task(f"{md.input}"),
22
+ ]
23
+
24
+ prompt = Prompt(sections)
25
+ return str(prompt)
@@ -3,11 +3,8 @@
3
3
 
4
4
  from typing import List
5
5
  from mito_ai.completions.models import AgentSmartDebugMetadata
6
- from mito_ai.completions.prompt_builders.prompt_constants import (
7
- FILES_SECTION_HEADING,
8
- JUPYTER_NOTEBOOK_SECTION_HEADING,
9
- VARIABLES_SECTION_HEADING
10
- )
6
+ from mito_ai.completions.prompt_builders.prompt_section_registry import SG, Prompt
7
+ from mito_ai.completions.prompt_builders.prompt_section_registry.base import PromptSection
11
8
 
12
9
  # TODO:
13
10
  # 1. In the future, it might make sense to pass the previous CELL_UPDATE to this prompt?
@@ -18,11 +15,10 @@ from mito_ai.completions.prompt_builders.prompt_constants import (
18
15
  # graph of cells that we calculate ourselves, not relying on the AI.
19
16
 
20
17
  def create_agent_smart_debug_prompt(md: AgentSmartDebugMetadata) -> str:
21
- variables_str = '\n'.join([f"{variable}" for variable in md.variables or []])
22
- files_str = '\n'.join([f"{file}" for file in md.files or []])
23
- ai_optimized_cells_str = '\n'.join([f"{cell}" for cell in md.aiOptimizedCells or []])
18
+ sections: List[PromptSection] = []
24
19
 
25
- return f"""I just applied and executed the CELL_UPDATE that you just shared with me, but it errored. Below I am sharing with you a strategy for how I want you to resolve this error and information about the actual error that occured.
20
+ # Add intro text
21
+ sections.append(SG.Generic("Instructions", f"""I just applied and executed the CELL_UPDATE that you just shared with me, but it errored. Below I am sharing with you a strategy for how I want you to resolve this error and information about the actual error that occured.
26
22
 
27
23
  Use this strategy for this message only. After this message, continue using the original set of instructions that I provided you.
28
24
 
@@ -33,7 +29,7 @@ Step 1: ERROR ANALYSIS: Analyze the error message to identify why the code cell
33
29
  Step 2: INTENT PRESERVATION: Make sure you understand the intent of the CELL_UPDATE so that you can be sure to preserve it when you create a new CELL_UPDATE
34
30
  Step 3: ERROR CORRECTION: Respond with a new CELL_UPDATE that is applied to the same cell as the erroring CELL_UPDATE.
35
31
 
36
- <Instructions for each Phase />
32
+ INSTRUCTIONS FOR EACH PHASE
37
33
 
38
34
  ERROR ANALYSIS:
39
35
 
@@ -61,100 +57,89 @@ ERROR CORRECTION:
61
57
  type: 'run_all_cells',
62
58
  message: str
63
59
  }}
64
- Note that if the name error persists even after using run_all_cells, it means that the variable is not defined in the notebook and you should not reuse this tool. Additionally, this tool could also be used to refresh the notebook state.
65
-
66
- <Example>
67
-
68
- <Input>
69
-
70
- {FILES_SECTION_HEADING}
71
- file_name: sales.csv
72
-
73
- Jupyter Notebook:
74
- [
75
- {{
76
- cell_type: 'markdown'
77
- id: '9e38c62b-38f8-457d-bb8d-28bfc52edf2c'
78
- code: \"\"\"# Transaction Analysis \"\"\"
79
- }},
80
- {{
81
- cell_type: 'code'
82
- id: 'adslkaf-jf73-l8xn-92j7-kjd8kdcnd2kso'
83
- code: \"\"\" 'df' = pd.DataFrame({{
84
- 'order_id': [1, 2, 3, 4],
85
- 'date': ['Mar 7, 2025', 'Sep 24, 2024', '25 June, 2024', 'June 29, 2024'],
86
- 'amount': [100, 150, 299, 99]
87
- }})
88
- }},
60
+ Note that if the name error persists even after using run_all_cells, it means that the variable is not defined in the notebook and you should not reuse this tool. Additionally, this tool could also be used to refresh the notebook state."""))
61
+
62
+ # Add example
63
+ example_content = f"""
64
+ <Input>
65
+
66
+ Files:
67
+ "file_name: sales.csv"
68
+
69
+ Jupyter Notebook:
70
+ [
71
+ {{
72
+ cell_type: 'markdown'
73
+ id: '9e38c62b-38f8-457d-bb8d-28bfc52edf2c'
74
+ code: \"\"\"# Transaction Analysis \"\"\"
75
+ }},
76
+ {{
77
+ cell_type: 'code'
78
+ id: 'adslkaf-jf73-l8xn-92j7-kjd8kdcnd2kso'
79
+ code: \"\"\" 'df' = pd.DataFrame({{
80
+ 'order_id': [1, 2, 3, 4],
81
+ 'date': ['Mar 7, 2025', 'Sep 24, 2024', '25 June, 2024', 'June 29, 2024'],
82
+ 'amount': [100, 150, 299, 99]
83
+ }})
84
+ }},
85
+ {{
86
+ cell_type: 'code'
87
+ id: 'c68fdf19-db8c-46dd-926f-d90ad35bb3bc'
88
+ code: \"\"\"df['date'] = pd.to_datetime(df['date'])\"\"\"
89
+ }},
90
+ ]
91
+
92
+ Variables:
89
93
  {{
90
- cell_type: 'code'
91
- id: 'c68fdf19-db8c-46dd-926f-d90ad35bb3bc'
92
- code: \"\"\"df['date'] = pd.to_datetime(df['date'])\"\"\"
93
- }},
94
- ]
95
-
96
- {VARIABLES_SECTION_HEADING}
97
- {{
98
- 'df': pd.DataFrame({{
99
- 'order_id': [1, 2, 3, 4],
100
- 'date': ['Mar 7, 2025', 'Sep 24, 2024', '25 June, 2024', 'June 29, 2024'],
101
- 'amount': [100, 150, 299, 99]
102
- }})
103
- }}
104
-
105
- Cell ID of the Error Producing Code Cell:
106
- 'c68fdf19-db8c-46dd-926f-d90ad35bb3bc'
94
+ 'df': pd.DataFrame({{
95
+ 'order_id': [1, 2, 3, 4],
96
+ 'date': ['Mar 7, 2025', 'Sep 24, 2024', '25 June, 2024', 'June 29, 2024'],
97
+ 'amount': [100, 150, 299, 99]
98
+ }})
99
+ }}
107
100
 
108
- Error Traceback:
109
- Cell In[27], line 1
110
- ----> 1 df['date'] = pd.to_datetime(df['date'])
101
+ Cell ID of the Error Producing Code Cell:
102
+ 'c68fdf19-db8c-46dd-926f-d90ad35bb3bc'
111
103
 
112
- ValueError: time data "25 June, 2024" doesn't match format "%b %d, %Y", at position 2. You might want to try:
113
- - passing `format` if your strings have a consistent format;
114
- - passing `format='ISO8601'` if your strings are all ISO8601 but not necessarily in exactly the same format;
115
- - passing `format='mixed'`, and the format will be inferred for each element individually. You might want to use `dayfirst` alongside this.
104
+ Error Traceback:
105
+ Cell In[27], line 1
106
+ ----> 1 df['date'] = pd.to_datetime(df['date'])
116
107
 
108
+ ValueError: time data "25 June, 2024" doesn't match format "%b %d, %Y", at position 2. You might want to try:
109
+ - passing `format` if your strings have a consistent format;
110
+ - passing `format='ISO8601'` if your strings are all ISO8601 but not necessarily in exactly the same format;
111
+ - passing `format='mixed'`, and the format will be inferred for each element individually. You might want to use `dayfirst` alongside this.
117
112
 
118
- </ Input>
119
113
 
120
- < Your Thinking >
114
+ </ Input>
121
115
 
122
- ERROR ANALYSIS
123
- This is a ValueError caused by applying the wrong format to a specific date string. Because it was triggered at position 2, the first date string must have successfully converted. By looking at the defined variables, I can see that first date string is in the format "Mar 7, 2025", but the third date string is in the format "25 June, 2024". Those dates are not in the same format, so the conversion failed.
116
+ < Your Thinking >
124
117
 
125
- INTENT PRESERVATION:
126
- User is trying to convert the date column to a datetime object even though the dates are not in the same starting format.
118
+ ERROR ANALYSIS
119
+ This is a ValueError caused by applying the wrong format to a specific date string. Because it was triggered at position 2, the first date string must have successfully converted. By looking at the defined variables, I can see that first date string is in the format "Mar 7, 2025", but the third date string is in the format "25 June, 2024". Those dates are not in the same format, so the conversion failed.
127
120
 
128
- </ Your Thinking >
121
+ INTENT PRESERVATION:
122
+ User is trying to convert the date column to a datetime object even though the dates are not in the same starting format.
129
123
 
130
- <Output>
124
+ </ Your Thinking >
131
125
 
126
+ <Output>
132
127
 
133
- {{
134
- is_finished: false,
135
- cell_update: {{
136
- type: 'modification'
137
- id: 'c68fdf19-db8c-46dd-926f-d90ad35bb3bc'
138
- code: "def parse_date(date_str):\n formats = ['%b %d, %Y', '%d %B, %Y']\n\n for fmt in formats:\n try:\n return pd.to_datetime(date_str, format=fmt)\n except ValueError:\n # Try next format\n continue\n\n # If not format worked, return Not a Time\n return pd.NaT\n\ndf['date'] = df['date'].apply(lambda x: parse_date(x))"
128
+ {{
129
+ is_finished: false,
130
+ cell_update: {{
131
+ type: 'modification'
132
+ id: 'c68fdf19-db8c-46dd-926f-d90ad35bb3bc'
133
+ code: "def parse_date(date_str):\n formats = ['%b %d, %Y', '%d %B, %Y']\n\n for fmt in formats:\n try:\n return pd.to_datetime(date_str, format=fmt)\n except ValueError:\n # Try next format\n continue\n\n # If not format worked, return Not a Time\n return pd.NaT\n\ndf['date'] = df['date'].apply(lambda x: parse_date(x))"
134
+ }}
139
135
  }}
140
- }}
141
-
142
- </Output>
143
-
144
- </Example>
145
-
146
- {FILES_SECTION_HEADING}
147
- {files_str}
148
-
149
- {JUPYTER_NOTEBOOK_SECTION_HEADING}
150
- {ai_optimized_cells_str}
151
-
152
- {VARIABLES_SECTION_HEADING}
153
- {variables_str}
154
136
 
155
- Cell ID of the Error Producing Code Cell:
156
- {md.error_message_producing_code_cell_id}
137
+ </Output>"""
138
+ sections.append(SG.Example("Example", example_content))
139
+ sections.append(SG.Files(md.files))
140
+ sections.append(SG.Notebook(md.aiOptimizedCells))
141
+ sections.append(SG.Variables(md.variables))
142
+ sections.append(SG.ErrorTraceback(md.error_message_producing_code_cell_id, md.errorMessage))
157
143
 
158
- Error Traceback:
159
- {md.errorMessage}
160
- """
144
+ prompt = Prompt(sections)
145
+ return str(prompt)