Metadata-Version: 2.4
Name: ai-library-swch
Version: 0.1.2
Summary: AI helper utilities and models
Requires-Python: ==3.12.3
Description-Content-Type: text/markdown
Requires-Dist: annotated-types==0.7.0
Requires-Dist: anyio==4.13.0
Requires-Dist: cloudpathlib==0.24.0
Requires-Dist: cloudpickle==3.1.2
Requires-Dist: confection==1.3.3
Requires-Dist: durationpy==0.10
Requires-Dist: fastai==2.8.7
Requires-Dist: fastcore==1.13.2
Requires-Dist: fastprogress==1.1.6
Requires-Dist: httpcore==1.0.9
Requires-Dist: matplotlib==3.11.0
Requires-Dist: mpmath==1.3.0
Requires-Dist: numpy==2.4.6
Requires-Dist: pandas==3.0.3
Requires-Dist: preshed==3.0.13
Requires-Dist: pyarrow==24.0.0
Requires-Dist: pydantic_core==2.46.4
Requires-Dist: PyYAML==6.0.3
Requires-Dist: requests==2.34.2
Requires-Dist: requests-oauthlib==2.0.0
Requires-Dist: scikit-learn==1.7.2
Requires-Dist: setuptools==81.0.0
Requires-Dist: swchmonclient==0.2.0
Requires-Dist: threadpoolctl==3.6.0
Requires-Dist: torch==2.12.0
Requires-Dist: torchaudio==2.11.0
Requires-Dist: torchvision==0.27.0
Requires-Dist: tsai==1.0.1
Requires-Dist: typing-inspection==0.4.2
Requires-Dist: typing_extensions==4.15.0
Requires-Dist: xgboost==3.2.0

# ai_library

`ai_library` is a Python package that exposes model training, inference, metrics recording, cron scheduling, and package-based configuration management.

## Package Overview

### Available Top-Level APIs

- `ai_library.validate_config(config_path=None)`
  - Loads and validates the package default `ai_library/config.yaml` if no path is provided.
  - Returns the parsed configuration dictionary.

- `ai_library.update_config(config_path=None, updates=...)`
  - Updates the package config file by default.
  - Supports a dictionary, a `[key, value]` pair, or a list of `[key, value]` pairs.

- `ai_library.show_config(config_path=None)`
  - Prints the current configuration to stdout.

- `ai_library.train()`
  - Loads configuration from the package config.
  - Reads data, builds the selected pipeline, and trains the model.

- `ai_library.infer()`
  - Loads package configuration.
  - Loads a saved model and performs inference.
  - returns predictions, first_predicted, last_predicted, data_frequency, conformal_q 
  - conformal_q is the safety margin in order to be 1-alpha accurate for the predicted time window

- `ai_library.record`
  - Use `ai_library.record.main()` or run the module directly to start metric collection.

- `ai_library.add_to_cron()` / `ai_library.remove_from_cron()`
  - Manage cron scheduling for recurring training runs.
  - Adds or removes a cron job that runs `python3 -m ai_library.codebase.setup.train`.

## How to Use

### Install
```bash
pip install ai-library-swch==0.1.1 
```
a safe python version is 3.12.3

### Configuration
this is an example of how config can be printed and updated.
```python
from ai_library import validate_config, update_config, show_config

update_config(None, updates=["parquet_train_size", 100000])
show_config()
validate_config()
```

### Metric Recorder Function
Make sure that `.env` is reachable in the folder where this is executed, and that the specified port is reachable.
Sample `.env` configuration:
```python
MON_CLIENT_STOMP_HOST=127.0.0.1
MON_CLIENT_STOMP_PORT=61622
```
Execution command:
```bash
nohup python3 -c "from ai_library import record; record.main()" > record.log 2>&1 &
```
nohup is not necessary, but make sure to run the recorder in the background. 

### Train and Infer
import the functions:
```python
from ai_library import train, infer
```

# Manually use train (no cron)
the standard way is to use the cron functions to train in intervals. This might still be useful, for example when switching models.
```python
train()
```

### Cron Scheduling
add_to_cron creates a cron job that runs the train function in intervals.
```python
import ai_library.codebase.setup.cron_manager as cron_manager

cron_manager.add_to_cron()
cron_manager.remove_from_cron()
```

# Inference
after a trained model is accessible via the path, that is given in the config file, inference can be applied:
```python
predictions, first_predicted, last_predicted, data_frequency, conformal_q = infer()
```
