File size: 1,081 Bytes
f52f1cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ae604b6
 
f52f1cd
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { config } from "@configs/config";

const endpoint = '/nutrition';

// Define the structure of a Nutrition Prediction Item
export interface INutritionPredictionItem {
  Calories: number;
  CarbohydrateContent: number;
  FatContent: number;
  Images: string[];
  Name: string;
  ProteinContent: number;
  RecipeIngredientParts: string[];
  RecipeInstructions: string[];
  type: string;
}

export interface INParams {
  calories: number
}

export class NutritionModel {
  public static async predictMealPlan(
    params: INParams
  ): Promise<INutritionPredictionItem[][]> {
    const response = await fetch(
      `${config.modelsServerUrl}${endpoint}`,
      {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
        },
        body: JSON.stringify(params),
      }
    );

    if (!response.ok) {
      console.error(await response.text());
      throw new Error("Failed to fetch data from the server");
    }

    return response.text().then((data) => {
      return JSON.parse(data) as INutritionPredictionItem[][];
    });
  }
}