Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ace
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ACE_LOGGER_VERBOSE_ENV="."
# STARTUP
run_tests() {
echo "Installing/Updating test dependencies..."
pip install --upgrade -r app/requirements
pip install --upgrade -r tests/requirements

python -m pytest tests/unit/ -v
Expand Down
1 change: 1 addition & 0 deletions app/components/controller/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .routes import controller_api
72 changes: 72 additions & 0 deletions app/components/controller/api/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# DEPENDENCIES
## Third-Party
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from http import HTTPStatus
from pydantic import ValidationError
## Local
from constants import Defaults, DefaultAPIResponseSchema, Names
from logger import logger
from . import service
from .schemas import (
EditSettingsRequest,
GetSettingsResponse, GetVersionDetailsResponse
)


controller_api = FastAPI()
controller_api.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:4200"], # Allow requests from your Angular app
allow_credentials=True,
allow_methods=["*"], # Allow all HTTP methods
allow_headers=["*"], # Allow all headers
)


# ROUTES
@controller_api.get(
"/settings",
response_model=GetSettingsResponse,
description=f"Get the {Names.ACE} controller settings data"
)
async def get_settings_route() -> dict:
try:
return service.get_settings_data()
except ValidationError as error:
logger.error(error)
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail="Settings data error!")
except Exception as error:
logger.error(error)
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=Defaults.INTERNAL_SERVER_ERROR_MESSAGE)

@controller_api.post(
"/settings",
response_model=DefaultAPIResponseSchema,
description=f"Edit the {Names.ACE} controller settings data"
)
async def set_settings_route(updated_settings: EditSettingsRequest) -> dict:
try:
service.edit_settings_data(updated_settings=updated_settings.dict())
return DefaultAPIResponseSchema(message="Settings data updated successfully!")
except ValidationError as error:
logger.error(error)
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail="Settings data error!")
except Exception as error:
logger.error(error)
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=Defaults.INTERNAL_SERVER_ERROR_MESSAGE)

@controller_api.get(
"/version",
response_model=GetVersionDetailsResponse,
description=f"Get the {Names.ACE}'s version data"
)
async def get_version_route() -> dict:
try:
return service.get_version_data()
except ValidationError as error:
logger.error(error)
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail="Version data error!")
except Exception as error:
logger.error(error)
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=Defaults.INTERNAL_SERVER_ERROR_MESSAGE)
26 changes: 26 additions & 0 deletions app/components/controller/api/schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# DEPENDENCIES
## Third-Party
from pydantic import BaseModel, validator
## Local
from constants import Defaults


class SettingsSchema(BaseModel):
# These are not required
ace_name: str = Defaults.ACE_NAME
model_provider: str = Defaults.MODEL_PROVIDER
temperature: float = Defaults.TEMPERATURE

@validator("temperature")
def validate_temperature(cls, value):
return min(max(0.0, value), 1.0)


# REQUESTS
EditSettingsRequest: type[BaseModel] = SettingsSchema

# RESPONSES
GetSettingsResponse: type[BaseModel] = SettingsSchema

class GetVersionDetailsResponse(BaseModel):
version: str
34 changes: 34 additions & 0 deletions app/components/controller/api/service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# DEPENDENCIES
## Built-In
import json
## Local
from constants import DictKeys, Files, ModelProviders


# HELPERS
def _get_settings() -> dict:
settings: dict = {}
with open(Files.CONTROLLER_SETTINGS, "r", encoding="utf-8") as settings_file:
settings = json.loads(settings_file.read())
return settings


# ROUTES
def get_settings_data() -> dict:
return _get_settings()

def edit_settings_data(updated_settings: dict):
settings: dict = _get_settings()
new_model_provider: str | None = updated_settings.get(DictKeys.MODEL_PROVIDER)
if new_model_provider:
available_model_providers: dict = ModelProviders.get_frozenset()
if new_model_provider not in available_model_providers:
raise ValueError(f"Invalid model provider: {new_model_provider}")
settings.update(updated_settings)
with open(Files.CONTROLLER_SETTINGS, "w", encoding="utf-8") as settings_file:
settings_file.write(json.dumps(settings))

