Jason
09/30/2024, 8:37 PMJeremiah
Jason
09/30/2024, 8:58 PMJeremiah
Jeremiah
Jason
09/30/2024, 9:53 PMJeremiah
Jeremiah
Jeremiah
import controlflow as cf
from pydantic import BaseModel
class Person(BaseModel):
name: str
age: int
cf.run(
"What's the person's name?",
context=dict(person=Person(name="John", age=30)),
)
Jason
09/30/2024, 10:01 PMimport typing as t
from datetime import datetime
from pydantic import BaseModel
class Email(BaseModel):
sender: str
sent_at: datetime
body: str
subject: str
class EmailHistory(BaseModel):
emails: t.List[Email]
Just a very basic example. I'm passing this into a @cf.flow method
@cf.flow
def process_email(email_history: EmailHistory):
cf.run(...., context={email_history=email_history})
Jason
09/30/2024, 10:03 PMJason
09/30/2024, 10:03 PMJeremiah
Jeremiah
Jeremiah
Jeremiah
Jason
10/02/2024, 8:01 PMJason
10/02/2024, 8:02 PMJason
10/02/2024, 8:03 PMJason
10/02/2024, 8:04 PMJeremiah
Jeremiah
Jeremiah
flow_context
or _context
(or somethign) kwarg to be passed whenever you call a flow. Another DX would be
@flow(context_kwargs=['x', 'z'])
def demo(x, y, z):
# x and z are automatically in context, y isnt
Jeremiah
Jeremiah
Jason
10/02/2024, 8:09 PMJason
10/02/2024, 8:10 PMJason
10/02/2024, 8:10 PMJason
10/02/2024, 8:10 PMJeremiah
Jeremiah
Jeremiah