mito-ai 0.1.54__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.
- mito_ai/_version.py +1 -1
- mito_ai/anthropic_client.py +7 -6
- mito_ai/completions/models.py +1 -1
- mito_ai/completions/prompt_builders/agent_execution_prompt.py +18 -50
- mito_ai/completions/prompt_builders/agent_smart_debug_prompt.py +77 -92
- mito_ai/completions/prompt_builders/agent_system_message.py +216 -270
- mito_ai/completions/prompt_builders/chat_prompt.py +15 -100
- mito_ai/completions/prompt_builders/chat_system_message.py +102 -63
- mito_ai/completions/prompt_builders/explain_code_prompt.py +22 -24
- mito_ai/completions/prompt_builders/inline_completer_prompt.py +78 -107
- mito_ai/completions/prompt_builders/prompt_constants.py +20 -36
- mito_ai/completions/prompt_builders/prompt_section_registry/__init__.py +70 -0
- mito_ai/completions/prompt_builders/prompt_section_registry/active_cell_code.py +15 -0
- mito_ai/completions/prompt_builders/prompt_section_registry/active_cell_id.py +10 -0
- mito_ai/completions/prompt_builders/prompt_section_registry/active_cell_output.py +20 -0
- mito_ai/completions/prompt_builders/prompt_section_registry/base.py +37 -0
- mito_ai/completions/prompt_builders/prompt_section_registry/error_traceback.py +17 -0
- mito_ai/completions/prompt_builders/prompt_section_registry/example.py +19 -0
- mito_ai/completions/prompt_builders/prompt_section_registry/files.py +17 -0
- mito_ai/completions/prompt_builders/prompt_section_registry/generic.py +15 -0
- mito_ai/completions/prompt_builders/prompt_section_registry/get_cell_output_tool_response.py +21 -0
- mito_ai/completions/prompt_builders/prompt_section_registry/notebook.py +19 -0
- mito_ai/completions/prompt_builders/prompt_section_registry/rules.py +39 -0
- mito_ai/completions/prompt_builders/prompt_section_registry/selected_context.py +100 -0
- mito_ai/completions/prompt_builders/prompt_section_registry/streamlit_app_status.py +25 -0
- mito_ai/completions/prompt_builders/prompt_section_registry/task.py +12 -0
- mito_ai/completions/prompt_builders/prompt_section_registry/variables.py +18 -0
- mito_ai/completions/prompt_builders/smart_debug_prompt.py +48 -63
- mito_ai/constants.py +0 -3
- mito_ai/tests/completions/test_prompt_section_registry.py +44 -0
- mito_ai/tests/message_history/test_message_history_utils.py +273 -340
- mito_ai/tests/providers/test_anthropic_client.py +7 -3
- mito_ai/utils/message_history_utils.py +68 -44
- mito_ai/utils/open_ai_utils.py +3 -0
- {mito_ai-0.1.54.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/build_log.json +147 -102
- {mito_ai-0.1.54.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/package.json +3 -2
- {mito_ai-0.1.54.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/schemas/mito_ai/package.json.orig +3 -2
- mito_ai-0.1.54.data/data/share/jupyter/labextensions/mito_ai/static/lib_index_js.31462f8f6a76b1cefbeb.js → mito_ai-0.1.56.data/data/share/jupyter/labextensions/mito_ai/static/lib_index_js.dfd7975de75d64db80d6.js +2689 -472
- mito_ai-0.1.56.data/data/share/jupyter/labextensions/mito_ai/static/lib_index_js.dfd7975de75d64db80d6.js.map +1 -0
- mito_ai-0.1.54.data/data/share/jupyter/labextensions/mito_ai/static/remoteEntry.3f3c98eaba66bf084c66.js → mito_ai-0.1.56.data/data/share/jupyter/labextensions/mito_ai/static/remoteEntry.1e7b5cf362385f109883.js +21 -19
- mito_ai-0.1.56.data/data/share/jupyter/labextensions/mito_ai/static/remoteEntry.1e7b5cf362385f109883.js.map +1 -0
- mito_ai-0.1.54.data/data/share/jupyter/labextensions/mito_ai/static/style_index_js.5876024bb17dbd6a3ee6.js → mito_ai-0.1.56.data/data/share/jupyter/labextensions/mito_ai/static/style_index_js.f5d476ac514294615881.js +15 -7
- mito_ai-0.1.56.data/data/share/jupyter/labextensions/mito_ai/static/style_index_js.f5d476ac514294615881.js.map +1 -0
- mito_ai-0.1.56.data/data/share/jupyter/labextensions/mito_ai/themes/mito_ai/index.css +708 -0
- mito_ai-0.1.56.data/data/share/jupyter/labextensions/mito_ai/themes/mito_ai/index.js +0 -0
- {mito_ai-0.1.54.dist-info → mito_ai-0.1.56.dist-info}/METADATA +5 -1
- {mito_ai-0.1.54.dist-info → mito_ai-0.1.56.dist-info}/RECORD +69 -51
- mito_ai/completions/prompt_builders/utils.py +0 -84
- mito_ai-0.1.54.data/data/share/jupyter/labextensions/mito_ai/static/lib_index_js.31462f8f6a76b1cefbeb.js.map +0 -1
- mito_ai-0.1.54.data/data/share/jupyter/labextensions/mito_ai/static/remoteEntry.3f3c98eaba66bf084c66.js.map +0 -1
- mito_ai-0.1.54.data/data/share/jupyter/labextensions/mito_ai/static/style_index_js.5876024bb17dbd6a3ee6.js.map +0 -1
- {mito_ai-0.1.54.data → mito_ai-0.1.56.data}/data/etc/jupyter/jupyter_server_config.d/mito_ai.json +0 -0
- {mito_ai-0.1.54.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/schemas/mito_ai/toolbar-buttons.json +0 -0
- {mito_ai-0.1.54.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/node_modules_process_browser_js.4b128e94d31a81ebd209.js +0 -0
- {mito_ai-0.1.54.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/node_modules_process_browser_js.4b128e94d31a81ebd209.js.map +0 -0
- {mito_ai-0.1.54.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/style.js +0 -0
- {mito_ai-0.1.54.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
- {mito_ai-0.1.54.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
- {mito_ai-0.1.54.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
- {mito_ai-0.1.54.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
- {mito_ai-0.1.54.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
- {mito_ai-0.1.54.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
- {mito_ai-0.1.54.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
- {mito_ai-0.1.54.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
- {mito_ai-0.1.54.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
- {mito_ai-0.1.54.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
- {mito_ai-0.1.54.data → mito_ai-0.1.56.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_semver_index_js.3f6754ac5116d47de76b.js +0 -0
- {mito_ai-0.1.54.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
- {mito_ai-0.1.54.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
- {mito_ai-0.1.54.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
- {mito_ai-0.1.54.dist-info → mito_ai-0.1.56.dist-info}/WHEEL +0 -0
- {mito_ai-0.1.54.dist-info → mito_ai-0.1.56.dist-info}/entry_points.txt +0 -0
- {mito_ai-0.1.54.dist-info → mito_ai-0.1.56.dist-info}/licenses/LICENSE +0 -0
mito_ai/_version.py
CHANGED
mito_ai/anthropic_client.py
CHANGED
|
@@ -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.
|
|
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
|
|
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) -
|
|
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):
|
mito_ai/completions/models.py
CHANGED
|
@@ -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.
|
|
6
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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.
|
|
7
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
<Input>
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
file_name: sales.csv
|
|
72
|
-
|
|
73
|
-
Jupyter Notebook:
|
|
74
|
-
[
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
|
109
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
114
|
+
</ Input>
|
|
121
115
|
|
|
122
|
-
|
|
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
|
-
|
|
126
|
-
|
|
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
|
-
|
|
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
|
-
|
|
124
|
+
</ Your Thinking >
|
|
131
125
|
|
|
126
|
+
<Output>
|
|
132
127
|
|
|
133
|
-
{{
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
156
|
-
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
"""
|
|
144
|
+
prompt = Prompt(sections)
|
|
145
|
+
return str(prompt)
|