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 |
Returns:
Type | Description |
---|---|
Popen[str]
|
Generator that yields stdout lines
(str) and has a return value of the
completed |
check_env_file(expected_vars, env_file_path)
¶
Checks for existence of required .env
file and its contents.
Raises:
Type | Description |
---|---|
ValueError
|
If |
FileNotFoundError
|
If |
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 |
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
|
None
|
compose_app_name
|
str
|
Name to give the compose app or to
identify it by. Defaults to |
'mirumoji'
|
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If |
ValueError
|
If |
Returns:
Type | Description |
---|---|
Popen[str]
|
Generator that yields stdout lines
(str) and has a return value of the
completed |
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 |
ensure_repo(repo_url, repo_path)
¶
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
|
var_name
|
str
|
Name of the environment variable if
|
'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 |
has_nvidia_container_toolkit()
¶
Checks if the NVIDIA Container Toolkit is installed and configured.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
|
has_nvidia_gpu()
¶
Checks if an NVIDIA GPU is available on the system by running nvidia-smi.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
|
run_command(command_list, *, cwd=None, check=True, shell=False, stream=True)
¶
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
|
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 |
Raises:
Type | Description |
---|---|
CalledProcessError
|
If command raises an error and
|
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
¶
StartRequest
¶
Bases: BaseModel
Format of request to launch the mirumoji application
with api/start
endpoint
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gpu
|
bool
|
If |
required |
local
|
bool
|
If |
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 |
required |
MIRUMOJI_MODAL_GPU
|
str
|
Which GPU to request Modal. Defaults
to |
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 |
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 |
required |
Returns:
Name | Type | Description |
---|---|---|
StreamingResponse |
StreamingResponse
|
Docker command's stdout |
check_docker()
¶
has_gpu()
¶
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 |
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 |
required |
Returns:
Name | Type | Description |
---|---|---|
StreamingResponse |
StreamingResponse
|
Docker command's stdout |