Added Artemis AI changes - #15
Open
grafail wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This update introduces several improvements and refactorings across the API, monitoring, and routing components. The changes focus on performance, maintainability, and robustness, especially in rate limiting, model routing, and metrics collection.
Key Changes by Area
1. API Handlers (
pkg/api/handlers.go)Rate Limiter Improvements:
Switched to
sync.RWMutexfor better concurrency. Added expiry and cleanup for unused client limiters to prevent memory leaks. Improved logic for creating and cleaning up per-client rate limiters.Validation & Security:
Centralized valid model and task type definitions for faster lookups. Added a
setCommonHeadersfunction to standardize security and cache headers across responses.Request Handling:
Simplified request body parsing and error handling. Improved error messages for invalid JSON and oversized requests.
Environment Variable Parsing:
Fixed bug in
getEnvAsInt(now correctly reads environment variables and parses integers).2. Parallel Query Handling (
pkg/api/parallel.go)Model Validation:
Centralized valid model definitions for parallel queries. Improved error handling for invalid models.
Performance:
Pre-sized response maps for efficiency. Improved error response structure and logging for parallel model queries.
3. Monitoring & Metrics (
pkg/monitoring/monitoring.go)Performance & Accuracy:
Added running sums and counts for efficient average duration calculation. Limited stored request durations to the most recent 100 for each model. Pre-allocated maps for better performance.
Metrics Reporting:
Average durations are now calculated using running totals, improving accuracy and efficiency.
4. Model Router (
pkg/router/router.go)Maintainability:
Centralized the list of all known model types to avoid duplication. Improved comments and documentation for clarity.
Concurrency & Robustness:
Enhanced locking and TTL checks for model availability updates. Improved fallback logic for model selection and error handling. More robust random selection of available models.
Logging:
Added more detailed logging for routing decisions and error fallbacks.
Impact