feat(py): web GUI for Model Performance Tool#4455
Conversation
Summary of ChangesHello @MengqinShen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Model Performance Tool by integrating a new web-based graphical user interface. This GUI, built with FastAPI for the backend and standard web technologies for the frontend, allows users to interactively select models, define test scenarios, adjust configuration parameters, and visualize test results. The underlying Python framework dynamically discovers available models and generates comprehensive test variations, streamlining the process of evaluating model performance across different settings. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces an excellent new model performance testing tool, complete with both a command-line interface and a web-based GUI. The overall structure is well-designed, with clear separation of concerns between the test runner, the isolated test executor, and the FastAPI backend. My review focuses on improving the robustness and correctness of the implementation. I've identified a critical issue in the asynchronous handling within the FastAPI server, a high-severity bug related to serving static files, and a medium-severity improvement for error handling consistency. Addressing these points will make the new tool more reliable and easier to debug.
| result = await asyncio.to_thread( | ||
| lambda: asyncio.run(run_wrapper( | ||
| request.model, | ||
| request.config, | ||
| request.user_prompt, | ||
| request.system_prompt, | ||
| script_path | ||
| )) | ||
| ) |
There was a problem hiding this comment.
The use of asyncio.run inside asyncio.to_thread is an anti-pattern and unnecessarily complex. Since run_model_test is a synchronous, blocking function, you can pass it directly to asyncio.to_thread along with its arguments. This simplifies the code, improves correctness, and removes the need for the run_wrapper function.
| result = await asyncio.to_thread( | |
| lambda: asyncio.run(run_wrapper( | |
| request.model, | |
| request.config, | |
| request.user_prompt, | |
| request.system_prompt, | |
| script_path | |
| )) | |
| ) | |
| # Run test in thread pool to not block async loop (subprocess call inside) | |
| result = await asyncio.to_thread( | |
| run_model_test, | |
| request.model, | |
| request.config, | |
| request.user_prompt, | |
| request.system_prompt, | |
| script_path, | |
| ) |
py/samples/sample-test/server.py
Outdated
|
|
||
|
|
||
| # Mount static files (Frontend) | ||
| app.mount("/", StaticFiles(directory="samples/sample-test/static", html=True), name="static") |
There was a problem hiding this comment.
The path directory="samples/sample-test/static" for StaticFiles is not robust and will likely fail depending on the current working directory from which the server is launched. To ensure the path is always correct, it should be constructed relative to the server.py file's location.
| app.mount("/", StaticFiles(directory="samples/sample-test/static", html=True), name="static") | |
| app.mount("/", StaticFiles(directory=Path(__file__).parent / "static", html=True), name="static") |
| plugins = [] | ||
| # Initialize with GoogleAI plugin | ||
| try: | ||
| plugins.append(GoogleAI()) | ||
| except Exception as e: | ||
| print(f"Warning: Failed to initialize GoogleAI plugin: {e}") | ||
|
|
||
| # Initialize with VertexAI plugin | ||
| try: | ||
| plugins.append(VertexAI()) | ||
| except Exception as e: | ||
| # print(f"Warning: Failed to initialize VertexAI plugin: {e}") | ||
| pass |
There was a problem hiding this comment.
The error handling for plugin initialization is inconsistent and could hide issues. The GoogleAI plugin failure prints a warning, while the VertexAI failure is silently ignored with pass. This can make debugging difficult if a plugin fails to load due to configuration errors (e.g., missing API keys or permissions). It's better to consistently log or print a warning for any plugin initialization failure.
| plugins = [] | |
| # Initialize with GoogleAI plugin | |
| try: | |
| plugins.append(GoogleAI()) | |
| except Exception as e: | |
| print(f"Warning: Failed to initialize GoogleAI plugin: {e}") | |
| # Initialize with VertexAI plugin | |
| try: | |
| plugins.append(VertexAI()) | |
| except Exception as e: | |
| # print(f"Warning: Failed to initialize VertexAI plugin: {e}") | |
| pass | |
| plugins = [] | |
| # Initialize with GoogleAI plugin | |
| try: | |
| plugins.append(GoogleAI()) | |
| except Exception as e: | |
| print(f"Warning: Failed to initialize GoogleAI plugin: {e}") | |
| # Initialize with VertexAI plugin | |
| try: | |
| plugins.append(VertexAI()) | |
| except Exception as e: | |
| print(f"Warning: Failed to initialize VertexAI plugin: {e}") |
| # Wrapper to run async run_model_test inside the thread | ||
| async def run_wrapper(model, config, user_prompt, system_prompt, script_path): | ||
| # run_model_test in test_model_performance is synchronous (uses subprocess.run) | ||
| # We need to call it directly. Wait, run_model_test in test_model_performance IS synchronous wrapper around subprocess. | ||
| # So we don't need asyncio.run inside the lambda unless run_model_test was async. | ||
| # Checking test_model_performance.py... run_model_test is synchronous. | ||
|
|
||
| return run_model_test( | ||
| model, | ||
| config, | ||
| user_prompt, | ||
| system_prompt, | ||
| script_path | ||
| ) |
There was a problem hiding this comment.
Following the recommended change to the /api/run endpoint, this run_wrapper function and its surrounding comments become redundant. Removing it will simplify the codebase. The comments here also highlight some confusion about the synchronous nature of the underlying test function, which the refactoring clarifies.
Uh oh!
There was an error while loading. Please reload this page.