File size: 1,115 Bytes
5aa5283
 
 
 
 
 
 
9b92ec5
5aa5283
 
 
 
 
fc5a259
 
 
5aa5283
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from typing import Dict, List, Any, Optional, TypedDict
from pydantic import BaseModel, Field


# Define a structured output model
class IngredientAnalysisResult(BaseModel):
    name: str
    id: int
    alternate_names: List[str] = Field(default_factory=list)
    is_found: bool = False
    safety_rating: int = 5
    description: str = "No information found."
    health_effects: List[str] = Field(default_factory=lambda: ["Unknown"])
    allergic_info: Optional[List[str]] = None  # New field
    diet_type: Optional[str] = None  # New field
    details_with_source: List[Dict[str, Any]] = Field(default_factory=list)
    
    class Config:
        from_attributes = True  # Enable ORM mode

# Define typed state for LangGraph
class IngredientState(TypedDict):
    ingredient: str
    sources_data: List[Dict[str, Any]]
    status: str
    result: Optional[Dict[str, Any]]
    local_db_checked: bool
    web_search_done: bool
    wikipedia_checked: bool
    open_food_facts_checked: bool
    usda_checked: bool
    pubchem_checked: bool
    analysis_done: bool

class IngredientRequest(BaseModel):
    name: str