mito-ai 0.1.45__py3-none-any.whl → 0.1.46__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/__init__.py +10 -1
  2. mito_ai/_version.py +1 -1
  3. mito_ai/anthropic_client.py +90 -5
  4. mito_ai/chat_history/handlers.py +63 -0
  5. mito_ai/chat_history/urls.py +32 -0
  6. mito_ai/completions/handlers.py +18 -20
  7. mito_ai/constants.py +3 -0
  8. mito_ai/streamlit_conversion/agent_utils.py +148 -30
  9. mito_ai/streamlit_conversion/prompts/prompt_constants.py +147 -24
  10. mito_ai/streamlit_conversion/prompts/streamlit_app_creation_prompt.py +2 -1
  11. mito_ai/streamlit_conversion/prompts/streamlit_error_correction_prompt.py +2 -2
  12. mito_ai/streamlit_conversion/prompts/streamlit_finish_todo_prompt.py +4 -3
  13. mito_ai/streamlit_conversion/prompts/update_existing_app_prompt.py +50 -0
  14. mito_ai/streamlit_conversion/streamlit_agent_handler.py +101 -107
  15. mito_ai/streamlit_conversion/streamlit_system_prompt.py +1 -0
  16. mito_ai/streamlit_conversion/streamlit_utils.py +13 -10
  17. mito_ai/streamlit_conversion/validate_streamlit_app.py +77 -82
  18. mito_ai/streamlit_preview/handlers.py +3 -4
  19. mito_ai/streamlit_preview/utils.py +11 -7
  20. mito_ai/tests/chat_history/test_chat_history.py +211 -0
  21. mito_ai/tests/message_history/test_message_history_utils.py +43 -19
  22. mito_ai/tests/providers/test_anthropic_client.py +178 -6
  23. mito_ai/tests/streamlit_conversion/test_apply_patch_to_text.py +368 -0
  24. mito_ai/tests/streamlit_conversion/test_fix_diff_headers.py +533 -0
  25. mito_ai/tests/streamlit_conversion/test_streamlit_agent_handler.py +71 -74
  26. mito_ai/tests/streamlit_conversion/test_streamlit_utils.py +16 -16
  27. mito_ai/tests/streamlit_conversion/test_validate_streamlit_app.py +17 -14
  28. mito_ai/tests/streamlit_preview/test_streamlit_preview_handler.py +2 -2
  29. mito_ai/tests/user/__init__.py +2 -0
  30. mito_ai/tests/user/test_user.py +120 -0
  31. mito_ai/user/handlers.py +33 -0
  32. mito_ai/user/urls.py +21 -0
  33. mito_ai/utils/anthropic_utils.py +8 -6
  34. mito_ai/utils/message_history_utils.py +4 -3
  35. mito_ai/utils/telemetry_utils.py +7 -4
  36. {mito_ai-0.1.45.data → mito_ai-0.1.46.data}/data/share/jupyter/labextensions/mito_ai/build_log.json +1 -1
  37. {mito_ai-0.1.45.data → mito_ai-0.1.46.data}/data/share/jupyter/labextensions/mito_ai/package.json +2 -2
  38. {mito_ai-0.1.45.data → mito_ai-0.1.46.data}/data/share/jupyter/labextensions/mito_ai/schemas/mito_ai/package.json.orig +1 -1
  39. mito_ai-0.1.45.data/data/share/jupyter/labextensions/mito_ai/static/lib_index_js.0c3368195d954d2ed033.js → mito_ai-0.1.46.data/data/share/jupyter/labextensions/mito_ai/static/lib_index_js.20f12766ecd3d430568e.js +955 -173
  40. mito_ai-0.1.46.data/data/share/jupyter/labextensions/mito_ai/static/lib_index_js.20f12766ecd3d430568e.js.map +1 -0
  41. mito_ai-0.1.45.data/data/share/jupyter/labextensions/mito_ai/static/remoteEntry.684f82575fcc2e3b350c.js → mito_ai-0.1.46.data/data/share/jupyter/labextensions/mito_ai/static/remoteEntry.54126ab6511271265443.js +5 -5
  42. mito_ai-0.1.45.data/data/share/jupyter/labextensions/mito_ai/static/remoteEntry.684f82575fcc2e3b350c.js.map → mito_ai-0.1.46.data/data/share/jupyter/labextensions/mito_ai/static/remoteEntry.54126ab6511271265443.js.map +1 -1
  43. {mito_ai-0.1.45.dist-info → mito_ai-0.1.46.dist-info}/METADATA +1 -1
  44. {mito_ai-0.1.45.dist-info → mito_ai-0.1.46.dist-info}/RECORD +68 -58
  45. mito_ai-0.1.45.data/data/share/jupyter/labextensions/mito_ai/static/lib_index_js.0c3368195d954d2ed033.js.map +0 -1
  46. {mito_ai-0.1.45.data → mito_ai-0.1.46.data}/data/etc/jupyter/jupyter_server_config.d/mito_ai.json +0 -0
  47. {mito_ai-0.1.45.data → mito_ai-0.1.46.data}/data/share/jupyter/labextensions/mito_ai/schemas/mito_ai/toolbar-buttons.json +0 -0
  48. {mito_ai-0.1.45.data → mito_ai-0.1.46.data}/data/share/jupyter/labextensions/mito_ai/static/node_modules_process_browser_js.4b128e94d31a81ebd209.js +0 -0
  49. {mito_ai-0.1.45.data → mito_ai-0.1.46.data}/data/share/jupyter/labextensions/mito_ai/static/node_modules_process_browser_js.4b128e94d31a81ebd209.js.map +0 -0
  50. {mito_ai-0.1.45.data → mito_ai-0.1.46.data}/data/share/jupyter/labextensions/mito_ai/static/style.js +0 -0
  51. {mito_ai-0.1.45.data → mito_ai-0.1.46.data}/data/share/jupyter/labextensions/mito_ai/static/style_index_js.5876024bb17dbd6a3ee6.js +0 -0
  52. {mito_ai-0.1.45.data → mito_ai-0.1.46.data}/data/share/jupyter/labextensions/mito_ai/static/style_index_js.5876024bb17dbd6a3ee6.js.map +0 -0
  53. {mito_ai-0.1.45.data → mito_ai-0.1.46.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
  54. {mito_ai-0.1.45.data → mito_ai-0.1.46.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
  55. {mito_ai-0.1.45.data → mito_ai-0.1.46.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
  56. {mito_ai-0.1.45.data → mito_ai-0.1.46.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
  57. {mito_ai-0.1.45.data → mito_ai-0.1.46.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_dist_esm_index_mjs.6bac1a8c4cc93f15f6b7.js +0 -0
  58. {mito_ai-0.1.45.data → mito_ai-0.1.46.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_dist_esm_index_mjs.6bac1a8c4cc93f15f6b7.js.map +0 -0
  59. {mito_ai-0.1.45.data → mito_ai-0.1.46.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_ui-react_dist_esm_index_mjs.4fcecd65bef9e9847609.js +0 -0
  60. {mito_ai-0.1.45.data → mito_ai-0.1.46.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_ui-react_dist_esm_index_mjs.4fcecd65bef9e9847609.js.map +0 -0
  61. {mito_ai-0.1.45.data → mito_ai-0.1.46.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
  62. {mito_ai-0.1.45.data → mito_ai-0.1.46.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
  63. {mito_ai-0.1.45.data → mito_ai-0.1.46.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_semver_index_js.3f6754ac5116d47de76b.js +0 -0
  64. {mito_ai-0.1.45.data → mito_ai-0.1.46.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_semver_index_js.3f6754ac5116d47de76b.js.map +0 -0
  65. {mito_ai-0.1.45.data → mito_ai-0.1.46.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_vscode-diff_dist_index_js.ea55f1f9346638aafbcf.js +0 -0
  66. {mito_ai-0.1.45.data → mito_ai-0.1.46.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_vscode-diff_dist_index_js.ea55f1f9346638aafbcf.js.map +0 -0
  67. {mito_ai-0.1.45.dist-info → mito_ai-0.1.46.dist-info}/WHEEL +0 -0
  68. {mito_ai-0.1.45.dist-info → mito_ai-0.1.46.dist-info}/entry_points.txt +0 -0
  69. {mito_ai-0.1.45.dist-info → mito_ai-0.1.46.dist-info}/licenses/LICENSE +0 -0
@@ -3,7 +3,7 @@
3
3
 
4
4
  import anthropic
5
5
  from typing import Any, Dict, List, Optional, Union, AsyncGenerator, Tuple, Callable
6
- from anthropic.types import MessageParam, ToolUnionParam
6
+ from anthropic.types import MessageParam, TextBlockParam, ToolUnionParam
7
7
  from mito_ai.utils.mito_server_utils import get_response_from_mito_server, stream_response_from_mito_server
8
8
  from mito_ai.utils.provider_utils import does_message_require_fast_model
9
9
  from mito_ai.completions.models import AgentResponse, MessageType, ResponseFormatInfo, CompletionReply, CompletionStreamChunk
@@ -23,7 +23,7 @@ def _prepare_anthropic_request_data_and_headers(
23
23
  model: Union[str, None],
24
24
  max_tokens: int,
25
25
  temperature: float,
26
- system: Union[str, anthropic.Omit],
26
+ system: Union[str, List[TextBlockParam], anthropic.Omit],
27
27
  messages: List[MessageParam],
28
28
  message_type: MessageType,
29
29
  tools: Optional[List[ToolUnionParam]],
@@ -92,7 +92,7 @@ async def stream_anthropic_completion_from_mito_server(
92
92
  model: Union[str, None],
93
93
  max_tokens: int,
94
94
  temperature: float,
95
- system: Union[str, anthropic.Omit],
95
+ system: Union[str, List[TextBlockParam], anthropic.Omit],
96
96
  messages: List[MessageParam],
97
97
  stream: bool,
98
98
  message_type: MessageType,
@@ -102,6 +102,7 @@ async def stream_anthropic_completion_from_mito_server(
102
102
  data, headers = _prepare_anthropic_request_data_and_headers(
103
103
  model, max_tokens, temperature, system, messages, message_type, None, None, stream
104
104
  )
105
+
105
106
  # Use the unified streaming function
106
107
  # If the reply_fn and message_id are empty, this function still handles those requests. This is particularly needed for the streamlit dashboard functionality
107
108
  actual_reply_fn = reply_fn if reply_fn is not None else (lambda x: None)
@@ -119,19 +120,20 @@ async def stream_anthropic_completion_from_mito_server(
119
120
  provider_name="Claude",
120
121
  ):
121
122
  yield chunk
122
-
123
+
124
+
123
125
  def get_anthropic_completion_function_params(
124
126
  message_type: MessageType,
125
127
  model: str,
126
128
  messages: List[MessageParam],
127
129
  max_tokens: int,
128
- system: Union[str, anthropic.Omit],
130
+ system: Union[str, List[TextBlockParam], anthropic.Omit],
129
131
  temperature: float = 0.0,
130
132
  tools: Optional[List[ToolUnionParam]] = None,
131
133
  tool_choice: Optional[dict] = None,
132
134
  stream: Optional[bool] = None,
133
135
  response_format_info: Optional[ResponseFormatInfo] = None,
134
- ) -> Dict[str, Any]:
136
+ ) -> Dict[str, Any]:
135
137
  """
136
138
  Build the provider_data dict for Anthropic completions, mirroring the OpenAI approach.
137
139
  Only includes fields needed for the Anthropic API.
@@ -3,6 +3,7 @@
3
3
 
4
4
  import re
5
5
  from typing import List
6
+ from mito_ai.constants import MESSAGE_HISTORY_TRIM_THRESHOLD
6
7
  from openai.types.chat import ChatCompletionMessageParam
7
8
  from mito_ai.completions.prompt_builders.prompt_constants import (
8
9
  ACTIVE_CELL_ID_SECTION_HEADING,
@@ -43,18 +44,18 @@ def trim_sections_from_message_content(content: str) -> str:
43
44
  return content
44
45
 
45
46
 
46
- def trim_old_messages(messages: List[ChatCompletionMessageParam], keep_recent: int = 3) -> List[ChatCompletionMessageParam]:
47
+ def trim_old_messages(messages: List[ChatCompletionMessageParam]) -> List[ChatCompletionMessageParam]:
47
48
  """
48
49
  Trims metadata sections from messages that are older than the specified number of recent messages.
49
50
  We do this in order to reduce the token count of the messages, which helps us stay under the token limit for the LLM.
50
51
  """
51
- if len(messages) <= keep_recent:
52
+ if len(messages) <= MESSAGE_HISTORY_TRIM_THRESHOLD:
52
53
  return messages
53
54
 
54
55
  # Process all messages except the keep_recent most recent ones.
55
56
  # Only trim user messages, which is where this metadata lives.
56
57
  # We want to not edit the system messages, as they contain important information / examples.
57
- for i in range(len(messages) - keep_recent):
58
+ for i in range(len(messages) - MESSAGE_HISTORY_TRIM_THRESHOLD):
58
59
  content = messages[i].get("content")
59
60
 
60
61
  is_user_message = messages[i].get("role") == "user"
@@ -386,10 +386,13 @@ def log_mito_server_free_tier_limit_reached(key_type: Literal['mito_server_key',
386
386
  # Streamlit Conversion
387
387
  #################################
388
388
 
389
- def log_streamlit_app_creation_success(key_type: Literal['mito_server_key', 'user_key'], message_type: MessageType) -> None:
389
+ def log_streamlit_app_creation_success(key_type: Literal['mito_server_key', 'user_key'], message_type: MessageType, edit_prompt: str) -> None:
390
390
  log(
391
391
  "mito_ai_streamlit_app_creation_success",
392
- key_type=key_type
392
+ key_type=key_type,
393
+ params={
394
+ "edit_prompt": edit_prompt,
395
+ }
393
396
  )
394
397
 
395
398
  def log_streamlit_app_creation_retry(key_type: Literal['mito_server_key', 'user_key'], message_type: MessageType, error: str) -> None:
@@ -401,12 +404,12 @@ def log_streamlit_app_creation_retry(key_type: Literal['mito_server_key', 'user_
401
404
  key_type=key_type
402
405
  )
403
406
 
404
- def log_streamlit_app_creation_error(key_type: Literal['mito_server_key', 'user_key'], message_type: MessageType, error: str) -> None:
407
+ def log_streamlit_app_creation_error(key_type: Literal['mito_server_key', 'user_key'], message_type: MessageType, error: str, edit_prompt: str) -> None:
405
408
  log(
406
409
  "mito_ai_streamlit_app_creation_error",
407
410
  params={
408
411
  "error_message": error,
412
+ "edit_prompt": edit_prompt,
409
413
  },
410
414
  key_type=key_type
411
415
  )
412
-
@@ -712,7 +712,7 @@
712
712
  "semver": {},
713
713
  "vscode-diff": {},
714
714
  "mito_ai": {
715
- "version": "0.1.45",
715
+ "version": "0.1.46",
716
716
  "singleton": true,
717
717
  "import": "/home/runner/work/mito/mito/mito-ai/lib/index.js"
718
718
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mito_ai",
3
- "version": "0.1.45",
3
+ "version": "0.1.46",
4
4
  "description": "AI chat for JupyterLab",
5
5
  "keywords": [
6
6
  "jupyter",
@@ -140,7 +140,7 @@
140
140
  "outputDir": "mito_ai/labextension",
141
141
  "schemaDir": "schema",
142
142
  "_build": {
143
- "load": "static/remoteEntry.684f82575fcc2e3b350c.js",
143
+ "load": "static/remoteEntry.54126ab6511271265443.js",
144
144
  "extension": "./extension",
145
145
  "style": "./style"
146
146
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mito_ai",
3
- "version": "0.1.45",
3
+ "version": "0.1.46",
4
4
  "description": "AI chat for JupyterLab",
5
5
  "keywords": [
6
6
  "jupyter",