REFACTOR API gateway
This commit is contained in:
@@ -75,9 +75,9 @@ export class TrainingService {
|
||||
/**
|
||||
* Start new training job
|
||||
*/
|
||||
async startTraining(config: TrainingConfiguration): Promise<TrainingJobStatus> {
|
||||
async startTraining(tenantId: string, config: TrainingConfiguration): Promise<TrainingJobStatus> {
|
||||
const response = await apiClient.post<TrainingJobStatus>(
|
||||
'/api/v1/training/jobs',
|
||||
`/api/v1/tenants/${tenantId}/training/jobs`,
|
||||
config
|
||||
);
|
||||
return response.data!;
|
||||
@@ -86,9 +86,9 @@ export class TrainingService {
|
||||
/**
|
||||
* Get training job status
|
||||
*/
|
||||
async getTrainingStatus(jobId: string): Promise<TrainingJobProgress> {
|
||||
async getTrainingStatus(tenantId: string, jobId: string): Promise<TrainingJobProgress> {
|
||||
const response = await apiClient.get<ApiResponse<TrainingJobProgress>>(
|
||||
`/api/v1/training/jobs/${jobId}`
|
||||
`/api/v1/tenants/${tenantId}/training/jobs/${jobId}`
|
||||
);
|
||||
return response.data!;
|
||||
}
|
||||
@@ -96,7 +96,7 @@ export class TrainingService {
|
||||
/**
|
||||
* Get all training jobs
|
||||
*/
|
||||
async getTrainingHistory(params?: {
|
||||
async getTrainingHistory(tenantId: string, params?: {
|
||||
page?: number;
|
||||
limit?: number;
|
||||
status?: string;
|
||||
@@ -113,14 +113,14 @@ export class TrainingService {
|
||||
/**
|
||||
* Cancel training job
|
||||
*/
|
||||
async cancelTraining(jobId: string): Promise<void> {
|
||||
await apiClient.post(`/api/v1/training/jobs/${jobId}/cancel`);
|
||||
async cancelTraining(tenantId: string, jobId: string): Promise<void> {
|
||||
await apiClient.post(`/api/v1/tenants/${tenantId}/training/jobs/${jobId}/cancel`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get trained models
|
||||
*/
|
||||
async getModels(params?: {
|
||||
async getModels(tenantId: string, params?: {
|
||||
productName?: string;
|
||||
active?: boolean;
|
||||
page?: number;
|
||||
@@ -131,14 +131,14 @@ export class TrainingService {
|
||||
page: number;
|
||||
pages: number;
|
||||
}> {
|
||||
const response = await apiClient.get<ApiResponse<any>>('/api/v1/training/models', { params });
|
||||
const response = await apiClient.get<ApiResponse<any>>(`/api/v1/tenants/${tenantId}/training/models`, { params });
|
||||
return response.data!;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get specific model details
|
||||
*/
|
||||
async getModel(modelId: string): Promise<TrainedModel> {
|
||||
async getModel(tenantId: string, modelId: string): Promise<TrainedModel> {
|
||||
const response = await apiClient.get<ApiResponse<TrainedModel>>(
|
||||
`/api/v1/training/models/${modelId}`
|
||||
);
|
||||
@@ -148,9 +148,9 @@ export class TrainingService {
|
||||
/**
|
||||
* Get model metrics
|
||||
*/
|
||||
async getModelMetrics(modelId: string): Promise<ModelMetrics> {
|
||||
async getModelMetrics(tenantId: string, modelId: string): Promise<ModelMetrics> {
|
||||
const response = await apiClient.get<ApiResponse<ModelMetrics>>(
|
||||
`/api/v1/training/models/${modelId}/metrics`
|
||||
`/api/v1/tenants/${tenantId}/training/models/${modelId}/metrics`
|
||||
);
|
||||
return response.data!;
|
||||
}
|
||||
@@ -158,9 +158,9 @@ export class TrainingService {
|
||||
/**
|
||||
* Activate/deactivate model
|
||||
*/
|
||||
async toggleModelStatus(modelId: string, active: boolean): Promise<TrainedModel> {
|
||||
async toggleModelStatus(tenantId: string, modelId: string, active: boolean): Promise<TrainedModel> {
|
||||
const response = await apiClient.patch<ApiResponse<TrainedModel>>(
|
||||
`/api/v1/training/models/${modelId}`,
|
||||
`/api/v1/tenants/${tenantId}/training/models/${modelId}`,
|
||||
{ is_active: active }
|
||||
);
|
||||
return response.data!;
|
||||
@@ -169,16 +169,16 @@ export class TrainingService {
|
||||
/**
|
||||
* Delete model
|
||||
*/
|
||||
async deleteModel(modelId: string): Promise<void> {
|
||||
async deleteModel(tenantId: string, modelId: string): Promise<void> {
|
||||
await apiClient.delete(`/api/v1/training/models/${modelId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Train specific product
|
||||
*/
|
||||
async trainProduct(productName: string, config?: Partial<TrainingConfiguration>): Promise<TrainingJobStatus> {
|
||||
async trainProduct(tenantId: string, productName: string, config?: Partial<TrainingConfiguration>): Promise<TrainingJobStatus> {
|
||||
const response = await apiClient.post<ApiResponse<TrainingJobStatus>>(
|
||||
'/api/v1/training/products/train',
|
||||
`/api/v1/tenants/${tenantId}/training/products/train`,
|
||||
{
|
||||
product_name: productName,
|
||||
...config,
|
||||
@@ -190,7 +190,7 @@ export class TrainingService {
|
||||
/**
|
||||
* Get training statistics
|
||||
*/
|
||||
async getTrainingStats(): Promise<{
|
||||
async getTrainingStats(tenantId: string): Promise<{
|
||||
total_models: number;
|
||||
active_models: number;
|
||||
avg_accuracy: number;
|
||||
@@ -198,21 +198,21 @@ export class TrainingService {
|
||||
products_trained: number;
|
||||
training_time_avg_minutes: number;
|
||||
}> {
|
||||
const response = await apiClient.get<ApiResponse<any>>('/api/v1/training/stats');
|
||||
const response = await apiClient.get<ApiResponse<any>>(`/api/v1/tenants/${tenantId}/training/stats`);
|
||||
return response.data!;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate training data
|
||||
*/
|
||||
async validateTrainingData(products?: string[]): Promise<{
|
||||
async validateTrainingData(tenantId: string, products?: string[]): Promise<{
|
||||
valid: boolean;
|
||||
errors: string[];
|
||||
warnings: string[];
|
||||
product_data_points: Record<string, number>;
|
||||
recommendation: string;
|
||||
}> {
|
||||
const response = await apiClient.post<ApiResponse<any>>('/api/v1/training/validate', {
|
||||
const response = await apiClient.post<ApiResponse<any>>(`/api/v1/tenants/${tenantId}/training/validate`, {
|
||||
products,
|
||||
});
|
||||
return response.data!;
|
||||
@@ -221,29 +221,29 @@ export class TrainingService {
|
||||
/**
|
||||
* Get training recommendations
|
||||
*/
|
||||
async getTrainingRecommendations(): Promise<{
|
||||
async getTrainingRecommendations(tenantId: string): Promise<{
|
||||
should_retrain: boolean;
|
||||
reasons: string[];
|
||||
recommended_products: string[];
|
||||
optimal_config: TrainingConfiguration;
|
||||
}> {
|
||||
const response = await apiClient.get<ApiResponse<any>>('/api/v1/training/recommendations');
|
||||
const response = await apiClient.get<ApiResponse<any>>(`/api/v1/tenants/${tenantId}/training/recommendations`);
|
||||
return response.data!;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get training logs
|
||||
*/
|
||||
async getTrainingLogs(jobId: string): Promise<string[]> {
|
||||
const response = await apiClient.get<ApiResponse<string[]>>(`/api/v1/training/jobs/${jobId}/logs`);
|
||||
async getTrainingLogs(tenantId: string, jobId: string): Promise<string[]> {
|
||||
const response = await apiClient.get<ApiResponse<string[]>>(`/api/v1/tenants/${tenantId}/training/jobs/${jobId}/logs`);
|
||||
return response.data!;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export model
|
||||
*/
|
||||
async exportModel(modelId: string, format: 'pickle' | 'onnx' = 'pickle'): Promise<Blob> {
|
||||
const response = await apiClient.get(`/api/v1/training/models/${modelId}/export`, {
|
||||
async exportModel(tenantId: string, modelId: string, format: 'pickle' | 'onnx' = 'pickle'): Promise<Blob> {
|
||||
const response = await apiClient.get(`/api/v1/tenants/${tenantId}/training/models/${modelId}/export`, {
|
||||
params: { format },
|
||||
responseType: 'blob',
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user