Skip to content

Commit

Permalink
feat: print playground url on deploy (#249)
Browse files Browse the repository at this point in the history
* feat: print playground url on deploy

* fix tests

* print both endpoint and playground urls
  • Loading branch information
mederka authored Jun 25, 2024
1 parent 16a27f4 commit 92af843
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 34 deletions.
16 changes: 10 additions & 6 deletions projects/fal/src/fal/cli/deploy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import argparse
from collections import namedtuple
from pathlib import Path

from .parser import FalClientParser, RefAction

User = namedtuple("User", ["user_id", "username"])


def _remove_http_and_port_from_url(url):
# Remove http://
Expand All @@ -21,17 +24,17 @@ def _remove_http_and_port_from_url(url):
return url


def _get_user_id() -> str:
def _get_user() -> User:
import json
from http import HTTPStatus

import openapi_fal_rest.api.billing.get_user_details as get_user_details
import openapi_fal_rest.api.users.get_current_user as get_current_user

from fal.api import FalServerlessError
from fal.rest_client import REST_CLIENT

try:
user_details_response = get_user_details.sync_detailed(
user_details_response = get_current_user.sync_detailed(
client=REST_CLIENT,
)
except Exception as e:
Expand All @@ -52,7 +55,7 @@ def _get_user_id() -> str:
if not user_id:
user_id = full_user_id

return user_id
return User(user_id=user_id, username=user_details_response.parsed.nickname)
except Exception as e:
raise FalServerlessError(f"Could not parse the user data: {e}")

Expand All @@ -78,7 +81,7 @@ def _deploy(args):
[file_path] = options
file_path = str(file_path)

user_id = _get_user_id()
user = _get_user()
host = FalServerlessHost(args.host)
isolated_function, app_name = load_function_from(
host,
Expand All @@ -104,7 +107,8 @@ def _deploy(args):
"Registered a new revision for function "
f"'{app_name}' (revision='{app_id}')."
)
args.console.print(f"URL: https://{gateway_host}/{user_id}/{app_name}")
args.console.print(f"Playground: https://fal.ai/models/{user.username}/{app_name}")
args.console.print(f"Endpoint: https://{gateway_host}/{user.username}/{app_name}")


def add_parser(main_subparsers, parents):
Expand Down
43 changes: 15 additions & 28 deletions projects/fal/tests/test_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import httpx
import pytest
from fal import apps
from fal.cli.deploy import _get_user
from fal.container import ContainerImage
from fal.rest_client import REST_CLIENT
from fal.workflows import Workflow
Expand Down Expand Up @@ -206,28 +207,24 @@ def aliased_app() -> Generator[tuple[str, str], None, None]:
def test_app():
# Create a temporary app, register it, and return the ID of it.

from fal.cli.deploy import _get_user_id

app_revision = addition_app.host.register(
func=addition_app.func,
options=addition_app.options,
)
user_id = _get_user_id()
yield f"{user_id}/{app_revision}"
user = _get_user()
yield f"{user.user_id}/{app_revision}"


@pytest.fixture(scope="module")
def test_nomad_app():
# Create a temporary app, register it, and return the ID of it.

from fal.cli.deploy import _get_user_id

app_revision = nomad_addition_app.host.register(
func=nomad_addition_app.func,
options=nomad_addition_app.options,
)
user_id = _get_user_id()
yield f"{user_id}/{app_revision}"
user = _get_user()
yield f"{user.user_id}/{app_revision}"


@pytest.mark.xfail(
Expand All @@ -237,74 +234,64 @@ def test_nomad_app():
def test_container_app():
# Create a temporary app, register it, and return the ID of it.

from fal.cli.deploy import _get_user_id

app_revision = container_addition_app.host.register(
func=container_addition_app.func,
options=container_addition_app.options,
)
user_id = _get_user_id()
yield f"{user_id}/{app_revision}"
user = _get_user()
yield f"{user.user_id}/{app_revision}"


@pytest.fixture(scope="module")
def test_fastapi_app():
# Create a temporary app, register it, and return the ID of it.

from fal.cli.deploy import _get_user_id

app_revision = calculator_app.host.register(
func=calculator_app.func,
options=calculator_app.options,
)
user_id = _get_user_id()
yield f"{user_id}/{app_revision}"
user = _get_user()
yield f"{user.user_id}/{app_revision}"


@pytest.fixture(scope="module")
def test_stateful_app():
# Create a temporary app, register it, and return the ID of it.

from fal.cli.deploy import _get_user_id

app = fal.wrap_app(StatefulAdditionApp)
app_revision = app.host.register(
func=app.func,
options=app.options,
)
user_id = _get_user_id()
yield f"{user_id}/{app_revision}"
user = _get_user()
yield f"{user.user_id}/{app_revision}"


@pytest.fixture(scope="module")
def test_exception_app():
# Create a temporary app, register it, and return the ID of it.

from fal.cli.deploy import _get_user_id

app = fal.wrap_app(ExceptionApp)
app_revision = app.host.register(
func=app.func,
options=app.options,
)
user_id = _get_user_id()
yield f"{user_id}/{app_revision}"
user = _get_user()
yield f"{user.user_id}/{app_revision}"


@pytest.fixture(scope="module")
def test_realtime_app():
# Create a temporary app, register it, and return the ID of it.

from fal.cli.deploy import _get_user_id

app = fal.wrap_app(RealtimeApp)
app_revision = app.host.register(
func=app.func,
options=app.options,
application_auth_mode="public",
)
user_id = _get_user_id()
yield f"{user_id}/{app_revision}"
user = _get_user()
yield f"{user.user_id}/{app_revision}"


def test_app_client(test_app: str, test_nomad_app: str):
Expand Down

0 comments on commit 92af843

Please sign in to comment.