-
Notifications
You must be signed in to change notification settings - Fork 0
Handle missing FastAPI dependencies gracefully #6
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
base: 0.0.0
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR adds robust dependency handling for the FastAPI web server, enabling graceful degradation when optional web dependencies are missing. The changes ensure users receive clear installation guidance instead of cryptic stack traces when trying to run the web interface without the required packages.
- Adds import guards and fallback implementations for FastAPI and Pydantic dependencies
- Creates an ASGI placeholder that provides clear error messages when FastAPI is unavailable
- Documents the optional web dependencies and server launch instructions in the README
Reviewed Changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| app/web/static/index.html | Complete new web interface implementation with chat functionality |
| app/web/server.py | FastAPI server with dependency guards and graceful error handling |
| app/logger.py | Enhanced logger with optional loguru dependency handling |
| README.md | Added web interface documentation with dependency installation instructions |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| raise RuntimeError( | ||
| "FastAPI is not installed. Install dependencies with 'pip install fastapi " | ||
| "uvicorn' or via requirements.txt before running the web server." | ||
| ) |
Copilot
AI
Oct 20, 2025
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.
The ASGI placeholder function should properly handle the ASGI protocol by sending an HTTP response instead of raising an exception. The current implementation will cause the ASGI server to crash rather than gracefully informing the user.
| raise RuntimeError( | |
| "FastAPI is not installed. Install dependencies with 'pip install fastapi " | |
| "uvicorn' or via requirements.txt before running the web server." | |
| ) | |
| if scope["type"] == "http": | |
| content = ( | |
| b"FastAPI is not installed. Install dependencies with 'pip install fastapi uvicorn' " | |
| b"or via requirements.txt before running the web server." | |
| ) | |
| await send( | |
| { | |
| "type": "http.response.start", | |
| "status": 503, | |
| "headers": [ | |
| [b"content-type", b"text/plain; charset=utf-8"], | |
| [b"content-length", str(len(content)).encode("ascii")], | |
| ], | |
| } | |
| ) | |
| await send( | |
| { | |
| "type": "http.response.body", | |
| "body": content, | |
| } | |
| ) | |
| else: | |
| # For non-HTTP scopes, just close the connection if possible | |
| pass |
| ) | ||
| args = parser.parse_args(argv) | ||
|
|
||
| import uvicorn |
Copilot
AI
Oct 20, 2025
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.
The uvicorn import should be wrapped in a try-except block to handle cases where uvicorn is not installed, providing a clear error message similar to the FastAPI handling.
| import uvicorn | |
| try: | |
| import uvicorn | |
| except ModuleNotFoundError as exc: | |
| raise SystemExit( | |
| "Uvicorn is required to run the OpenManus web server. Install it with " | |
| "'pip install uvicorn' or via 'pip install -r requirements.txt'." | |
| ) from exc |
| def define_log_level( | ||
| print_level: str = "INFO", logfile_level: str = "DEBUG", name: str | None = None |
Copilot
AI
Oct 20, 2025
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.
[nitpick] The function signature uses modern Python union syntax (str | None) but should be consistent with the typing imports. Consider using Optional[str] from typing module for broader compatibility.
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_68dc4c8a38088324b4608255df8522b9