-
Notifications
You must be signed in to change notification settings - Fork 13
feat(mistralai_engine): migrate to mistralai module, add support for OCR and Document Understanding #584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(mistralai_engine): migrate to mistralai module, add support for OCR and Document Understanding #584
Changes from 15 commits
61e56f1
1dd3853
9cd2509
4c2c24d
22f4ead
20b4f77
1aedc46
2e7e5cb
420bf35
75b3aeb
90392e3
5a8411f
fcdbcfd
3bc4ec4
9793983
c1b7a48
fd02821
b2d45e3
6cd5a27
83e0e29
eda9d12
c6bd7be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| import re | ||
| import threading | ||
| import time | ||
| from multiprocessing import Process | ||
| from typing import TYPE_CHECKING, Any, Optional | ||
|
|
||
| import wx | ||
|
|
@@ -51,6 +52,7 @@ | |
|
|
||
| from .base_conversation import BaseConversation | ||
| from .history_msg_text_ctrl import HistoryMsgTextCtrl | ||
| from .ocr_handler import OCRHandler | ||
| from .read_only_message_dialog import ReadOnlyMessageDialog | ||
|
|
||
| if TYPE_CHECKING: | ||
|
|
@@ -62,6 +64,8 @@ | |
| log = logging.getLogger(__name__) | ||
| accessible_output = get_accessible_output() | ||
|
|
||
| CHECK_TASK_DELAY = 100 # ms | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Expose CHECK_TASK_DELAY configurability Having a 100ms delay for checking task progress is fine for most scenarios. Consider making this a configurable constant for easier tuning if needed. |
||
|
|
||
|
|
||
| class ConversationTab(wx.Panel, BaseConversation): | ||
| """A tab panel that manages a single conversation with an AI assistant. | ||
|
|
@@ -164,7 +168,9 @@ def __init__( | |
| self.last_time = 0 | ||
| self.recording_thread: Optional[RecordingThread] = None | ||
| self.task = None | ||
| self.process: Optional[Process] = None | ||
| self._stop_completion = False | ||
| self.ocr_handler = OCRHandler(self) | ||
|
Comment on lines
+171
to
+173
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix indentation: use tabs instead of spaces Multiple lines have incorrect indentation using spaces instead of tabs. Fix all indentation issues: - self.process: Optional[Process] = None
+ self.process: Optional[Process] = None
- self._stop_completion = False
+ self._stop_completion = False
- self.ocr_handler = OCRHandler(self)
+ self.ocr_handler = OCRHandler(self)
- self.ocr_button = self.ocr_handler.create_ocr_widget(self)
+ self.ocr_button = self.ocr_handler.create_ocr_widget(self)
- sizer.Add(self.ocr_button, proportion=0, flag=wx.EXPAND)
+ sizer.Add(self.ocr_button, proportion=0, flag=wx.EXPAND)
- self.ocr_button.Enable(
- ProviderCapability.OCR in account.provider.engine_cls.capabilities
- )
+ self.ocr_button.Enable(
+ ProviderCapability.OCR in account.provider.engine_cls.capabilities
+ )
- self.ocr_button.Hide()
+ self.ocr_button.Hide()
- self.ocr_button.Show()
+ self.ocr_button.Show()
- def check_attachments_valid(self) -> bool:
- """Check if all attachments are valid and supported by the current provider.
+def check_attachments_valid(self) -> bool:
+ """Check if all attachments are valid and supported by the current provider.
- if not self.check_attachments_valid():
+ if not self.check_attachments_valid():Also applies to: 261-262, 377-379, 724-729, 1155-1156, 1189-1189 🧰 Tools🪛 Pylint (3.3.7)[warning] 171-171: Bad indentation. Found 2 spaces, expected 8 (W0311) [warning] 172-172: Bad indentation. Found 2 spaces, expected 8 (W0311) [warning] 173-173: Bad indentation. Found 2 spaces, expected 8 (W0311) 🤖 Prompt for AI Agents |
||
| self.init_ui() | ||
| self.init_data(profile) | ||
| self.adjust_advanced_mode_setting() | ||
|
|
@@ -251,6 +257,10 @@ def init_ui(self): | |
| self.attachments_list.SetColumnWidth(1, 100) | ||
| self.attachments_list.SetColumnWidth(2, 500) | ||
| sizer.Add(self.attachments_list, proportion=0, flag=wx.ALL | wx.EXPAND) | ||
|
|
||
| self.ocr_button = self.ocr_handler.create_ocr_widget(self) | ||
| sizer.Add(self.ocr_button, proportion=0, flag=wx.EXPAND) | ||
|
|
||
| label = self.create_model_widget() | ||
| sizer.Add(label, proportion=0, flag=wx.EXPAND) | ||
| sizer.Add(self.model_list, proportion=0, flag=wx.ALL | wx.EXPAND) | ||
|
|
@@ -364,6 +374,9 @@ def on_account_change(self, event: wx.CommandEvent | None): | |
| self.toggle_record_btn.Enable( | ||
| ProviderCapability.STT in account.provider.engine_cls.capabilities | ||
| ) | ||
| self.ocr_button.Enable( | ||
| ProviderCapability.OCR in account.provider.engine_cls.capabilities | ||
| ) | ||
| self.web_search_mode.Enable( | ||
| ProviderCapability.WEB_SEARCH | ||
| in account.provider.engine_cls.capabilities | ||
|
|
@@ -708,10 +721,12 @@ def refresh_attachments_list(self): | |
| if not self.attachment_files: | ||
| self.attachments_list_label.Hide() | ||
| self.attachments_list.Hide() | ||
| self.ocr_button.Hide() | ||
| self.Layout() | ||
| return | ||
| self.attachments_list_label.Show() | ||
| self.attachments_list.Show() | ||
| self.ocr_button.Show() | ||
|
Comment on lines
+724
to
+729
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Conditional visibility for OCR button Hiding the OCR button when no attachments exist can prevent user confusion. However, if a user wants to attach later without re-showing the button, re-check logic carefully. |
||
| for attachment in self.attachment_files: | ||
| self.attachments_list.Append(attachment.get_display_info()) | ||
| last_index = len(self.attachment_files) - 1 | ||
|
|
@@ -1138,6 +1153,11 @@ def get_completion_args(self) -> dict[str, Any] | None: | |
| } | ||
|
|
||
| def _check_attachments_valid(self) -> bool: | ||
| """Check if all attachments are valid and supported by the current provider. | ||
|
|
||
| Returns: | ||
| True if all attachments are valid, False otherwise | ||
| """ | ||
| supported_attachment_formats = ( | ||
| self.current_engine.supported_attachment_formats | ||
| ) | ||
|
|
@@ -1158,7 +1178,6 @@ def _check_attachments_valid(self) -> bool: | |
| invalid_found = True | ||
| return not invalid_found | ||
|
|
||
| @ensure_no_task_running | ||
| def on_submit(self, event: wx.CommandEvent): | ||
| """Handle the submission of a new message block for completion. | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix relative import beyond top-level package
The relative import is causing an error. Change to absolute import:
📝 Committable suggestion
🧰 Tools
🪛 Pylint (3.3.7)
[error] 55-55: Attempted relative import beyond top-level package
(E0402)
🤖 Prompt for AI Agents