Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e406a5a

Browse files
committed
fix: async model call prints should only occur if PDL_VERBOSE_ASYNC env is set
Signed-off-by: Nick Mitchell <[email protected]>
1 parent 8653808 commit e406a5a

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

pdl-live-react/src/view/term/RunTerminal.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ export default function RunTerminal({
8383
// spawn shell
8484
const pty = spawn(cmd, args, {
8585
cwd,
86+
env: {
87+
PDL_VERBOSE_ASYNC: "true",
88+
},
8689
cols: term.cols,
8790
rows: term.rows,
8891
})

src/pdl/pdl_llms.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# pylint: disable=import-outside-toplevel
2+
from os import environ
23
import asyncio
34
import threading
45
from concurrent.futures import Future
@@ -87,7 +88,8 @@ def generate_text(
8788
messages: ModelInput,
8889
parameters: dict[str, Any],
8990
) -> tuple[LazyMessage, PdlLazy[Any]]:
90-
print(f"Asynchronous model call started to {model_id}", file=stderr)
91+
if "PDL_VERBOSE_ASYNC" in environ:
92+
print(f"Asynchronous model call started to {model_id}", file=stderr)
9193
# global _BACKGROUND_TASKS
9294
future = asyncio.run_coroutine_threadsafe(
9395
LitellmModel.async_generate_text(
@@ -130,22 +132,23 @@ def update_end_nanos(future):
130132
else 0
131133
)
132134
exec_nanos = block.pdl__timing.end_nanos - start
133-
print(
134-
f"Asynchronous model call to {model_id} completed in {(exec_nanos)/1000000}ms",
135-
file=stderr,
136-
)
137-
msg = future.result()[0]
138-
if msg["content"] is not None:
139-
from termcolor import colored
140-
141-
from .pdl_ast import BlockKind
142-
from .pdl_scheduler import color_of
143-
135+
if "PDL_VERBOSE_ASYNC" in environ:
144136
print(
145-
colored(msg["content"], color=color_of(BlockKind.MODEL)),
137+
f"Asynchronous model call to {model_id} completed in {(exec_nanos)/1000000}ms",
146138
file=stderr,
147139
)
148-
print("\n", file=stderr)
140+
msg = future.result()[0]
141+
if msg["content"] is not None:
142+
from termcolor import colored
143+
144+
from .pdl_ast import BlockKind
145+
from .pdl_scheduler import color_of
146+
147+
print(
148+
colored(msg["content"], color=color_of(BlockKind.MODEL)),
149+
file=stderr,
150+
)
151+
print("\n", file=stderr)
149152

150153
future.add_done_callback(update_end_nanos)
151154

0 commit comments

Comments
 (0)