|
1 | | -# 算命 · Divination Suite |
| 1 | +# Bazaar of Fates · 算命 Divination Suite |
2 | 2 |
|
3 | | -十一套傳統命理系統,寫成**確定性 Python 排盤引擎**,前面接一層 LLM 解讀,後面只吃一個輸入:**生辰**(出生日期+時辰+出生地)。 |
| 3 | +**Eleven traditional divination systems as deterministic Python engines**, behind one input — your **birth moment** (date + time + place) — each producing a reproducible chart plus an optional bilingual AI reading. |
4 | 4 |
|
5 | | -> 起源:本專案的排盤引擎源自一個更大的量化研究專案,原本是當作「對照組/安慰劑」(把命理當成 date-keyed 訊號,跑無未來函數回測證明它們是雜訊)。這裡把**排盤數學**單獨抽出來,去掉所有交易/回測,還原成它本來的用途——**幫人算命**。排盤數學以 `scripts/sync_from_main.sh` 從母專案同步(單一真相源),算命產品殼(生辰輸入、API、解讀、前端)是本 repo 原生。 |
| 5 | +**十一套傳統命理系統**,寫成確定性 Python 排盤引擎,只吃一個輸入:**生辰**(出生日期+時辰+出生地),各自排出可重現的命盤+可選的雙語 AI 解讀。 |
6 | 6 |
|
7 | | -## 十一系 |
| 7 | +> **Origin / 起源.** These engines began life as *placebo controls* in a larger quant project — divination cast as date-keyed trading signals, run through a lookahead-free backtest to prove they were noise. Here the **chart math is lifted out**, all trading/backtest stripped, and restored to its real purpose: **telling fortunes**. The 排盤 math is synced from the parent monorepo (single source of truth) via `scripts/sync_from_main.sh`; the product shell (birth input, API, readings, web) is native to this repo. |
| 8 | +> 這些引擎原本是某量化專案裡的「對照組/安慰劑」(把命理當訊號跑無未來函數回測,證明它們是雜訊)。這裡把排盤數學抽出、去掉交易回測,還原它本來的用途——算命。 |
8 | 9 |
|
9 | | -| key | 系統 | 引擎核心 | 時辰敏感 | 出生地敏感 | |
10 | | -|---|---|---|:--:|:--:| |
11 | | -| `astrology` | 西洋占星 | `ephem` 黃道經度 | 月相 | 規劃中(上升/宮位)| |
12 | | -| `bazi` | 八字(四柱)| JDN 校準干支 | ✅ 時柱 | — | |
13 | | -| `ziwei` | 紫微斗數 | 純 Python 排盤 | 規劃中(命宮)| — | |
14 | | -| `iching` | 梅花易數 | 時間起卦 | — | — | |
15 | | -| `suimei` | 四柱推命(日)| 十二運星+天中殺 | ✅ | — | |
16 | | -| `qizheng` | 七政四餘 | 真實天文經度 | — | 規劃中 | |
17 | | -| `tieban` | 鐵板神數 | 起命數 | — | — | |
18 | | -| `qimen` | 奇門遁甲 | 八門九宮起局 | — | — | |
19 | | -| `liuren` | 大六壬 | 四課三傳 | — | — | |
20 | | -| `taiyi` | 太乙神數 | 太乙九宮 | — | — | |
21 | | -| `jyotish` | Jyotiṣa 吠陀占星 | 恆星黃道+Vimśottarī 大運 | — | 規劃中 | |
| 10 | +## The eleven systems / 十一系 |
22 | 11 |
|
23 | | -> **誠實標註**:八字/四柱推命已用 `時辰` 排時柱;占星/紫微/七政等的「時辰/出生地」欄位已在輸入層備好(`BirthInput`),但對應引擎的上升星座、命宮、宮位計算是**規劃中的引擎升級**——升級寫在母專案、再 sync 過來。 |
| 12 | +| key | System | 系統 | engine core | time-aware 時辰 | place-aware 出生地 | |
| 13 | +|---|---|---|---|:--:|:--:| |
| 14 | +| `astrology` | Western Astrology | 西洋占星 | `ephem` ecliptic longitudes | moon phase | planned 規劃中 | |
| 15 | +| `bazi` | BaZi · Four Pillars | 八字(四柱)| JDN-anchored 干支 | ✅ hour pillar | — | |
| 16 | +| `ziwei` | Zi Wei Dou Shu | 紫微斗數 | pure-Python 排盤 | planned 規劃中 | — | |
| 17 | +| `iching` | Plum-Blossom I Ching | 梅花易數 | time-cast hexagram | — | — | |
| 18 | +| `suimei` | Shichū-Suimei (JP) | 四柱推命(日)| 十二運星 + 天中殺 | ✅ | — | |
| 19 | +| `qizheng` | Seven Luminaries | 七政四餘 | real astronomical longitudes | — | planned 規劃中 | |
| 20 | +| `tieban` | Iron Plate | 鐵板神數 | 起命數 | — | — | |
| 21 | +| `qimen` | Qi Men Dun Jia | 奇門遁甲 | 八門九宮起局 | — | — | |
| 22 | +| `liuren` | Da Liu Ren | 大六壬 | 四課三傳 | — | — | |
| 23 | +| `taiyi` | Tai Yi Shen Shu | 太乙神數 | 太乙九宮 | — | — | |
| 24 | +| `jyotish` | Jyotiṣa (Vedic) | 吠陀占星 | sidereal + Vimśottarī daśā | — | planned 規劃中 | |
24 | 25 |
|
25 | | -## 快速開始 |
| 26 | +> **Honest note / 誠實標註.** BaZi and Suimei already use `time` for the hour pillar; the time/place fields are carried on `BirthInput` for every system, but ascendant/house/命宮 computation in astrology · ziwei · qizheng · jyotish is a **planned engine upgrade** — to be written in the parent monorepo and synced over, not hand-patched here. |
| 27 | +
|
| 28 | +## Quickstart / 快速開始 |
26 | 29 |
|
27 | 30 | ```bash |
28 | 31 | python -m venv .venv && source .venv/bin/activate |
29 | | -pip install -e ".[dev,llm]" # llm 可省略;不裝就用 mock 解讀 |
| 32 | +pip install -e ".[dev,llm]" # drop "llm" to stay on the mock reader / 省略 llm 即用 mock |
30 | 33 | cp .env.example .env |
31 | 34 |
|
32 | | -# 後端 API |
| 35 | +# Backend API / 後端 |
33 | 36 | uvicorn fortune.api.main:app --reload |
34 | 37 |
|
35 | | -# 靜態算命頁(免 node build):用任意靜態伺服器開 web/index.html |
| 38 | +# Static fortune page, no node build / 靜態算命頁,免 node build |
36 | 39 | python -m http.server 5500 --directory web |
37 | | -# 開 http://localhost:5500/ 填生辰 → 選命理系統 → 看命盤+解讀 |
| 40 | +# open http://localhost:5500/ → fill birth → pick a system → see chart + reading |
38 | 41 | ``` |
39 | 42 |
|
40 | | -不接 LLM 也能跑:每個命盤都會**確定性排出**,只有解讀文字是 mock 的事實摘要。設 `LLM_BACKEND=anthropic` + `ANTHROPIC_API_KEY` 即換成真正的 AI 解讀。 |
| 43 | +Runs with **no LLM key**: every chart casts deterministically; only the prose reading is a mocked facts digest. Set `LLM_BACKEND=anthropic` + `ANTHROPIC_API_KEY` for a real **bilingual (English + 中文)** AI reading. |
| 44 | +不接 LLM 也能跑:命盤照排,只有解讀走 mock。設金鑰後即得真正的雙語 AI 解讀。 |
41 | 45 |
|
42 | 46 | ## API |
43 | 47 |
|
44 | | -| method | path | 說明 | |
| 48 | +| method | path | | |
45 | 49 | |---|---|---| |
46 | | -| `GET` | `/systems` | 11 系清單+哪些可用 | |
47 | | -| `POST` | `/cast/{system}` | 純命盤(不呼叫 LLM)→ `Chart` | |
48 | | -| `POST` | `/reading/{system}` | 命盤+解讀 → `Reading` | |
| 50 | +| `GET` | `/systems` | the 11 systems + which cast cleanly / 11 系清單+可用狀態 | |
| 51 | +| `POST` | `/cast/{system}` | deterministic chart, no LLM → `Chart` / 純命盤 | |
| 52 | +| `POST` | `/reading/{system}` | chart + bilingual reading → `Reading` / 命盤+解讀 | |
49 | 53 |
|
50 | 54 | ```bash |
51 | 55 | curl -s localhost:8000/cast/bazi -H 'content-type: application/json' -d '{ |
52 | | - "name":"小美","birth_date":"1990-06-15","birth_time":"14:30", |
53 | | - "gender":"女","place":"台北","latitude":25.04,"longitude":121.56 |
| 56 | + "name":"Mei","birth_date":"1990-06-15","birth_time":"14:30", |
| 57 | + "gender":"female","place":"Taipei","latitude":25.04,"longitude":121.56 |
54 | 58 | }' | jq .summary |
55 | 59 | # "日主 辛金・身弱(喜生扶)・喜用 土、金" |
56 | 60 | ``` |
57 | 61 |
|
58 | | -## 架構 |
| 62 | +## Architecture / 架構 |
59 | 63 |
|
60 | 64 | ``` |
61 | 65 | fortune/ |
62 | | - birth.py 生辰輸入(唯一輸入) |
63 | | - schemas.py Chart / Reading 統一封裝 |
64 | | - shared/ 原生:config / logging / llm(mock+anthropic) |
65 | | - engines/<system>/ ← sync 自母專案的純排盤數學(勿手改,會被覆蓋) |
66 | | - casting/<system>.py 每系 adapter:生辰 → 引擎函式 → Chart |
67 | | - casting/__init__.py 11 系註冊表(惰性 import) |
68 | | - interpret.py 命盤事實 + 門派 prompt → LLM 解讀 |
| 66 | + birth.py BirthInput — the single input / 生辰輸入 |
| 67 | + schemas.py Chart / Reading envelope |
| 68 | + shared/ native: config / logging / llm (mock + anthropic) |
| 69 | + engines/<system>/ ← synced 排盤 math from the monorepo (do NOT hand-edit) |
| 70 | + casting/<system>.py per-system adapter: birth → engine fns → Chart |
| 71 | + casting/__init__.py registry of the 11 systems (lazy import) |
| 72 | + interpret.py chart facts + tradition prompt → bilingual reading |
69 | 73 | api/main.py FastAPI |
70 | | -prompts/<system>/ ← sync 自母專案的門派解讀 prompt |
71 | | -web/ 靜態算命頁 + sync 來的命盤渲染元件 |
72 | | -scripts/sync_from_main.sh 重新同步排盤數學 |
| 74 | +prompts/<system>/ ← synced reading prompts from the monorepo |
| 75 | +web/index.html static fortune page + synced chart renderers |
| 76 | +scripts/sync_from_main.sh re-sync the 排盤 math |
73 | 77 | ``` |
74 | 78 |
|
75 | | -### 重新同步排盤數學 |
| 79 | +### Re-syncing the engine math / 重新同步排盤數學 |
76 | 80 |
|
77 | | -母專案改了某系的排盤邏輯後: |
| 81 | +After the parent monorepo changes a system's casting logic: |
78 | 82 |
|
79 | 83 | ```bash |
80 | | -scripts/sync_from_main.sh # 預設母專案 ~/Desktop/威鯨面試_LLMEng |
| 84 | +scripts/sync_from_main.sh # default monorepo ~/Desktop/威鯨面試_LLMEng |
81 | 85 | scripts/sync_from_main.sh /path/to/monorepo |
82 | 86 | ``` |
83 | 87 |
|
84 | | -只會覆蓋 `fortune/engines/*`、`prompts/*`、`web/app/_charts/*`(排盤數學與命盤視覺); |
85 | | -生辰輸入、API、解讀、前端殼是原生的,**不會被動到**。 |
| 88 | +Only `fortune/engines/*`, `prompts/*`, `web/app/_charts/*` are overwritten (the 排盤 math + chart visuals). The birth input, API, readings, and web shell are native and **untouched**. |
| 89 | +只覆蓋排盤數學與命盤視覺;生辰輸入、API、解讀、前端殼不會被動到。 |
86 | 90 |
|
87 | | -## 測試 |
| 91 | +## Tests / 測試 |
88 | 92 |
|
89 | 93 | ```bash |
90 | | -pytest -q # 11 系各自從同一個生辰排出非空命盤 + mock 解讀 |
| 94 | +pytest -q # all 11 systems cast a non-empty chart from one birth + a mock reading |
91 | 95 | ``` |
| 96 | + |
| 97 | +## License |
| 98 | + |
| 99 | +For cultural, educational, and entertainment purposes. Divination is not a basis for financial, medical, or legal decisions. |
| 100 | +僅供文化、教育與娛樂用途;命理不應作為財務、醫療或法律決策的依據。 |
0 commit comments