def get_version_data() -> dict:
with open(Files.VERSION, "r", encoding="utf-8") as settings_file:
return json.loads(settings_file.read())

17 changes: 17 additions & 0 deletions app/components/controller/start.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
# DEPENDENCIES
## Built-In
import json
## Third-Party
import uvicorn
## Local
from constants import NetworkPorts
from logger import logger
from .api import controller_api, service
from .api.schemas import SettingsSchema
from constants import Files


def _ensure_settings() -> dict:
settings: dict = service._get_settings()
settings = SettingsSchema(**settings).dict()
with open(Files.CONTROLLER_SETTINGS, "w", encoding="utf-8") as settings_file:
settings_file.write(json.dumps(settings))

def start_controller(component_type: str, dev: bool) -> None:
logger.startup(f"Starting {component_type}...")
_ensure_settings()
uvicorn.run(controller_api, host="0.0.0.0", port=int(NetworkPorts.CONTROLLER))
86 changes: 86 additions & 0 deletions app/components/ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions app/components/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "ui",
"name": "ACE",
"version": "0.0.0",
"scripts": {
"ng": "ng",
Expand All @@ -21,6 +21,12 @@
"@angular/platform-browser": "^19.1.0",
"@angular/platform-browser-dynamic": "^19.1.0",
"@angular/router": "^19.1.0",
"@ngrx/component": "^19.0.1",
"@ngrx/data": "^19.0.1",
"@ngrx/effects": "^19.0.1",
"@ngrx/entity": "^19.0.1",
"@ngrx/store": "^19.0.1",
"@ngrx/store-devtools": "^19.0.1",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.15.0"
Expand All @@ -38,4 +44,4 @@
"karma-jasmine-html-reporter": "~2.1.0",
"typescript": "~5.7.2"
}
}
}
5 changes: 5 additions & 0 deletions app/components/ui/src/app/api.urls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const defaultClusterURL: string = `http://127.0.0.1`;

export const serviceURLs = {
controller: defaultClusterURL + ":2349"
};
2 changes: 1 addition & 1 deletion app/components/ui/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<ace-sidebar></ace-sidebar>
<ace-rootpage></ace-rootpage>
25 changes: 16 additions & 9 deletions app/components/ui/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { ACESidebarComponent } from './components/sidebar/sidebar.component';
import { Component, OnInit } from "@angular/core";
import { Store } from "@ngrx/store";
import { appActions } from "./store/actions/app.actions";
import { ACERootpageComponent } from "./components/rootpage/rootpage.component";

@Component({
selector: 'app-root',
selector: "app-root",
imports: [
ACESidebarComponent
ACERootpageComponent
],
templateUrl: './app.component.html',
styleUrl: './app.component.scss'
templateUrl: "./app.component.html",
styleUrl: "./app.component.scss"
})
export class AppComponent {
title = 'ACE';
export class AppComponent implements OnInit {
title = "ACE";

constructor(private store: Store) {}

ngOnInit(): void {
this.store.dispatch(appActions.getACEVersionData());
}
}
20 changes: 18 additions & 2 deletions app/components/ui/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { provideHttpClient } from '@angular/common/http';
import { provideRouter } from '@angular/router';

import { provideEffects } from '@ngrx/effects';
import { provideStore } from '@ngrx/store';
import { provideStoreDevtools } from '@ngrx/store-devtools';
import { routes } from './app.routes';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import { AppEffects } from './store/effects/app.effects';
import { appReducer } from './store/reducers/app.reducers';

export const appConfig: ApplicationConfig = {
providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes), provideAnimationsAsync()]
providers: [
provideAnimationsAsync(),
provideEffects([AppEffects]),
provideHttpClient(),
provideStore({ app_data: appReducer }),
provideStoreDevtools({
maxAge: 25,
logOnly: false
}),
provideRouter(routes),
provideZoneChangeDetection({ eventCoalescing: true })
]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<footer class="footer">
<p>Developed by JayFalls</p>
<p>Version: v{{ version }}</p>
</footer>


Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.footer {
display: flex;
align-items: center;
justify-content: center;
height: 2rem;
gap: 2rem;
outline: auto;
}
Loading
Loading