Skip to content

Commit

Permalink
Auto initialize phi
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpreetbedi committed Feb 13, 2024
1 parent c591348 commit d4f577f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
2 changes: 1 addition & 1 deletion phi/cli/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def print_info(msg: str) -> None:


def log_config_not_available_msg() -> None:
logger.error("Phi not initialized, please run `phi init`")
logger.error("phi not initialized, please run `phi init`")


def log_active_workspace_not_available() -> None:
Expand Down
50 changes: 36 additions & 14 deletions phi/cli/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ def start(
),
env_filter: Optional[str] = typer.Option(None, "-e", "--env", metavar="", help="Filter the environment to deploy"),
infra_filter: Optional[str] = typer.Option(None, "-i", "--infra", metavar="", help="Filter the infra to deploy."),
config_filter: Optional[str] = typer.Option(None, "-c", "--config", metavar="", help="Filter the config to deploy"),
group_filter: Optional[str] = typer.Option(
None, "-g", "--group", metavar="", help="Filter resources using group name."
),
Expand Down Expand Up @@ -338,13 +337,22 @@ def start(
from pathlib import Path
from phi.cli.config import PhiCliConfig
from phi.cli.console import log_config_not_available_msg
from phi.cli.operator import start_resources
from phi.cli.operator import start_resources, initialize_phi
from phi.infra.type import InfraType

phi_config: Optional[PhiCliConfig] = PhiCliConfig.from_saved_config()
if not phi_config:
log_config_not_available_msg()
return
init_success = initialize_phi()
if not init_success:
from phi.cli.console import log_phi_init_failed_msg

log_phi_init_failed_msg()
return False
phi_config = PhiCliConfig.from_saved_config()
# If phi_config is still None, throw an error
if not phi_config:
log_config_not_available_msg()
return False

target_env: Optional[str] = None
target_infra_str: Optional[str] = None
Expand Down Expand Up @@ -395,7 +403,6 @@ def stop(
),
env_filter: Optional[str] = typer.Option(None, "-e", "--env", metavar="", help="Filter the environment to deploy"),
infra_filter: Optional[str] = typer.Option(None, "-i", "--infra", metavar="", help="Filter the infra to deploy."),
config_filter: Optional[str] = typer.Option(None, "-c", "--config", metavar="", help="Filter the config to deploy"),
group_filter: Optional[str] = typer.Option(
None, "-g", "--group", metavar="", help="Filter resources using group name."
),
Expand Down Expand Up @@ -445,13 +452,22 @@ def stop(
from pathlib import Path
from phi.cli.config import PhiCliConfig
from phi.cli.console import log_config_not_available_msg
from phi.cli.operator import stop_resources
from phi.cli.operator import stop_resources, initialize_phi
from phi.infra.type import InfraType

phi_config: Optional[PhiCliConfig] = PhiCliConfig.from_saved_config()
if not phi_config:
log_config_not_available_msg()
return
init_success = initialize_phi()
if not init_success:
from phi.cli.console import log_phi_init_failed_msg

log_phi_init_failed_msg()
return False
phi_config = PhiCliConfig.from_saved_config()
# If phi_config is still None, throw an error
if not phi_config:
log_config_not_available_msg()
return False

target_env: Optional[str] = None
target_infra_str: Optional[str] = None
Expand Down Expand Up @@ -552,13 +568,22 @@ def patch(
from pathlib import Path
from phi.cli.config import PhiCliConfig
from phi.cli.console import log_config_not_available_msg
from phi.cli.operator import patch_resources
from phi.cli.operator import patch_resources, initialize_phi
from phi.infra.type import InfraType

phi_config: Optional[PhiCliConfig] = PhiCliConfig.from_saved_config()
if not phi_config:
log_config_not_available_msg()
return
init_success = initialize_phi()
if not init_success:
from phi.cli.console import log_phi_init_failed_msg

log_phi_init_failed_msg()
return False
phi_config = PhiCliConfig.from_saved_config()
# If phi_config is still None, throw an error
if not phi_config:
log_config_not_available_msg()
return False

target_env: Optional[str] = None
target_infra_str: Optional[str] = None
Expand Down Expand Up @@ -609,7 +634,6 @@ def restart(
),
env_filter: Optional[str] = typer.Option(None, "-e", "--env", metavar="", help="Filter the environment to deploy"),
infra_filter: Optional[str] = typer.Option(None, "-i", "--infra", metavar="", help="Filter the infra to deploy."),
config_filter: Optional[str] = typer.Option(None, "-c", "--config", metavar="", help="Filter the config to deploy"),
group_filter: Optional[str] = typer.Option(
None, "-g", "--group", metavar="", help="Filter resources using group name."
),
Expand Down Expand Up @@ -660,7 +684,6 @@ def restart(
resources_file=resources_file,
env_filter=env_filter,
infra_filter=infra_filter,
config_filter=config_filter,
group_filter=group_filter,
name_filter=name_filter,
type_filter=type_filter,
Expand All @@ -675,7 +698,6 @@ def restart(
resources_file=resources_file,
env_filter=env_filter,
infra_filter=infra_filter,
config_filter=config_filter,
group_filter=group_filter,
name_filter=name_filter,
type_filter=type_filter,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "phidata"
version = "2.3.36"
version = "2.3.37"
description = "Build AI Assistants using function calling"
requires-python = ">=3.8"
readme = "README.md"
Expand Down

0 comments on commit d4f577f

Please sign in to comment.