Skip to content

GUI

gui

Contains the Mirumoji Launcher GUI implementation

core

This module contains the main helper functions to check the environment and launch the mirumoji application.

build_img(image_name, dockerfile, build_context)

Runs the docker build command for a specified image name and streams the command's stdout and stderr, finally returning the Popen process object.

Parameters:

Name Type Description Default
image_name str

Name the image will be given

required
dockerfile Path

Path to the Dockefile which should be used

required
build_context Path

Path to the directory which should be used as the build context

required

Raises:

Type Description
FileNotFoundError

If dockerfile or build_context couldn't be found

Returns:

Type Description
Popen[str]

Generator that yields stdout lines (str) and has a return value of the completed subprocess.Popen object.

check_env_file(expected_vars, env_file_path)

Checks for existence of required .env file and its contents.

Raises:

Type Description
ValueError

If env_file_path doesn't contain one of expected_vars

FileNotFoundError

If env_file_path isn't a file

Parameters:

Name Type Description Default
expected_vars List[str]

List of variables that should be present

required
env_file_path Path

Path to the environment file

required

docker_compose(compose_command, *, name_only, command_flags=[], docker_compose_file=None, compose_app_name='mirumoji')

Run a docker compose command on docker_compose_file with compose_app_name as the compose application name and stream the stdout and stderr.

Parameters:

Name Type Description Default
compose_command str

Name of the compose command to run

required
name_only bool

If True use only compose_app_name in the command.

required
command_flags List[str]

Optional flags to run command with. Defaults to empty list

[]
docker_compose_file Path

Path to the docker compose file if name_only=False. Defaults to None

None
compose_app_name str

Name to give the compose app or to identify it by. Defaults to mirumoji

'mirumoji'

Raises:

Type Description
FileNotFoundError

If docker_compose_file can't be found

ValueError

If name_only=Falseand docker_compose_file=None

Returns:

Type Description
Popen[str]

Generator that yields stdout lines (str) and has a return value of the completed subprocess.Popen object.

docker_running()

Checks if the Docker service/daemon is currently running by executing docker info command.

Raises:

Type Description
CalledProcessError

If command fails

Returns:

Type Description
CompletedProcess[str]

The subprocess.CompletedProcess object

ensure_repo(repo_url, repo_path)

Clones or updates a git repository repo_url at repo_path

Parameters:

Name Type Description Default
repo_url str

The GitHub repository url

required
repo_path Path

Where to clone the repo or where to find it for updates

required

get_host_lan_ip(load_to_env=True, var_name='HOST_LAN_IP')

Get the primary LAN IPv4 address of the host machine and loads it as an environment variable.

Parameters:

Name Type Description Default
load_to_env bool

If True, load IPv4 as an environemnt variable. Defaults to True

True
var_name str

Name of the environment variable if load_to_env=True. Defaults to HOST_LAN_IP

'HOST_LAN_IP'

Returns:

Name Type Description
str str

The Primary LAN IPv4 address of the host machine

git_installed()

Checks if git is installed by running git --version

Raises:

Type Description
CalledProcessError

If command fails

Returns:

Type Description
CompletedProcess[str]

The subprocess.CompletedProcess object

has_nvidia_container_toolkit()

Checks if the NVIDIA Container Toolkit is installed and configured.

Returns:

Name Type Description
bool bool

False if command returns non-zero exit status, True otherwhise.

has_nvidia_gpu()

Checks if an NVIDIA GPU is available on the system by running nvidia-smi.

Returns:

Name Type Description
bool bool

False if command returns non-zero exit status, True otherwhise.

run_command(command_list, *, cwd=None, check=True, shell=False, stream=True)

run_command(
    command_list: List[str],
    *,
    cwd: Optional[Path] = None,
    check: bool = True,
    shell: bool = False,
    stream: Literal[True]
) -> Generator[str, str, Popen[str]]
run_command(
    command_list: List[str],
    *,
    cwd: Optional[Path] = None,
    check: bool = True,
    shell: bool = False,
    stream: Literal[False]
) -> Popen[str]

subprocess.Popen wrapper with error handling and logging

Parameters:

Name Type Description Default
command_list List[str]

List of command arguments to be executed

required
cwd Path

