General AI Models Service
Relevant source files
The following files were used as context for generating this wiki page:
The General AI Models service is a core microservice within the Aether-X Ultimate platform designed to manage and execute various artificial intelligence models. Its primary scope includes hosting Large Language Models (LLMs) like GPT-2, specialized anomaly detection models, and text classification systems. The service provides a unified interface for both real-time generation and batch processing, supporting the broader ecosystem's needs for intelligent content generation and data analysis.
This service operates on port 8003 and integrates with the API Gateway for external request routing and the Security Service for protected operations. It utilizes a persistent volume for model storage and relies on a containerized infrastructure for scalable deployment.
Sources: IMPLEMENTATION_COMPLETE.md:16, docker-compose.yml:68-87, services/ai-models/app.py:1-20
Service Architecture
The AI Models service is built using the Flask web framework and leverages the Hugging Face transformers library for LLM operations. It follows a microservices pattern where model logic is decoupled from data ingestion and gateway routing.
Component Interaction
The service interacts with several infrastructure components to ensure high availability and data persistence.
Functional Modules
1. Large Language Model (LLM) Integration
The service initializes a gpt2 text-generation pipeline upon startup. This pipeline is used for general text synthesis and as a backbone for more complex tasks like natural language text classification.
Sources: services/ai-models/app.py:12-25
2. Specialized Models
The service includes specific logic for non-generative AI tasks:
- Anomaly Detection: Uses the
Isolation Forestalgorithm fromsklearnto identify outliers in numerical feature sets. - Text Classification: Leverages the LLM to classify provided text strings into categories (e.g., positive, negative, neutral) via prompt engineering.
Sources: services/ai-models/app.py:75-125
3. Training and Persistence
The service supports the training of custom models, specifically anomaly detection models. Once trained, models are serialized using joblib and saved to a persistent volume at /app/models/.
Sources: services/ai-models/app.py:127-160, k8s/deployment.yaml:166-170
API Endpoints
The AI Models service exposes several RESTful endpoints for model interaction. While the service runs on port 8003, these are typically accessed via the API Gateway prefix /api/v1/llm/ or /api/v1/specialized/.
| Endpoint | Method | Description | Parameters |
|---|---|---|---|
/llm/generate | POST | Generates text based on a single prompt. | prompt (str), model_name (str) |
/llm/batch-generate | POST | Processes an array of prompts in a single request. | prompts (list[str]) |
/specialized/predict | POST | Runs predictions using specific model types. | model_type (str), input_data (dict) |
/model/train | POST | Trains and saves a new model instance. | model_type (str), training_data (dict) |
/health | GET | Returns service health status. | None |
| Sources: services/ai-models/app.py:27-160, services/api-gateway/app.py:145-155 |
Request Flow for LLM Generation
The following sequence diagram illustrates the flow of a text generation request from the user through the system.
Deployment Configuration
Kubernetes Specification
In production, the service is deployed with the following resource constraints and volume mounts to ensure stability when handling memory-intensive AI models.
# Configuration Summary from k8s/deployment.yaml
replicas: 2
resources:
requests:
memory: "1Gi"
cpu: "500m"
limits:
memory: "2Gi"
cpu: "1000m"
volumeMounts:
- name: models-volume
mountPath: /app/models
Sources: k8s/deployment.yaml:148-175
Technical Implementation Snippet
The following snippet demonstrates how the service handles specialized anomaly detection using Isolation Forest.
# From services/ai-models/app.py:84-106
@app.route('/specialized/predict', methods=['POST'])
def specialized_predict():
data = request.json
model_type = data.get('model_type', '')
input_data = data.get('input_data', {})
if model_type == 'anomaly_detection':
features = input_data.get('features', [])
X = np.array(features).reshape(-1, 1)
model = IsolationForest(contamination=0.1)
model.fit(X)
predictions = model.predict(X)
anomaly_scores = model.decision_function(X)
return jsonify({
"predictions": predictions.tolist(),
"anomaly_scores": anomaly_scores.tolist()
})
Sources: services/ai-models/app.py:75-106
Summary
The General AI Models Service acts as the intelligence hub for Aether-X Ultimate. By providing standardized endpoints for LLM generation and specialized data analysis, it enables other microservices to incorporate advanced AI capabilities without managing model lifecycles locally. Its reliance on persistent storage and specialized libraries like transformers and sklearn ensures it can handle both generative and analytical workloads effectively.