Generating Desktop Tools with LLMs: Requirement Decomposition and UI Responsiveness Practices
This article discusses how to generate a desktop utility using a large language model (LLM), focusing on requirement decomposition, code verification, and keeping the user interface responsive during long-running tasks. Using a video-to-audio converter as an example, it presents a three-category requirement breakdown, a four-layer validation approach, and a threaded model for background work with queue-based UI updates, along with practical code snippets and design notes for extension features.
1. Problem Background
Large language models can now generate complete small programs from natural language descriptions. For developers, the real difficulty is not “whether the code can be generated” but whether the generated result runs correctly, covers all requirements, and behaves reliably under abnormal conditions. Desktop tools are particularly challenging because they involve UI layout, file system access, external processes, and concurrent execution—any mistake in these areas will surface during actual use.
This article uses a typical requirement as an example: batch extract audio from common video files, support exporting to mainstream formats such as MP3 and WAV, provide a file list, format settings, a progress bar, a status bar, and error reporting, and keep the interface responsive during conversion. This type of requirement covers a wide range of concerns and is well suited for evaluating the quality of LLM-generated code.
2. Requirement Decomposition: Turning Descriptions into Verifiable Items
The more vague the prompt, the more the generated result relies on the model’s default assumptions. A better approach is to break the requirement into three categories: functional items, quality items, and boundary items.
Functional items describe “what to do,” for example:
- Allow importing a single file, multiple files, and an entire directory.
- Accept common video container formats as input.
- Support MP3 and WAV as output formats.
- Provide action buttons such as “Start Conversion” and “Exit.”
Quality items describe “how well it should be done,” for example:
- The interface must remain responsive to clicks and drags during conversion.
- The progress bar updates according to the actual completion ratio.
- Error messages are visible in the interface.
Boundary items describe “what to do when something goes wrong,” for example:
- The source file does not exist.
- The output directory has no write permission.
- A file with the same name already exists.
- The required conversion program is not installed.
Each item should be verifiable by a single action or observation. After the code is generated, you can check them one by one instead of relying on a vague impression that “it looks about right.”
3. Four-Layer Verification of Generated Code
Once you receive the code, do not conclude immediately after a simple run. It is recommended to check it in the following four layers.
3.1 Syntax and Static Checks
First, confirm that the code can be parsed by the interpreter without errors. Then use static analysis tools to look for undefined variables, unused imports, and obvious type issues. This step has the lowest cost and filters out most low-level mistakes.
3.2 Runtime Environment Detection
This type of tool usually depends on external programs or third-party libraries. A proper implementation checks for dependencies before starting the conversion and gives clear installation instructions, rather than failing at the first conversion attempt. Here is a simple detection function:
import shutildef check_dependency(name: str) -> bool:"""Check whether a command-line program can be found in the system PATH."""return shutil.which(name) is not None
3.3 Functional Item Verification
Go through each functional item from Section 2 by performing the corresponding action. Pay special attention to two points:
- When importing a directory, does the code truly recurse into subdirectories?
- Is format detection case-insensitive? For example, both
.MP4and.mp4should be recognized.
3.4 Abnormal Path Testing
Deliberately create failure conditions: delete the source file, set the output directory to read-only, or place a file with the same name in the output directory. A correct program should skip the failed item, record the failure reason, and continue processing the remaining files, rather than crashing or silently dropping tasks.
4. Keeping the UI Responsive: A Threaded Model for Long-Running Tasks
A graphical interface program relies on a main event loop to respond to user actions. If the conversion logic is written directly in the button callback, the main loop will be blocked, the window will become unresponsive during conversion, and the progress bar will not refresh. The solution is to run the long-running task in a background thread and communicate progress and results back to the UI thread through a queue.
This model has three core principles:
- The UI thread is responsible only for drawing and event handling; it does not perform file I/O or external process calls.
- The background thread communicates with the UI only through a queue; it does not directly modify UI controls.
- The UI thread reads the queue on a periodic timer and converts messages into progress updates or status notifications.
The following example code shows the background processing part. The converter program name is passed by the caller, and command arguments should be adjusted according to the actual tool being used. Arguments are passed as a list to avoid injection and escaping issues from string concatenation.
import osimport queueimport subprocessimport threadingmsg_queue = queue.Queue()def unique_path(path: str) -> str:"""If the target file already exists, append a number to avoid overwriting."""if not os.path.exists(path):return pathroot, ext = os.path.splitext(path)n = 1while os.path.exists(f"{root}_{n}{ext}"):n += 1return f"{root}_{n}{ext}"def convert_worker(sources, out_dir, audio_fmt, tool_name):total = len(sources)for idx, src in enumerate(sources, start=1):base = os.path.splitext(os.path.basename(src))[0]dst = unique_path(os.path.join(out_dir, f"{base}.{audio_fmt}"))cmd = [tool_name, src, dst] # Adjust arguments based on the actual convertertry:result = subprocess.run(cmd, capture_output=True, text=True)if result.returncode != 0:msg_queue.put(("error", f"{src}: {result.stderr.strip()[:200]}"))else:msg_queue.put(("ok", dst))except OSError as exc:msg_queue.put(("error", f"{src}: {exc}"))msg_queue.put(("progress", idx / total))msg_queue.put(("done", None))def start_conversion(sources, out_dir, audio_fmt, tool_name):worker = threading.Thread(target=convert_worker,args=(sources, out_dir, audio_fmt, tool_name),daemon=True,)worker.start()return worker
On the UI side, you only need a periodic timer that drains all messages from the queue every short interval and updates the progress bar, status bar, and error list accordingly. When a done message is received, restore the button state.
When exiting the program, you also need to handle tasks that are still running. A common approach is to set a cancel flag that the worker thread checks between files and exits early if set. If you prefer not to allow mid-process cancellation, wait for the thread to finish before exiting and give the user a clear message.
5. Design Considerations for Extension Features
Common extension features in requirements each have their own implementation caveats.
- Recursive directory scanning: Use a file system traversal function and filter by an extension whitelist. Normalize extensions to lowercase before comparison to avoid issues with uppercase versions such as
.MP4versus.mp4.
