Auto-activate Gatewayz top models on startup; add gatewayz API endpoints#4
Auto-activate Gatewayz top models on startup; add gatewayz API endpoints#4vdimarco wants to merge 2 commits into
Conversation
…tion - Disable OpenAI and Ollama APIs by default (config.py) - Add explicit env vars for Gatewayz-only mode in Dockerfile - Add /rankings and /rankings/top-models endpoints to fetch popular models - Auto-activate top 3 models from each provider (OpenAI, Anthropic, Google, xAI) on startup - Add frontend API functions for rankings - Add unit tests for extract_top_models_by_provider The rankings are synced on every startup to keep models current. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix PersistentConfig mutation by creating new dict before assignment - Add documentation for /ranking/apps endpoint verification - Improve logging for missing API keys and empty rankings - Make error messages more actionable for users Addresses PR comments: - backend/open_webui/main.py:606 - Fixed config mutation - backend/open_webui/routers/gatewayz.py:410 - Verified endpoint - backend/open_webui/main.py:569 - Added helpful logging 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Rate limit exceeded
⌛ 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. ✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
| api_key = ( | ||
| app.state.config.GATEWAYZ_API_KEYS[0] | ||
| if app.state.config.GATEWAYZ_API_KEYS | ||
| else "" | ||
| ) |
There was a problem hiding this comment.
Potential IndexError if GATEWAYZ_API_KEYS is an empty list
| api_key = ( | |
| app.state.config.GATEWAYZ_API_KEYS[0] | |
| if app.state.config.GATEWAYZ_API_KEYS | |
| else "" | |
| ) | |
| api_key = ( | |
| app.state.config.GATEWAYZ_API_KEYS[0] | |
| if app.state.config.GATEWAYZ_API_KEYS and len(app.state.config.GATEWAYZ_API_KEYS) > 0 | |
| else "" | |
| ) |
Prompt To Fix With AI
This is a comment left during a code review.
Path: backend/open_webui/main.py
Line: 576:580
Comment:
Potential `IndexError` if `GATEWAYZ_API_KEYS` is an empty list
```suggestion
api_key = (
app.state.config.GATEWAYZ_API_KEYS[0]
if app.state.config.GATEWAYZ_API_KEYS and len(app.state.config.GATEWAYZ_API_KEYS) > 0
else ""
)
```
How can I resolve this? If you propose a fix, please make it concise.
Summary
Changes
Backend
Frontend / API (TypeScript)
Tests
Deployment / Config
🌿 Generated by Terry
ℹ️ Tag @terragon-labs to ask questions and address PR feedback
📎 Task: https://terragon-www-production.up.railway.app/task/b5e46d51-e57f-4605-8f30-45c66b248600
Greptile Overview
Greptile Summary
This PR implements auto-activation of top-ranked Gatewayz models on application startup and exposes ranking API endpoints for frontend consumption.
Key Changes
ENABLE_GATEWAYZ_APIis true, the app automatically fetches rankings from Gatewayz API and activates the top 3 models from each of 4 providers (OpenAI, Anthropic, Google, xAI)/rankingsand/rankings/top-modelsendpoints expose model rankings to authenticated usersArchitecture
The implementation adds a startup hook that queries the Gatewayz
/ranking/appsendpoint, extracts top models using flexible parsing (handles multiple data formats, provider field variations, and model ID inference), and persists the configuration toGATEWAYZ_API_CONFIGS. The frontend gains TypeScript API functions to fetch these rankings.Issues Found
GATEWAYZ_API_KEYS[0]access inbackend/open_webui/main.py:576-580doesn't check list length, only truthiness, which can fail if the list is emptyConfidence Score: 4/5
Important Files Changed
activate_top_gatewayz_modelsfunction with error handling/rankingsand/rankings/top-modelsendpoints, plus helper functions for fetching and extracting top modelsENABLE_OLLAMA_APIandENABLE_OPENAI_APIfrom True to FalseSequence Diagram
sequenceDiagram participant App as FastAPI App participant Startup as Lifespan Startup participant ActFunc as activate_top_gatewayz_models participant FetchFunc as fetch_rankings_from_gatewayz participant ExtractFunc as extract_top_models_by_provider participant Config as GATEWAYZ_API_CONFIGS participant GatewayAPI as Gatewayz API App->>Startup: Start application Startup->>Startup: Check ENABLE_GATEWAYZ_API alt ENABLE_GATEWAYZ_API is true Startup->>ActFunc: Call function ActFunc->>ActFunc: Check GATEWAYZ_API_BASE_URLS exists alt URLs configured ActFunc->>ActFunc: Get first URL and API key ActFunc->>FetchFunc: Fetch rankings FetchFunc->>FetchFunc: Construct rankings URL FetchFunc->>GatewayAPI: GET /ranking/apps with Bearer token GatewayAPI-->>FetchFunc: Return rankings data or error FetchFunc-->>ActFunc: Return rankings list or empty array alt Rankings received ActFunc->>ExtractFunc: Extract top models by provider ExtractFunc->>ExtractFunc: Parse rankings data ExtractFunc->>ExtractFunc: Group models by provider ExtractFunc->>ExtractFunc: Select top 3 per provider ExtractFunc-->>ActFunc: Return list of top model IDs alt Top models found ActFunc->>Config: Update config index 0 ActFunc->>Config: Set enable=true, model_ids=top_models Config-->>ActFunc: Configuration persisted ActFunc->>ActFunc: Log success else No top models ActFunc->>ActFunc: Log warning end else No rankings ActFunc->>ActFunc: Log warning end else No URLs configured ActFunc->>ActFunc: Log info message end end Startup->>App: Continue startup process