Skip to content

Commit e8a5be8

Browse files
authored
Use async function across tests (#190)
* remove unused code Signed-off-by: kerthcet <kerthcet@gmail.com> * use async function across tests Signed-off-by: kerthcet <kerthcet@gmail.com> * update tests Signed-off-by: kerthcet <kerthcet@gmail.com> * fix lint Signed-off-by: kerthcet <kerthcet@gmail.com> * update test Signed-off-by: kerthcet <kerthcet@gmail.com> * Add comments Signed-off-by: kerthcet <kerthcet@gmail.com> * update readme.md * fix lint Signed-off-by: kerthcet <kerthcet@gmail.com> * release v0.2.0 Signed-off-by: kerthcet <kerthcet@gmail.com> * fix test Signed-off-by: kerthcet <kerthcet@gmail.com> --------- Signed-off-by: kerthcet <kerthcet@gmail.com>
1 parent f2206bd commit e8a5be8

7 files changed

Lines changed: 215 additions & 197 deletions

File tree

README.md

Lines changed: 62 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,123 +6,121 @@
66
</p>
77

88
<h3 align="center">
9-
Open, modular framework to build GenAI applications.
9+
Open, modular framework to build and optimize GenAI applications
1010
</h3>
1111

1212
[![stability-alpha](https://img.shields.io/badge/stability-alpha-f4d03f.svg)](https://github.com/mkenney/software-guides/blob/master/STABILITY-BADGES.md#alpha)
1313
[![Latest Release](https://img.shields.io/github/v/release/inftyai/alphatrion?include_prereleases)](https://github.com/inftyai/alphatrion/releases/latest)
1414

15-
**AlphaTrion** is an open-source framework to help build GenAI applications, including experiment tracking, adaptive model routing, prompt optimization, performance evaluation and so on. The name comes after the oldest and wisest Transformer - AlphaTrion.
15+
**AlphaTrion** is an open-source framework for building and optimizing GenAI applications. Track experiments, monitor performance, analyze model usage, and manage artifacts—all through an intuitive dashboard. Named after the oldest and wisest Transformer.
1616

17-
*Still under active development.*
17+
*Currently in active development.*
1818

19-
## Concepts
19+
## Features
2020

21-
- **Team**: A Team is the highest-level organizational unit in AlphaTrion. It represents a group of users collaborating on experiments.
22-
- **Experiment**: An Experiment is a logic-level abstraction for organizing and managing a series of related runs. It allows users to group runs that share a common purpose or configuration. Experiments can be organized using labels.
23-
- **Run**: A Run is a real execution instance of an experiment. It represents the actual execution of the code with the specified configuration and hyperparameters defined in the experiment.
21+
- **🔬 Experiment Tracking** - Organize and manage ML experiments with hierarchical teams, experiments, and runs
22+
- **📊 Performance Monitoring** - Track metrics, visualize trends, and monitor experiment status in real-time
23+
- **🔍 Distributed Tracing** - Automatic OpenTelemetry integration for LLM calls with detailed span analysis
24+
- **💰 Token Usage Analytics** - Monitor daily token consumption across input/output with historical trends
25+
- **🤖 Model Distribution** - Analyze request patterns and usage across different AI models
26+
- **📦 Artifact Management** - Store and version execution results, checkpoints, and model outputs
27+
- **🎯 Interactive Dashboard** - Modern web UI for exploring experiments, metrics, and traces
28+
- **🔌 Easy Integration** - Simple Python API with async/await support
29+
30+
## Core Concepts
31+
32+
- **Team** - Top-level organizational unit for user collaboration
33+
- **Experiment** - Logical grouping of runs with shared purpose, organized by labels
34+
- **Run** - Individual execution instance with configuration and metrics
2435

2536
## Quick Start
2637

27-
### Install from PyPI
38+
### 1. Installation
2839

2940
```bash
41+
# From PyPI
3042
pip install alphatrion
31-
```
32-
33-
### Install from Source
34-
35-
* Git clone the repository
36-
* Run `source start.sh` to activate the virtual environment.
37-
3843

39-
### Initialize the Environment
40-
41-
Run the following command for setup:
42-
43-
```bash
44-
cp .env.example .env & make up
44+
# Or from source
45+
git clone https://github.com/inftyai/alphatrion.git && cd alphatrion
46+
source start.sh
4547
```
46-
You can login to pgAdmin at `http://localhost:8081` to see the Postgres database with following credentials. Remember to register the server first.
47-
48-
```shell
49-
Email: alphatrion@inftyai.com
50-
Password: alphatr1on
51-
ServerName: alphatrion
52-
HostName: postgres
53-
ServerPWD: alphatr1on
54-
```
55-
56-
You can also visit the Docker Registry UI at `http://localhost:80` to see the local registry where the built images are stored.
5748

58-
Next, init the environment with a user and team:
49+
### 2. Setup Infrastructure
5950

6051
```bash
61-
alphatrion init # see -h for options to specify username, email and team name
52+
# Start PostgreSQL, ClickHouse, and Registry
53+
cp .env.example .env
54+
make up
55+
56+
# Initialize your team and user
57+
alphatrion init # Use -h for custom options
6258
```
6359

64-
You will see the generated user ID in the console. Use this ID to initialize the AlphaTrion environment in your code later.
60+
Save the generated user ID—you'll need it to track experiments.
6561

66-
### Run a Simple Experiment
62+
**Optional Tools:**
63+
- pgAdmin: `http://localhost:8081` (alphatrion@inftyai.com / alphatr1on)
64+
- Registry UI: `http://localhost:80`
6765

68-
Below is a simple example with two approaches demonstrating how to create an experiment and log performance metrics.
66+
### 3. Track Your First Experiment
6967

7068
```python
7169
import alphatrion as alpha
7270
from alphatrion import experiment
7371

74-
# Use the user ID generated from the `alphatrion init` command.
75-
alpha.init(user_id=<user_id>)
72+
# Initialize with your user ID
73+
alpha.init(user_id="<your_user_id>")
7674

77-
async def your_task():
78-
# Run your code here then log metrics.
79-
await alpha.log_metrics({"accuracy": 0.95})
75+
async def my_task():
76+
# Your ML code here
77+
await alpha.log_metrics({"accuracy": 0.95, "loss": 0.12})
8078

8179
async with experiment.CraftExperiment.start(name="my_experiment") as exp:
82-
task = exp.run(your_task) # use lambda or partial if you need to pass arguments to your_task
83-
await task.wait()
80+
task = exp.run(my_task)
81+
await task.wait()
8482
```
8583

86-
### View Dashboard
87-
88-
![dashboard](./site/images/dashboard.png)
89-
90-
The dashboard provides a web interface to explore experiments, runs, and metrics through an intuitive UI.
91-
92-
#### Launch Dashboard
84+
### 4. Launch Dashboard
9385

9486
```bash
95-
# Start the backend server (in one terminal)
87+
# Start backend server (terminal 1)
9688
alphatrion server
9789

98-
# Launch the dashboard (in another terminal)
90+
# Launch dashboard (terminal 2)
9991
alphatrion dashboard
10092
```
10193

102-
The dashboard will automatically open in your browser at `http://127.0.0.1:5173`.
103-
104-
**Options:**
105-
- `--port <PORT>`: Run on a custom port (default: 5173)
94+
Access the dashboard at `http://127.0.0.1:5173` to explore experiments, visualize metrics, and analyze traces.
10695

107-
**Documentation:**
108-
- [Dashboard Setup Guide](./docs/dashboard/setup.md) - Complete setup and troubleshooting guide
109-
- [Dashboard CLI Guide](./docs/dashboard/dashboard-cli.md) - Using the dashboard CLI command
110-
- [Dashboard Architecture](./docs/dashboard/dashboard-architecture.md) - Technical architecture and deployment patterns
96+
![dashboard](./site/images/dashboard.png)
11197

112-
### Tracing
98+
### 5. View Traces
11399

114-
AlphaTrion automatically captures tracing data for all runs, including spans for each run and associated metadata. You can query this data to analyze model performance, latency, and token usage.
100+
AlphaTrion automatically captures distributed tracing data for all LLM calls, including latency, token usage, and span relationships.
115101

116102
![tracing](./site/images/trace.png)
117103

104+
### 6. Other APIs
105+
106+
- **log_params**: Track hyperparameters and configuration settings
107+
- **log_metrics**: Record performance metrics and visualize trends
108+
- **log_artifacts**: Store and manage files, checkpoints, and model outputs
109+
110+
118111
### Cleanup
119112

120113
```bash
121114
make down
122115
```
123116

117+
## Documentation
118+
119+
- **Dashboard**: [Setup Guide](./docs/dashboard/setup.md) | [CLI Reference](./docs/dashboard/dashboard-cli.md) | [Architecture](./docs/dashboard/dashboard-architecture.md)
120+
- **Development**: [Contributing Guide](./docs/dev/development.md)
121+
124122
## Contributing
125123

126-
We welcome contributions! Please refer to [developer.md](./docs/dev/development.md) for more information on how to set up your development environment and contribute to the project.
124+
We welcome contributions! Check out our [development guide](./docs/dev/development.md) to get started.
127125

128126
[![Star History Chart](https://api.star-history.com/svg?repos=inftyai/alphatrion&type=Date)](https://www.star-history.com/#inftyai/alphatrion&Date)

alphatrion/experiment/base.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
199199
current_exp_id.reset(self._token)
200200
self._runtime.current_experiment = None
201201

202+
self._cleanup_files()
203+
202204
def _start(
203205
self,
204206
name: str,
@@ -366,13 +368,8 @@ async def wait(self):
366368
def is_done(self) -> bool:
367369
return self._context.cancelled()
368370

369-
# done function should be called manually as a pair of start
370-
# FIXME: watch for system signals to cancel the Experiment gracefully,
371-
# or it could lead to experiment not being marked as completed.
372-
# TODO: Should we distinguish done and cancel?
373371
def done(self):
374372
self._cancel()
375-
self._cleanup()
376373

377374
def done_with_err(self):
378375
self._end_status = "Err"
@@ -462,7 +459,7 @@ def start(
462459
) -> "Experiment":
463460
raise NotImplementedError
464461

465-
def _cleanup(self):
462+
def _cleanup_files(self):
466463
# remove the whole folder once the experiment is done.
467464
if (
468465
os.path.exists(team_path())

alphatrion/log/log.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ async def log_artifact(
3030
If a folder is provided, all files in the folder will be logged.
3131
Don't support nested folders currently, only files in the first level
3232
of the folder will be logged.
33+
:param repo_name: the name of the repository to log the artifact to.
3334
:param version: the version (tag) to log the files
3435
:param pre_save_hook: a callable function to be called before saving the artifact.
3536
If want to save something, make sure it's under the paths.
@@ -63,9 +64,13 @@ async def log_artifact(
6364
)
6465

6566

66-
# log_params is used to save a set of parameters, which is a dict of key-value pairs.
67-
# should be called after starting a Experiment.
6867
async def log_params(params: dict):
68+
"""
69+
Log parameters to the database.
70+
Support in Experiment level currently, should be called after starting a Experiment.
71+
72+
:param params: a dict of key-value pairs to log as parameters.
73+
"""
6974
exp_id = current_exp_id.get()
7075
if exp_id is None:
7176
raise RuntimeError("log_params must be called inside a Experiment.")
@@ -78,14 +83,14 @@ async def log_params(params: dict):
7883
)
7984

8085

81-
# log_metrics is used to log a set of metrics at once,
82-
# metric key must be string, value must be float.
83-
# If save_on_best is enabled in the experiment config, and the metric is the best metric
84-
# so far, the experiment will checkpoint the current data.
85-
#
86-
# Note: log_metrics can only be called inside a Run, because it needs a run_id.
87-
# Return bool indicates whether the metric is the best metric.
8886
async def log_metrics(metrics: dict[str, float]) -> bool:
87+
"""
88+
Log metrics to the database.
89+
Support in Run level currently, should be called after starting a Run.
90+
91+
:param metrics: a dict of key-value pairs to log as metrics.
92+
:return: a bool indicating whether the metric is the best metric.
93+
"""
8994
run_id = current_run_id.get()
9095
if run_id is None:
9196
raise RuntimeError("log_metrics must be called inside a Run.")
@@ -150,6 +155,7 @@ async def log_metrics(metrics: dict[str, float]) -> bool:
150155
# including both input and output, e.g. you want to save the code snippet.
151156
# It will be stored in the object storage as a JSON file if object storage
152157
# is enabled or locally otherwise.
158+
# NOTE: will be deprecated in the v0.3.0, use log_dataset instead.
153159
async def log_result(
154160
output: dict[str, Any],
155161
input: dict[str, Any] | None = None,
@@ -196,3 +202,28 @@ async def log_result(
196202
}
197203
},
198204
)
205+
206+
207+
# log_records is used to log a list of records, which is similar to log_metrics
208+
# but for tracing the execution of the code.
209+
# async def log_records():
210+
211+
# log_dataset will store sometime in the artifacts als record in the database.
212+
# async def log_dataset(
213+
# name: str,
214+
# paths: str | list[str],
215+
# version: str | None = None,
216+
# ):
217+
# path = await log_artifact(
218+
# paths=paths,
219+
# repo_name="dataset",
220+
# version=version,
221+
# )
222+
223+
# runtime = global_runtime()
224+
# runtime.metadb.create_dataset(
225+
# name=name,
226+
# team_id=runtime._team_id,
227+
# path=path,
228+
# version=version,
229+
# )

alphatrion/server/graphql/types.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ def exps_by_timeframe(
6969
end_time=end_time,
7070
)
7171

72-
# @strawberry.field
73-
# def labels(self) -> list["Label"]:
74-
# from .resolvers import GraphQLResolvers
75-
76-
# return GraphQLResolvers.list_labels_by_team_id(team_id=self.id)
77-
7872

7973
@strawberry.type
8074
class User:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "alphatrion"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
description = "⚒️ AlphaTrion is an open-source framework to help build GenAI applications, including experiment tracking, adaptive model routing, prompt optimization and performance evaluation."
55
license = {text = "Apache-2.0"}
66
readme = "README.md"

site/images/dashboard.png

33.5 KB
Loading

0 commit comments

Comments
 (0)