From f17b62737ac1e9e758e5a0abcf273f3b2d9aa5bf Mon Sep 17 00:00:00 2001 From: Folzo Date: Sat, 11 Apr 2026 02:09:09 +0200 Subject: [PATCH] fix(effi-ocr): improve file search and show available files on error --- effi-ocr-legacy/TOOL-OPENWEBUI.md | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/effi-ocr-legacy/TOOL-OPENWEBUI.md b/effi-ocr-legacy/TOOL-OPENWEBUI.md index 4738d1a..ad1213a 100644 --- a/effi-ocr-legacy/TOOL-OPENWEBUI.md +++ b/effi-ocr-legacy/TOOL-OPENWEBUI.md @@ -39,7 +39,8 @@ class Tools: file_path = self._find_file(image_path) if not file_path: - return "[ERROR] File not found: " + image_path + ". Use list_recent_files() to see available files." + available = self._list_files() + return "[ERROR] File not found: " + image_path + "\n\nAvailable files:\n" + available with open(file_path, 'rb') as f: files = {'file': (os.path.basename(file_path), f)} @@ -103,6 +104,20 @@ class Tools: except Exception as e: return "[ERROR] " + str(e) + def _list_files(self): + try: + files = [] + for directory in [self.uploads_dir, self.host_uploads_dir]: + if os.path.exists(directory): + files.extend(glob.glob(os.path.join(directory, "*"))) + files = [f for f in files if os.path.isfile(f)] + if not files: + return "No files found" + files.sort(key=os.path.getmtime, reverse=True) + return "\n".join([os.path.basename(f) for f in files[:10]]) + except: + return "Cannot list files" + def _find_file(self, filename): filename = filename.strip().strip('"').strip("'") @@ -119,12 +134,20 @@ class Tools: search_dirs = [d for d in [self.uploads_dir, self.host_uploads_dir] if os.path.exists(d)] + if not search_dirs: + return None + for directory in search_dirs: all_files = glob.glob(os.path.join(directory, "*")) for f in all_files: - basename = os.path.basename(f) - if basename.startswith(filename) or filename in basename: + basename = os.path.basename(f).lower() + search_name = filename.lower() + if search_name in basename: return f + parts = search_name.replace('.jpeg', '').replace('.jpg', '').replace('.png', '').split() + for part in parts: + if len(part) > 3 and part in basename: + return f return None