Skip to content

Commit 64d0256

Browse files
authored
feat: add llm_usage to the exec_* config (#1331)
Signed-off-by: Louis Mandel <[email protected]>
1 parent e181a45 commit 64d0256

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/pdl/pdl.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class InterpreterConfig(TypedDict, total=False):
5858
"""
5959
event_loop: AbstractEventLoop
6060
"""Event loop to schedule LLM calls."""
61+
llm_usage: PdlUsage
62+
"""Data structure where to accumulate LLMs usage."""
6163

6264

6365
class Result(TypedDict):

src/pdl/pdl_interpreter_state.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ class InterpreterState(BaseModel):
3636
"""Cache containing the imported files."""
3737
event_loop: AbstractEventLoop = Field(default_factory=create_event_loop_thread)
3838
"""Event loop to schedule LLM calls."""
39-
current_pdl_context: Ref[LazyMessages] = Ref(DependentContext([]))
39+
current_pdl_context: Ref[LazyMessages] = Field(
40+
default_factory=lambda: Ref(DependentContext([]))
41+
)
4042
"""Current value of the context set at the beginning of the execution of the block."""
4143
replay: dict[str, Any] = {}
4244
"""Dictionary that associate runtime block ids with their values to be able to replay an execution."""
4345
llm_usage: PdlUsage = PdlUsage()
44-
"""Record statistics about LLM usage."""
46+
"""Data structure where to accumulate LLMs usage."""
4547

4648
def with_yield_result(self: "InterpreterState", b: bool) -> "InterpreterState":
4749
return self.model_copy(update={"yield_result": b})

0 commit comments

Comments
 (0)