-
Notifications
You must be signed in to change notification settings - Fork 191
feat: Make OpenAPI spec usable by custom GPTs #462
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
Conversation
🦋 Changeset detectedLatest commit: d609e16 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Warning Rate limit exceeded@marcusschiesser has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 5 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (3)
WalkthroughA new patch titled "create-llama" has been introduced to enhance the usability of the OpenAPI specification for custom GPT implementations. This change streamlines the integration process for developers creating tailored GPT models. Additionally, modifications have been made to the FastAPI application, including updates to the router's metadata for API endpoints, the addition of the Changes
Possibly related PRs
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (2)
templates/types/streaming/fastapi/pyproject.toml (1)
24-24: LGTM! Consider usingtomlifor newer projects.The addition of the
tomlpackage is appropriate for readingfly.tomlconfiguration files. While this package works well, for newer projects you might want to consider usingtomliwhich is actively maintained and follows PEP 517/518 specifications.Alternative implementation:
-toml = "^0.10.2" +tomli = "^2.0.1"templates/types/streaming/fastapi/app/api/routers/query.py (1)
Line range hint
19-30: LGTM! The changes align with making the API more discoverable.The addition of OpenAPI metadata improves the API's usability for custom GPTs by providing clear documentation about the endpoint's purpose and behavior.
Consider adding these OpenAPI enhancements to make the API even more usable:
- Response schema documentation
- Example queries
- Error responses documentation
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (4)
.changeset/famous-snails-destroy.md(1 hunks)templates/types/streaming/fastapi/app/api/routers/query.py(1 hunks)templates/types/streaming/fastapi/main.py(2 hunks)templates/types/streaming/fastapi/pyproject.toml(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- .changeset/famous-snails-destroy.md
🧰 Additional context used
📓 Path-based instructions (3)
templates/types/streaming/fastapi/pyproject.toml (1)
Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.
templates/types/streaming/fastapi/main.py (1)
Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.
templates/types/streaming/fastapi/app/api/routers/query.py (1)
Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.
🔇 Additional comments (2)
templates/types/streaming/fastapi/main.py (2)
4-4: LGTM: Import statement is correctly placed.
The toml import is appropriately positioned with other standard library imports.
36-36: LGTM: FastAPI initialization properly configures OpenAPI servers.
The initialization correctly sets up the servers list for OpenAPI specification, which will help custom GPTs locate the API endpoint.
Let's verify the OpenAPI spec generation:
✅ Verification successful
FastAPI initialization correctly configures OpenAPI servers with proper dynamic URL handling
The verification confirms that:
- The FastAPI app is properly initialized with a dynamic
serverslist that's populated based on the fly.toml configuration - When fly.toml exists, it correctly sets the server URL to
https://{app_name}.fly.dev - FastAPI's default OpenAPI/Swagger endpoints are automatically enabled (no explicit configuration needed to disable them)
- The server URL configuration will be properly exposed in the OpenAPI specification
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that the OpenAPI spec includes the server URL when fly.toml exists
# Create a test fly.toml
echo 'app = "test-app"' > fly.toml
# Search for FastAPI routes that serve OpenAPI spec
rg -l 'openapi.json|swagger.json'
# Clean up
rm fly.toml
Length of output: 75
Script:
#!/bin/bash
# Let's verify the FastAPI initialization and OpenAPI spec configuration from multiple angles
# 1. Check FastAPI app initialization and server configuration
rg -A 5 "FastAPI\(.*servers"
# 2. Look for OpenAPI/Swagger related configurations
rg -A 5 "openapi_|swagger_|docs_url"
# 3. Check if there are any route handlers for OpenAPI/Swagger docs
ast-grep --pattern 'app.$_("/docs" | "/openapi.json" | "/swagger", $$$)'
# 4. Examine the servers variable construction
rg -B 5 "servers\s*="
Length of output: 10840
| servers = [] | ||
| # Add the fly.dev URL to the OpenAPI spec | ||
| if os.path.exists("fly.toml"): | ||
| try: | ||
| with open("fly.toml") as f: | ||
| fly_config = toml.load(f) | ||
| app_name = fly_config["app"] | ||
| servers = [{"url": f"https://{app_name}.fly.dev"}] | ||
| except Exception as e: | ||
| logger.warning(f"Failed to read fly.toml: {e}") |
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.
🛠️ Refactor suggestion
Enhance error handling and configuration robustness.
While the implementation works, consider these improvements for better reliability:
- Use absolute path for fly.toml
- Add type checking for the configuration
- Make the protocol configurable
Here's a suggested improvement:
servers = []
-if os.path.exists("fly.toml"):
+config_path = os.path.join(os.path.dirname(__file__), "fly.toml")
+if os.path.exists(config_path):
try:
- with open("fly.toml") as f:
+ with open(config_path) as f:
fly_config = toml.load(f)
- app_name = fly_config["app"]
- servers = [{"url": f"https://{app_name}.fly.dev"}]
+ if not isinstance(fly_config, dict) or "app" not in fly_config:
+ raise ValueError("Invalid fly.toml: missing 'app' field")
+ app_name = str(fly_config["app"])
+ protocol = os.getenv("API_PROTOCOL", "https")
+ servers = [{"url": f"{protocol}://{app_name}.fly.dev"}]
- except Exception as e:
+ except (IOError, toml.TomlDecodeError, ValueError) as e:
logger.warning(f"Failed to read fly.toml: {e}")📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| servers = [] | |
| # Add the fly.dev URL to the OpenAPI spec | |
| if os.path.exists("fly.toml"): | |
| try: | |
| with open("fly.toml") as f: | |
| fly_config = toml.load(f) | |
| app_name = fly_config["app"] | |
| servers = [{"url": f"https://{app_name}.fly.dev"}] | |
| except Exception as e: | |
| logger.warning(f"Failed to read fly.toml: {e}") | |
| servers = [] | |
| config_path = os.path.join(os.path.dirname(__file__), "fly.toml") | |
| if os.path.exists(config_path): | |
| try: | |
| with open(config_path) as f: | |
| fly_config = toml.load(f) | |
| if not isinstance(fly_config, dict) or "app" not in fly_config: | |
| raise ValueError("Invalid fly.toml: missing 'app' field") | |
| app_name = str(fly_config["app"]) | |
| protocol = os.getenv("API_PROTOCOL", "https") | |
| servers = [{"url": f"{protocol}://{app_name}.fly.dev"}] | |
| except (IOError, toml.TomlDecodeError, ValueError) as e: | |
| logger.warning(f"Failed to read fly.toml: {e}") |
a73a49b to
a0d56bc
Compare
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Summary by CodeRabbit
New Features
fly.tomlfile.Improvements
query_requestendpoint with a summary and description.Dependencies
tomlpackage as a new dependency in the project configuration.