Skip to content

Commit 54a4bad

Browse files
badayvedatefiop
andauthored
feat(fal): print routes for ephemeral runs (#586)
* feat(hacky): sdk route printer * use service_urls * ignore old messages * fix --------- Co-authored-by: Ruslan Kuprieiev <kupruser@gmail.com>
1 parent 1f5e7e8 commit 54a4bad

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

projects/fal/src/fal/api.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,27 @@ def run(
600600
kwargs: dict[str, Any],
601601
) -> ReturnT:
602602
def result_handler(partial_result):
603+
from fal.console import console
604+
605+
if service_urls := partial_result.service_urls:
606+
console.print("Playground:")
607+
endpoints = getattr(func, "_routes", ["/"]) # type: ignore[attr-defined]
608+
for endpoint in endpoints:
609+
console.print(f"\t{service_urls.playground}{endpoint}")
610+
console.print("Synchronous Endpoints:")
611+
for endpoint in endpoints:
612+
console.print(f"\t{service_urls.run}{endpoint}")
613+
console.print("Asynchronous Endpoints (Recommended):")
614+
for endpoint in endpoints:
615+
console.print(f"\t{service_urls.queue}{endpoint}")
616+
603617
for log in partial_result.logs:
618+
if (
619+
"Access the playground at" in log.message
620+
or "And API access through" in log.message
621+
):
622+
# Obsolete messages from before service_urls were added.
623+
continue
604624
self._log_printer.print(log)
605625

606626
return self._run(func, options, args, kwargs, result_handler=result_handler)

projects/fal/src/fal/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def initialize_and_serve():
110110
metadata["openapi"] = app.openapi()
111111

112112
routes = app.collect_routes()
113+
initialize_and_serve._routes = [r.path for r in routes.keys()] or ["/"] # type: ignore[attr-defined]
113114
realtime_app = any(route.is_websocket for route in routes)
114115

115116
kind = cls.host_kwargs.pop("kind", "virtualenv")

0 commit comments

Comments
 (0)