feat: add phoenix & trigger.dev

This commit is contained in:
Sun-ZhenXing
2025-12-09 15:19:11 +08:00
parent 0b11022ef8
commit 8f30f94184
20 changed files with 1726 additions and 617 deletions

31
src/phoenix/.env.example Normal file
View File

@@ -0,0 +1,31 @@
# Phoenix version
PHOENIX_VERSION=version-12.19.0
# Timezone
TZ=UTC
# Phoenix ports
PHOENIX_PORT_OVERRIDE=6006 # UI and OTLP HTTP collector
PHOENIX_GRPC_PORT_OVERRIDE=4317 # OTLP gRPC collector
# Phoenix configuration
PHOENIX_ENABLE_PROMETHEUS=false
PHOENIX_SECRET= # Optional: Set for authentication, generate with: openssl rand -base64 32
# PostgreSQL configuration
POSTGRES_VERSION=17.2-alpine3.21
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=phoenix
# Resource limits for Phoenix
PHOENIX_CPU_LIMIT=2.0
PHOENIX_MEMORY_LIMIT=2G
PHOENIX_CPU_RESERVATION=0.5
PHOENIX_MEMORY_RESERVATION=512M
# Resource limits for PostgreSQL
PHOENIX_DB_CPU_LIMIT=1.0
PHOENIX_DB_MEMORY_LIMIT=1G
PHOENIX_DB_CPU_RESERVATION=0.25
PHOENIX_DB_MEMORY_RESERVATION=256M

100
src/phoenix/README.md Normal file
View File