Path in which to execute the command from. If None use program execution cwd

None
check bool

When True, if the command returns an error status code an exception is propagated. Defaults to True

True
shell bool

When True, concatenate the list of arguments into a string and run in shell mode. Defaults to False

False
stream bool

When True, stream command output. Defaults to True

True

Returns:

Type Description
Union[Popen[str], Generator[str, str, Popen[str]]]

Subprocess object with pid, stdin, stdout, stderr and returncode or a generator that yields stdout lines (str) and has a return value of the completed subprocess.Popen object.

Raises:

Type Description
CalledProcessError

If command raises an error and check=True

main

Defines and starts the Mirumoji Launcher GUI

http_exception_handler(request, exc) async

Custom Exception Handler for all HTTP Errors.

Parameters:

Name Type Description Default
request Request

Incoming request object.

required
exc HTTPException

Raised Exception Object.

required

Returns:

Name Type Description
JSONResponse JSONResponse

The exception response to return.

lifespan(app) async

Context Manager for managing API's lifecyle.

Parameters:

Name Type Description Default
app FastAPI

The API object.

required

Yields:

Name Type Description
Any AsyncGenerator[Any, None]

Application

setup_logging()

Setups custom logging for the launcher.

Includes a formatted stream handler and a file handler directed to ~/.mirumoji_launcher/logs/main.log

models

Pydantic models for the GUI FastAPI application.

BuildRequest

Bases: BaseModel

Format of request to build images locally with api/build endpoint

Parameters:

Name Type Description Default
gpu bool

If True, build GPU version of backend, otherwise build CPU version

required

StartRequest

Bases: BaseModel

Format of request to launch the mirumoji application with api/start endpoint

Parameters:

Name Type Description Default
gpu bool

If True run GPU version, otherwise run CPU version

required
local bool

If True run with locally built images, otherwise pull from repository

required
OPENAI_API_KEY str

API Key to the OpenAI API

required
MODAL_TOKEN_ID str

Modal Token ID if using CPU version

required
MODAL_TOKEN_SECRET str

Modal Token Secret if using CPU version

required
MIRUMOJI_LOGGING_LEVEL str

Level of logging to run the application inside the container. Defaults to INFO

required
MIRUMOJI_MODAL_GPU str

Which GPU to request Modal. Defaults to A10G

required
MODAL_FORCE_BUILD bool

Whether to re-pull the Modal Image on every Modal run. Defaults to False

required
repository str

Wether to pull images from GitHub or DockerHub if local=False

required

StopRequest

Bases: BaseModel

Format of request to stop the mirumoji application with api/stop endpoint

Parameters:

Name Type Description Default
clean bool

Wether to delete created Docker volumes and networks

required

paths

This module defines configuration Constants and utility functions for the paths used in the Mirumoji Launcher GUI

router

Defines the /api router of the GUI launcher application

build_imgs(request)

POST endpoint which builds the mirumoji Docker images locally by running docker build command and streaming back the process's stdout.

Parameters:

Name Type Description Default
request StartRequest

Endpoint request in the format of StopRequest

required

Returns:

Name Type Description
StreamingResponse StreamingResponse

Docker command's stdout

check_docker()

GET endpoint which checks if Docker deamon is running

Returns:

Type Description
Dict[str, bool]

Dictionary with status key

has_gpu()

GET endpoint which checks if the system has an NVIDIA GPU installed

Returns:

Type Description
Dict[str, bool]

Dictionary with status key

send_logs()

GET endpoint which streams the mirumoji application logs from the docker compose application.

Returns:

Name Type Description
StreamingResponse StreamingResponse

Docker command's stdout

start_app(request)

POST endpoint which starts the mirumoji application by running docker compose up command and streaming back the process's stdout.

Parameters:

Name Type Description Default
request StartRequest

Endpoint request in the format of StartRequest

required

Returns:

Name Type Description
StreamingResponse StreamingResponse

Docker command's stdout

stop_app(request)

POST endpoint which stops the mirumoji application by running docker compose down command and streaming back the process's stdout.

Parameters:

Name Type Description Default
request StartRequest

Endpoint request in the format of StopRequest

required

Returns:

Name Type Description
StreamingResponse StreamingResponse

Docker command's stdout