Repository navigation
48 lines (44 loc) · 2.22 KB
/
Copy pathpricing.yml
File metadata and controls
48 lines (44 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 价目表会不会已经过期了。
#
# **这是个提醒,不是一道关卡**。真正的关卡是
# `tw-pricing` 里那条比对测试 —— 它每次 CI 都跑,对不上就红。
#
# 这个 workflow 只回答另一个问题:**内置快照放了多久了。**任何第三方
# 数据源都会滞后,而一份三个月前的快照算出来的「今日花费」,和一份上周
# 的,可信度完全不同。
name: Pricing freshness
on:
schedule:
# 每周一早上看一眼
- cron: "0 1 * * 1"
workflow_dispatch:
jobs:
staleness:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: How old is the bundled snapshot
run: |
set -euo pipefail
SNAP=$(grep -oE 'Snapshot date \| [0-9-]+' crates/tw-pricing/data/PROVENANCE.md | grep -oE '[0-9-]+$')
AGE=$(( ( $(date +%s) - $(date -d "$SNAP" +%s) ) / 86400 ))
echo "Bundled snapshot: $SNAP ($AGE days old)"
# 上游那份文件几乎天天在动,但价格变动是月级的。30 天是个
# 「该看一眼了」的信号,不是「一定过期了」。
if [ "$AGE" -gt 30 ]; then
echo "::warning::The bundled price table is $AGE days old. Steps to refresh it are in crates/tw-pricing/data/PROVENANCE.md"
fi
- name: Does upstream have a newer revision
run: |
set -euo pipefail
PINNED=$(grep -oE '`[0-9a-f]{40}`' crates/tw-pricing/data/PROVENANCE.md | tr -d '`' | head -1)
LATEST=$(curl -sS "https://api.github.com/repos/BerriAI/litellm/commits?path=model_prices_and_context_window.json&per_page=1" \
| python3 -c 'import json,sys; print(json.load(sys.stdin)[0]["sha"])')
echo "pinned: $PINNED"
echo "upstream: $LATEST"
if [ "$PINNED" != "$LATEST" ]; then
# **不自动更新。**pin 到具体的 commit,不要用 main ——
# 自动跟随意味着两次构建可能拿到不同的价格,而「昨天算出来的
# 钱和今天不一样」是没法解释的。
echo "::warning::Upstream has a newer revision. To take it, follow PROVENANCE.md and re-verify verified.yaml against the vendors' own pricing pages"
fi