支持两种工作流:
Streamlit UI(app.py):用于交互式运行与分析
无界面运行器(headless_runner.py):用于定时与自动化任务
目标是在多个 LLM 上运行同一条提示词,并以标准化格式对比输出,同时进行长期存储与历史记录留存。
技术栈
- Python 3.10+
- Streamlit
- Bright Data 抓取工具 API
- Supabase
前置条件
推荐使用 Python 3.10+
拥有 Bright Data 账号并开通 Web Scraper API 访问权限
拥有 Supabase 账号与项目
安装配置
1) 创建并激活虚拟环境
Linux / macOS:
python -m venv .venv
source .venv/bin/activate
Windows(PowerShell):
python -m venv .venv
..venvScriptsActivate.ps1
2) 安装依赖
pip install -r requirements.txt
3) 配置环境变量
在项目根目录创建 .env 文件:
BRIGHTDATA_API_TOKEN=your_brightdata_api_token_here
SUPABASE_URL=your_supabase_project_url
SUPABASE_API_TOKEN=your_supabase_api_key
这些凭据用于数据库持久化与定时调度,必不可少。
4) 创建数据库
在 Supabase 中创建 llm_runs 表。
create table public.llm_runs (
id bigint generated by default as identity primary key,
created_at_ts bigint not null, -- unix seconds
model_name text not null,
prompt text not null,
country text null,
target_phrase text null,
mentioned boolean not null default false,
payload jsonb not null
);
create index if not exists llm_runs_created_at_ts_idx
on public.llm_runs (created_at_ts);
create index if not exists llm_runs_model_idx
on public.llm_runs (model_name);
create index if not exists llm_runs_target_idx
on public.llm_runs (target_phrase);
创建 prompts 表。
create table public.prompts (
id bigint generated by default as identity primary key,
created_at_ts bigint not null,
prompt text not null,
is_active boolean not null default true
);
create index if not exists prompts_created_at_ts_idx
on public.prompts (created_at_ts desc);
create index if not exists prompts_active_idx
on public.prompts (is_active);
创建 schedules 表。
create table public.schedules (
id bigint generated by default as identity primary key,
name text not null,
is_enabled boolean not null default true,
next_run_ts bigint not null,
last_run_ts bigint null,
models jsonb not null default '[]'::jsonb,
country text null,
target_phrase text null,
only_active_prompts boolean not null default true,
locked_until_ts bigint null,
lock_owner text null,
repeat_every_seconds bigint not null default 86400
);
create index if not exists schedules_due_idx
on public.schedules (is_enabled, next_run_ts);
create index if not exists schedules_lock_idx
on public.schedules (locked_until_ts);
启动应用
启动无界面运行器
打开一个终端并运行:
python headless_runner.py
该进程负责处理定时任务与数据库持久化。
启动 Streamlit UI
打开第二个终端并运行:
streamlit run app.py
UI 用于交互式运行、报表查看与计划任务管理。
备注
- 通过 Bright Data 使用基于快照的轮询
- 结果由 Bright Data 进行标准化处理
- 所有运行记录都会持久化到 Supabase
- 失败会按模型进行隔离处理
- UI 与无界面运行器被设计为可并行运行