@@ -0,0 +1,100 @@
# Arize Phoenix
[English](./README.md) | [中文](./README.zh.md)
Arize Phoenix is an open-source AI observability platform for LLM applications. It provides tracing, evaluation, datasets, and experiments to help you build and improve AI applications.
## Services
- `phoenix`: The main Phoenix application server with UI and OpenTelemetry collectors.
- `phoenix-db`: PostgreSQL database for persistent storage.
## Ports
| Port | Protocol | Description |
| ---- | -------- | ----------------------------------------- |
| 6006 | HTTP | UI and OTLP HTTP collector (`/v1/traces`) |
| 4317 | gRPC | OTLP gRPC collector |
## Environment Variables
| Variable Name | Description | Default Value |
| -------------------------- | ------------------------------------- | ----------------- |
| PHOENIX_VERSION | Phoenix image version | `version-12.19.0` |
| PHOENIX_PORT_OVERRIDE | Host port for Phoenix UI and HTTP API | `6006` |
| PHOENIX_GRPC_PORT_OVERRIDE | Host port for OTLP gRPC collector | `4317` |
| PHOENIX_ENABLE_PROMETHEUS | Enable Prometheus metrics endpoint | `false` |
| PHOENIX_SECRET | Secret for authentication (optional) | `""` |
| POSTGRES_VERSION | PostgreSQL image version | `17.2-alpine3.21` |
| POSTGRES_USER | PostgreSQL username | `postgres` |
| POSTGRES_PASSWORD | PostgreSQL password | `postgres` |
| POSTGRES_DB | PostgreSQL database name | `phoenix` |
## Volumes
- `phoenix_db_data`: PostgreSQL data volume for persistent storage.
## Getting Started
1. Copy the example environment file:
```bash
cp .env.example .env
```
2. (Optional) For production, set a secure password and secret:
```bash
# Generate a secret for authentication
openssl rand -base64 32
```
3. Start the services:
```bash
docker compose up -d
```
4. Access Phoenix UI at `http://localhost:6006`
## Sending Traces
Phoenix supports OpenTelemetry-compatible traces. You can send traces using:
### HTTP (OTLP)
Send traces to `http://localhost:6006/v1/traces`
### gRPC (OTLP)
Send traces to `localhost:4317`
### Python Example
```python
from phoenix.otel import register
tracer_provider = register(
project_name="my-llm-app",
endpoint="http://localhost:6006/v1/traces",
)
```
## Features
- **Tracing**: Capture and visualize LLM application traces with OpenTelemetry support.
- **Evaluation**: Run evaluations using built-in or custom evaluators.
- **Datasets**: Create and manage datasets for testing and evaluation.
- **Experiments**: Run experiments to compare model performance.
- **Playground**: Test prompts with different models interactively.
## Documentation
For more information, visit the [official Phoenix documentation](https://docs.arize.com/phoenix).
## Security Notes
- Change default PostgreSQL password in production.
- Set `PHOENIX_SECRET` for authentication if exposing Phoenix publicly.
- Consider using a reverse proxy with SSL/TLS in production.
- Regularly backup the PostgreSQL database.

100
src/phoenix/README.zh.md Normal file
View File

@@ -0,0 +1,100 @@
# Arize Phoenix
[English](./README.md) | [中文](./README.zh.md)
Arize Phoenix 是一个开源的 AI 可观测性平台,专为 LLM 应用设计。它提供追踪、评估、数据集和实验功能,帮助你构建和改进 AI 应用。
## 服务
- `phoenix`Phoenix 主应用服务器,包含 UI 和 OpenTelemetry 采集器。
- `phoenix-db`:用于持久化存储的 PostgreSQL 数据库。
## 端口
| 端口 | 协议 | 描述 |
| ---- | ---- | -------------------------------------- |
| 6006 | HTTP | UI 和 OTLP HTTP 采集器(`/v1/traces` |
| 4317 | gRPC | OTLP gRPC 采集器 |
## 环境变量
| 变量名 | 描述 | 默认值 |
| -------------------------- | --------------------------------- | ----------------- |
| PHOENIX_VERSION | Phoenix 镜像版本 | `version-12.19.0` |
| PHOENIX_PORT_OVERRIDE | Phoenix UI 和 HTTP API 的主机端口 | `6006` |
| PHOENIX_GRPC_PORT_OVERRIDE | OTLP gRPC 采集器的主机端口 | `4317` |
| PHOENIX_ENABLE_PROMETHEUS | 启用 Prometheus 指标端点 | `false` |
| PHOENIX_SECRET | 认证密钥(可选) | `""` |
| POSTGRES_VERSION | PostgreSQL 镜像版本 | `17.2-alpine3.21` |
| POSTGRES_USER | PostgreSQL 用户名 | `postgres` |
| POSTGRES_PASSWORD | PostgreSQL 密码 | `postgres` |
| POSTGRES_DB | PostgreSQL 数据库名 | `phoenix` |
## 数据卷
- `phoenix_db_data`PostgreSQL 数据卷,用于持久化存储。
## 快速开始
1. 复制示例环境文件:
```bash
cp .env.example .env
```
2. (可选)生产环境下,请设置安全的密码和密钥:
```bash
# 生成认证密钥
openssl rand -base64 32
```
3. 启动服务:
```bash
docker compose up -d
```
4. 访问 Phoenix UI`http://localhost:6006`
## 发送追踪数据
Phoenix 支持 OpenTelemetry 兼容的追踪数据。你可以通过以下方式发送追踪:
### HTTPOTLP
发送追踪到 `http://localhost:6006/v1/traces`
### gRPCOTLP
发送追踪到 `localhost:4317`
### Python 示例
```python
from phoenix.otel import register
tracer_provider = register(
project_name="my-llm-app",
endpoint="http://localhost:6006/v1/traces",
)
```
## 功能特性
- **追踪**:捕获和可视化 LLM 应用追踪,支持 OpenTelemetry。
- **评估**:使用内置或自定义评估器运行评估。
- **数据集**:创建和管理用于测试和评估的数据集。
- **实验**:运行实验以比较模型性能。
- **Playground**:交互式测试不同模型的提示词。
## 文档
更多信息请访问 [Phoenix 官方文档](https://docs.arize.com/phoenix)。
## 安全说明
- 生产环境请更改默认的 PostgreSQL 密码。
- 如果公开暴露 Phoenix请设置 `PHOENIX_SECRET` 进行认证。
- 生产环境建议使用反向代理并启用 SSL/TLS。
- 定期备份 PostgreSQL 数据库。

View File

@@ -0,0 +1,68 @@
# Arize Phoenix - AI Observability and Evaluation Platform
# https://docs.arize.com/phoenix
x-defaults: &defaults
restart: unless-stopped
logging:
driver: json-file
options:
max-size: 100m
max-file: "3"
services:
phoenix:
<<: *defaults
image: ${GLOBAL_REGISTRY:-}arizephoenix/phoenix:${PHOENIX_VERSION:-version-12.19.0}
ports:
- "${PHOENIX_PORT_OVERRIDE:-6006}:6006" # UI and OTLP HTTP collector
- "${PHOENIX_GRPC_PORT_OVERRIDE:-4317}:4317" # OTLP gRPC collector
environment:
- TZ=${TZ:-UTC}
- PHOENIX_SQL_DATABASE_URL=postgresql://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@phoenix-db:5432/${POSTGRES_DB:-phoenix}
- PHOENIX_ENABLE_PROMETHEUS=${PHOENIX_ENABLE_PROMETHEUS:-false}
- PHOENIX_SECRET=${PHOENIX_SECRET:-}
depends_on:
phoenix-db:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:6006/healthz"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
deploy:
resources:
limits:
cpus: ${PHOENIX_CPU_LIMIT:-2.0}
memory: ${PHOENIX_MEMORY_LIMIT:-2G}
reservations:
cpus: ${PHOENIX_CPU_RESERVATION:-0.5}
memory: ${PHOENIX_MEMORY_RESERVATION:-512M}
phoenix-db:
<<: *defaults
image: ${GLOBAL_REGISTRY:-}postgres:${POSTGRES_VERSION:-17.2-alpine3.21}
environment:
- TZ=${TZ:-UTC}
- POSTGRES_USER=${POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres}
- POSTGRES_DB=${POSTGRES_DB:-phoenix}
volumes:
- phoenix_db_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres}"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
deploy:
resources:
limits:
cpus: ${PHOENIX_DB_CPU_LIMIT:-1.0}
memory: ${PHOENIX_DB_MEMORY_LIMIT:-1G}
reservations:
cpus: ${PHOENIX_DB_CPU_RESERVATION:-0.25}
memory: ${PHOENIX_DB_MEMORY_RESERVATION:-256M}
volumes:
phoenix_db_data: