-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstates.py
More file actions
52 lines (35 loc) · 1.01 KB
/
Copy pathstates.py
File metadata and controls
52 lines (35 loc) · 1.01 KB
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
48
49
50
51
52
#so now we are creating a graph
#and the first thing you create is a state
import os
#1) typed DICT (Most common approach)
from typing import TypedDict
class State(TypedDict):
topic : str
summary : str
score : int
#2) pydantic approach
#it is good at data validation and type checking at
#runtime
from pydantic import BaseModel, field_validator
class State(BaseModel):
topic : str
score :int
summary : str = ""
@field_validator
def score_positive(cls,v):
if v < 0:
raise ValueError("score must be positive")
#python dataclaseess
#standard python dataclass but it is used very rarelty
from dataclasses import dataclass, field
@dataclass
class State:
topic : str = ""
summary : str = ""
messages : list = field(default_factory=list)
from langgraph.graph import MessagesState
class State(MessagesState):
# messages field is already included with add_messages reducer
# just add your extra fields
user_name: str
language: str