bersona


Namebersona JSON
Version 0.1.3 PyPI version JSON
download
home_pageNone
SummaryBersona: Astrology chart generation and LLM-based interpretation
upload_time2025-10-13 08:22:58
maintainerNone
docs_urlNone
authorfanrenaz
requires_python>=3.10
licenseMIT
keywords astrology astronomy llm chart skyfield
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">

# Bersona

精准西方占星本命星盘生成与 LLM 解释引擎。

<p>
<strong>Generate natal charts (Sun..Pluto, Ascendant, Houses, Aspects, Mutual Receptions) and obtain structured AI interpretations.</strong>
</p>

<p>
<img alt="python" src="https://img.shields.io/badge/Python-3.10%2B-blue" />
<img alt="license" src="https://img.shields.io/badge/License-MIT-green" />
<img alt="status" src="https://img.shields.io/badge/status-alpha-orange" />
</p>

</div>

## 1. 简介 (Overview)
`Bersona` 提供本命星盘核心计算与基于 LLM 的自动解释。核心依赖 Skyfield(高精度行星位置),可选 PySwissEph(Placidus 宫位),并以 Pydantic 2 定义结构化数据模型,方便序列化与集成。

应用场景:
- 在线占星应用 / 微信小程序 / Web 后端服务
- 星盘计算微服务或批量数据处理
- 将星盘结构转接入 LLM 进行定制风格解读

## 2. 主要特性 (Features)
- 行星位置:Sun, Moon, Mercury, Venus, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto
- 宫位系统:Equal;安装 `pyswisseph` 自动支持 Placidus
- 上升星座 (Ascendant)
- 主要相位:0° / 60° / 90° / 120° / 180°,支持自定义容许度 (orb)
- 逆行标记:通过前一日黄经差异简单判定
- 互溶接纳 (Mutual Reception):传统 / 现代主宰体系可选
- 多格式出生时间解析:ISO, 简化, 中文日期, 时间戳
- 可选地理编码:行政区解析 + Nominatim(需要网络)
- LLM 解释:基于完整星盘文本提示生成自然语言描述,可自定义 system prompt

## 3. 安装 (Installation)
核心最小安装:
```bash
pip install .
```
全部可选功能:
```bash
pip install .[all]
```


## 4. 快速开始 (Quick Start)
```python
from bersona import Bersona
from datetime import datetime
import zoneinfo

tz = zoneinfo.ZoneInfo('Asia/Shanghai')
dt = datetime(1990, 5, 17, 14, 30, tzinfo=tz)
astro = Bersona()
chart = astro.generate_chart(dt)
print(chart.summary())
```

LLM 解释(自动根据环境变量创建客户端):
```python
if astro.llm_available:
    desc = astro.astrology_describe(chart)
    print(desc.text)
```

直接注入已有 OpenAI 客户端:
```python
from openai import OpenAI
client = OpenAI(api_key="YOUR_KEY")
astro = Bersona(llm_client=client, llm_model="gpt-4o-mini")
desc = astro.astrology_describe(chart)
print(desc.text)
```

运行后再替换 / 注入:
```python
astro.set_llm_client(client, model="gpt-4o")
```

## 5. 数据模型 (Data Models)
核心 Pydantic 模型:
- `ChartInput` / `ChartSettings` / `ChartResult`
- `Ascendant` / `HouseCusp` / `PlanetPosition` / `Aspect` / `MutualReception`
- `AstrologyDesc` (LLM 输出包装)

示例:
```python
from bersona.models import ChartResult
print(chart.planets['Sun'].ecliptic_longitude)
print(chart.aspects[0].aspect)
print(chart.model_dump())
```

## 6. 时间输入支持 (Date Parsing)
`parse_birth_datetime` 支持:
- `1990-05-17 14:30:00`, `1990/05/17 14:30`
- 中文:`1990年5月17日14时30分`
- 仅日期:`1990-05-17` 自动补中午 12:00 并标记 `date_only=True`
- 时间戳:`643708200`

## 7. 环境变量 (Environment Variables)
| 变量 | 说明 | 默认 |
|------|------|------|
| `BERSONA_EPHEMERIS` | 星历文件名 | `de421.bsp` |
| `SKYFIELD_CACHE_DIR` | 自定义缓存目录 | `~/.skyfield` |
| `OPENAI_API_KEY` / `OPENAI_KEY` | LLM API 密钥 | 无 |
| `OPENAI_BASE_URL` | 自定义 OpenAI 接口地址 | 官方地址 |
| `OPENAI_MODEL` | 默认模型名称 | 无 |
| `BERSONA_QUIET` | 关闭下载提示 (1) | 0 |
| `BERSONA_LOG_LEVEL` | 未来日志级别 | `info` |

可复制 `.env.example`:
```bash
cp .env.example .env
source .env
```

## 8. API 摘要 (API Summary)
| 方法 | 说明 | 关键参数 |
|------|------|---------|
| `Bersona.generate_chart` | 生成星盘 | `birth_dt_input`, `latitude`, `longitude`, `house_system` |
| `Bersona.astrology_describe` | LLM 解释 | `chart`, `language`, `system_prompt`, `model` |
| `Bersona.llm_chat` | 低层对话 | `messages`, `model` |
| `Bersona.set_system_prompt` | 设置实例级 system prompt | `prompt` |
| `Bersona.set_llm_client` | 动态注入/替换 LLM 客户端 | `client`, `model` |
| `utils.chart_to_text` | 星盘序列化文本 | `ChartResult` |
| `utils.parse_birth_datetime` | 输入时间解析 | 多格式字符串/时间戳 |

## 9. 测试 (Testing)
```bash
pip install .[dev]
python -m pytest -q
```
CI 在 push / PR 自动运行多 Python 版本测试与构建。

## 10. 构建与发布 (Build & Release)
构建:
```bash
python -m build
twine check dist/*
```
TestPyPI 发布与验证:
```bash
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
python -m venv .venv-test && source .venv-test/bin/activate
pip install --index-url https://test.pypi.org/simple --extra-index-url https://pypi.org/simple bersona
```
正式发布(自动):打 tag `vX.Y.Z` 触发 `release.yml` 使用 `PYPI_API_TOKEN`。

版本号管理:
```bash
python scripts/bump_version.py patch
git tag v$(python -c "import bersona;print(bersona.__version__)")
git push --tags
```

## 11. 版本策略 (Versioning)
语义化版本:`MAJOR.MINOR.PATCH`。
- 初期 (<1.0.0) 频繁变更:提升 MINOR 表示潜在破坏性。
- PATCH:bug 修复或非结构化微改。
- 预发布:可手动设置 `0.x.yrc1` / `0.x.ya1`。

## 12. 贡献指南 (Contributing)
欢迎 Issue 与 PR:
1. Fork & 创建分支:`feature/xxx`
2. 添加/更新测试
3. 运行 `python -m pytest -q`
4. 提交并描述意图与行为变化

建议工具:后续将加入 Ruff/Black;提交前可格式化。

## 13. 路线图 (Roadmap)
- Transit (行运) / Progressions 支持
- 更多天体:凯龙星、黑月莉莉丝、月亮交点
- 高级相位:半刑、梅花等
- 行星尊贵(旺陷庙失势)分析
- LLM 输出结构化 JSON + 可信度指标
- 国际化多语言模板扩展

## 14. License
MIT License © 2025 fanrenaz

## 15. English Quick Glance
```bash
pip install bersona
```
```python
from bersona import Bersona
from datetime import datetime
import zoneinfo
tz = zoneinfo.ZoneInfo('UTC')
chart = Bersona().generate_chart(datetime(1990,5,17,14,30,tzinfo=tz), 40.0, -74.0)
print(chart.summary())
```
LLM description (if API key set):
```python
desc = Bersona().astrology_describe(chart, language='en', system_prompt='You are a concise astrologer:')
print(desc.text)
```

## 16. System Prompt 定制 (System Prompt Customization)

Bersona 在实例上维护一个可覆盖的 system prompt,用于引导 LLM 撰写解释文本。

优先级(由高到低):
1. 调用 `astrology_describe` 时显式传入 `system_prompt` 参数
2. 实例属性 `bersona.system_prompt`(可通过 `set_system_prompt` 设置)
3. `BASE_PROMPTS` 中按语言代码的默认模板(受环境变量 `BERSONA_DEFAULT_LANG` 影响,默认 zh)

查看当前实例的 system prompt:
```python
from bersona import Bersona
b = Bersona()
print(b.system_prompt)  # 当前使用的 system prompt
```

覆盖 / 更新:
```python
b.set_system_prompt("你是一位极其简洁的占星分析师,请用要点式描述性格与潜力。")
desc = b.astrology_describe(chart)  # 将使用新的自定义 prompt
```

恢复默认(清除覆盖):
```python
b.set_system_prompt("")  # 或 None
# 再次调用将回退到 BASE_PROMPTS[默认语言]
desc = b.astrology_describe(chart)
```

临时指定(仅本次调用生效,不改变实例属性):
```python
desc = b.astrology_describe(chart, system_prompt="You are a concise astrologer. Output in English.")
```

多语言提示(`language` 会用于选择默认模板;若传入自定义 system_prompt 将直接覆盖语言逻辑):
```python
desc = b.astrology_describe(chart, language="en")
```

环境变量:
- `BERSONA_DEFAULT_LANG`:启动时选择默认语言的基础模板(如 `en`, `zh`)。
- 当你需要动态切换风格,可在多实例中分别设置不同 `system_prompt`。

快速要点:
- 长期风格:用 `set_system_prompt`.
- 一次性定制:在 `astrology_describe` 里传 `system_prompt`.
- 设空字符串即可回退默认。

## 17. LLM 客户端注入 (Inject Existing LLM Client)

你可以在初始化时传入已创建的兼容 OpenAI 接口客户端(需提供 `chat.completions.create` 方法):
```python
from openai import OpenAI
client = OpenAI(api_key="YOUR_KEY", base_url="https://api.openai.com/v1")
b = Bersona(llm_client=client, llm_model="gpt-4o-mini")
desc = b.astrology_describe(chart)
```

或在实例创建后动态替换:
```python
b.set_llm_client(client, model="gpt-4o")
```

要点:
- 未传入 `llm_client` 时,会按环境变量自动创建(需 `OPENAI_API_KEY`)。
- `llm_model` 未指定时,回退读取 `OPENAI_MODEL`。
- 调用前可检查:`b.llm_available`。

---
欢迎反馈与建议,共同改进 Bersona。

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "bersona",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "astrology, astronomy, llm, chart, skyfield",
    "author": "fanrenaz",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/62/dd/8821557df351029e5529162f2a473ddc739a74bace9f34cf371816229c2a/bersona-0.1.3.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n\n# Bersona\n\n\u7cbe\u51c6\u897f\u65b9\u5360\u661f\u672c\u547d\u661f\u76d8\u751f\u6210\u4e0e LLM \u89e3\u91ca\u5f15\u64ce\u3002\n\n<p>\n<strong>Generate natal charts (Sun..Pluto, Ascendant, Houses, Aspects, Mutual Receptions) and obtain structured AI interpretations.</strong>\n</p>\n\n<p>\n<img alt=\"python\" src=\"https://img.shields.io/badge/Python-3.10%2B-blue\" />\n<img alt=\"license\" src=\"https://img.shields.io/badge/License-MIT-green\" />\n<img alt=\"status\" src=\"https://img.shields.io/badge/status-alpha-orange\" />\n</p>\n\n</div>\n\n## 1. \u7b80\u4ecb (Overview)\n`Bersona` \u63d0\u4f9b\u672c\u547d\u661f\u76d8\u6838\u5fc3\u8ba1\u7b97\u4e0e\u57fa\u4e8e LLM \u7684\u81ea\u52a8\u89e3\u91ca\u3002\u6838\u5fc3\u4f9d\u8d56 Skyfield\uff08\u9ad8\u7cbe\u5ea6\u884c\u661f\u4f4d\u7f6e\uff09\uff0c\u53ef\u9009 PySwissEph\uff08Placidus \u5bab\u4f4d\uff09\uff0c\u5e76\u4ee5 Pydantic 2 \u5b9a\u4e49\u7ed3\u6784\u5316\u6570\u636e\u6a21\u578b\uff0c\u65b9\u4fbf\u5e8f\u5217\u5316\u4e0e\u96c6\u6210\u3002\n\n\u5e94\u7528\u573a\u666f\uff1a\n- \u5728\u7ebf\u5360\u661f\u5e94\u7528 / \u5fae\u4fe1\u5c0f\u7a0b\u5e8f / Web \u540e\u7aef\u670d\u52a1\n- \u661f\u76d8\u8ba1\u7b97\u5fae\u670d\u52a1\u6216\u6279\u91cf\u6570\u636e\u5904\u7406\n- \u5c06\u661f\u76d8\u7ed3\u6784\u8f6c\u63a5\u5165 LLM \u8fdb\u884c\u5b9a\u5236\u98ce\u683c\u89e3\u8bfb\n\n## 2. \u4e3b\u8981\u7279\u6027 (Features)\n- \u884c\u661f\u4f4d\u7f6e\uff1aSun, Moon, Mercury, Venus, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto\n- \u5bab\u4f4d\u7cfb\u7edf\uff1aEqual\uff1b\u5b89\u88c5 `pyswisseph` \u81ea\u52a8\u652f\u6301 Placidus\n- \u4e0a\u5347\u661f\u5ea7 (Ascendant)\n- \u4e3b\u8981\u76f8\u4f4d\uff1a0\u00b0 / 60\u00b0 / 90\u00b0 / 120\u00b0 / 180\u00b0\uff0c\u652f\u6301\u81ea\u5b9a\u4e49\u5bb9\u8bb8\u5ea6 (orb)\n- \u9006\u884c\u6807\u8bb0\uff1a\u901a\u8fc7\u524d\u4e00\u65e5\u9ec4\u7ecf\u5dee\u5f02\u7b80\u5355\u5224\u5b9a\n- \u4e92\u6eb6\u63a5\u7eb3 (Mutual Reception)\uff1a\u4f20\u7edf / \u73b0\u4ee3\u4e3b\u5bb0\u4f53\u7cfb\u53ef\u9009\n- \u591a\u683c\u5f0f\u51fa\u751f\u65f6\u95f4\u89e3\u6790\uff1aISO, \u7b80\u5316, \u4e2d\u6587\u65e5\u671f, \u65f6\u95f4\u6233\n- \u53ef\u9009\u5730\u7406\u7f16\u7801\uff1a\u884c\u653f\u533a\u89e3\u6790 + Nominatim\uff08\u9700\u8981\u7f51\u7edc\uff09\n- LLM \u89e3\u91ca\uff1a\u57fa\u4e8e\u5b8c\u6574\u661f\u76d8\u6587\u672c\u63d0\u793a\u751f\u6210\u81ea\u7136\u8bed\u8a00\u63cf\u8ff0\uff0c\u53ef\u81ea\u5b9a\u4e49 system prompt\n\n## 3. \u5b89\u88c5 (Installation)\n\u6838\u5fc3\u6700\u5c0f\u5b89\u88c5\uff1a\n```bash\npip install .\n```\n\u5168\u90e8\u53ef\u9009\u529f\u80fd\uff1a\n```bash\npip install .[all]\n```\n\n\n## 4. \u5feb\u901f\u5f00\u59cb (Quick Start)\n```python\nfrom bersona import Bersona\nfrom datetime import datetime\nimport zoneinfo\n\ntz = zoneinfo.ZoneInfo('Asia/Shanghai')\ndt = datetime(1990, 5, 17, 14, 30, tzinfo=tz)\nastro = Bersona()\nchart = astro.generate_chart(dt)\nprint(chart.summary())\n```\n\nLLM \u89e3\u91ca\uff08\u81ea\u52a8\u6839\u636e\u73af\u5883\u53d8\u91cf\u521b\u5efa\u5ba2\u6237\u7aef\uff09\uff1a\n```python\nif astro.llm_available:\n    desc = astro.astrology_describe(chart)\n    print(desc.text)\n```\n\n\u76f4\u63a5\u6ce8\u5165\u5df2\u6709 OpenAI \u5ba2\u6237\u7aef\uff1a\n```python\nfrom openai import OpenAI\nclient = OpenAI(api_key=\"YOUR_KEY\")\nastro = Bersona(llm_client=client, llm_model=\"gpt-4o-mini\")\ndesc = astro.astrology_describe(chart)\nprint(desc.text)\n```\n\n\u8fd0\u884c\u540e\u518d\u66ff\u6362 / \u6ce8\u5165\uff1a\n```python\nastro.set_llm_client(client, model=\"gpt-4o\")\n```\n\n## 5. \u6570\u636e\u6a21\u578b (Data Models)\n\u6838\u5fc3 Pydantic \u6a21\u578b\uff1a\n- `ChartInput` / `ChartSettings` / `ChartResult`\n- `Ascendant` / `HouseCusp` / `PlanetPosition` / `Aspect` / `MutualReception`\n- `AstrologyDesc` (LLM \u8f93\u51fa\u5305\u88c5)\n\n\u793a\u4f8b\uff1a\n```python\nfrom bersona.models import ChartResult\nprint(chart.planets['Sun'].ecliptic_longitude)\nprint(chart.aspects[0].aspect)\nprint(chart.model_dump())\n```\n\n## 6. \u65f6\u95f4\u8f93\u5165\u652f\u6301 (Date Parsing)\n`parse_birth_datetime` \u652f\u6301\uff1a\n- `1990-05-17 14:30:00`, `1990/05/17 14:30`\n- \u4e2d\u6587\uff1a`1990\u5e745\u670817\u65e514\u65f630\u5206`\n- \u4ec5\u65e5\u671f\uff1a`1990-05-17` \u81ea\u52a8\u8865\u4e2d\u5348 12:00 \u5e76\u6807\u8bb0 `date_only=True`\n- \u65f6\u95f4\u6233\uff1a`643708200`\n\n## 7. \u73af\u5883\u53d8\u91cf (Environment Variables)\n| \u53d8\u91cf | \u8bf4\u660e | \u9ed8\u8ba4 |\n|------|------|------|\n| `BERSONA_EPHEMERIS` | \u661f\u5386\u6587\u4ef6\u540d | `de421.bsp` |\n| `SKYFIELD_CACHE_DIR` | \u81ea\u5b9a\u4e49\u7f13\u5b58\u76ee\u5f55 | `~/.skyfield` |\n| `OPENAI_API_KEY` / `OPENAI_KEY` | LLM API \u5bc6\u94a5 | \u65e0 |\n| `OPENAI_BASE_URL` | \u81ea\u5b9a\u4e49 OpenAI \u63a5\u53e3\u5730\u5740 | \u5b98\u65b9\u5730\u5740 |\n| `OPENAI_MODEL` | \u9ed8\u8ba4\u6a21\u578b\u540d\u79f0 | \u65e0 |\n| `BERSONA_QUIET` | \u5173\u95ed\u4e0b\u8f7d\u63d0\u793a (1) | 0 |\n| `BERSONA_LOG_LEVEL` | \u672a\u6765\u65e5\u5fd7\u7ea7\u522b | `info` |\n\n\u53ef\u590d\u5236 `.env.example`\uff1a\n```bash\ncp .env.example .env\nsource .env\n```\n\n## 8. API \u6458\u8981 (API Summary)\n| \u65b9\u6cd5 | \u8bf4\u660e | \u5173\u952e\u53c2\u6570 |\n|------|------|---------|\n| `Bersona.generate_chart` | \u751f\u6210\u661f\u76d8 | `birth_dt_input`, `latitude`, `longitude`, `house_system` |\n| `Bersona.astrology_describe` | LLM \u89e3\u91ca | `chart`, `language`, `system_prompt`, `model` |\n| `Bersona.llm_chat` | \u4f4e\u5c42\u5bf9\u8bdd | `messages`, `model` |\n| `Bersona.set_system_prompt` | \u8bbe\u7f6e\u5b9e\u4f8b\u7ea7 system prompt | `prompt` |\n| `Bersona.set_llm_client` | \u52a8\u6001\u6ce8\u5165/\u66ff\u6362 LLM \u5ba2\u6237\u7aef | `client`, `model` |\n| `utils.chart_to_text` | \u661f\u76d8\u5e8f\u5217\u5316\u6587\u672c | `ChartResult` |\n| `utils.parse_birth_datetime` | \u8f93\u5165\u65f6\u95f4\u89e3\u6790 | \u591a\u683c\u5f0f\u5b57\u7b26\u4e32/\u65f6\u95f4\u6233 |\n\n## 9. \u6d4b\u8bd5 (Testing)\n```bash\npip install .[dev]\npython -m pytest -q\n```\nCI \u5728 push / PR \u81ea\u52a8\u8fd0\u884c\u591a Python \u7248\u672c\u6d4b\u8bd5\u4e0e\u6784\u5efa\u3002\n\n## 10. \u6784\u5efa\u4e0e\u53d1\u5e03 (Build & Release)\n\u6784\u5efa\uff1a\n```bash\npython -m build\ntwine check dist/*\n```\nTestPyPI \u53d1\u5e03\u4e0e\u9a8c\u8bc1\uff1a\n```bash\ntwine upload --repository-url https://test.pypi.org/legacy/ dist/*\npython -m venv .venv-test && source .venv-test/bin/activate\npip install --index-url https://test.pypi.org/simple --extra-index-url https://pypi.org/simple bersona\n```\n\u6b63\u5f0f\u53d1\u5e03\uff08\u81ea\u52a8\uff09\uff1a\u6253 tag `vX.Y.Z` \u89e6\u53d1 `release.yml` \u4f7f\u7528 `PYPI_API_TOKEN`\u3002\n\n\u7248\u672c\u53f7\u7ba1\u7406\uff1a\n```bash\npython scripts/bump_version.py patch\ngit tag v$(python -c \"import bersona;print(bersona.__version__)\")\ngit push --tags\n```\n\n## 11. \u7248\u672c\u7b56\u7565 (Versioning)\n\u8bed\u4e49\u5316\u7248\u672c\uff1a`MAJOR.MINOR.PATCH`\u3002\n- \u521d\u671f (<1.0.0) \u9891\u7e41\u53d8\u66f4\uff1a\u63d0\u5347 MINOR \u8868\u793a\u6f5c\u5728\u7834\u574f\u6027\u3002\n- PATCH\uff1abug \u4fee\u590d\u6216\u975e\u7ed3\u6784\u5316\u5fae\u6539\u3002\n- \u9884\u53d1\u5e03\uff1a\u53ef\u624b\u52a8\u8bbe\u7f6e `0.x.yrc1` / `0.x.ya1`\u3002\n\n## 12. \u8d21\u732e\u6307\u5357 (Contributing)\n\u6b22\u8fce Issue \u4e0e PR\uff1a\n1. Fork & \u521b\u5efa\u5206\u652f\uff1a`feature/xxx`\n2. \u6dfb\u52a0/\u66f4\u65b0\u6d4b\u8bd5\n3. \u8fd0\u884c `python -m pytest -q`\n4. \u63d0\u4ea4\u5e76\u63cf\u8ff0\u610f\u56fe\u4e0e\u884c\u4e3a\u53d8\u5316\n\n\u5efa\u8bae\u5de5\u5177\uff1a\u540e\u7eed\u5c06\u52a0\u5165 Ruff/Black\uff1b\u63d0\u4ea4\u524d\u53ef\u683c\u5f0f\u5316\u3002\n\n## 13. \u8def\u7ebf\u56fe (Roadmap)\n- Transit (\u884c\u8fd0) / Progressions \u652f\u6301\n- \u66f4\u591a\u5929\u4f53\uff1a\u51ef\u9f99\u661f\u3001\u9ed1\u6708\u8389\u8389\u4e1d\u3001\u6708\u4eae\u4ea4\u70b9\n- \u9ad8\u7ea7\u76f8\u4f4d\uff1a\u534a\u5211\u3001\u6885\u82b1\u7b49\n- \u884c\u661f\u5c0a\u8d35\uff08\u65fa\u9677\u5e99\u5931\u52bf\uff09\u5206\u6790\n- LLM \u8f93\u51fa\u7ed3\u6784\u5316 JSON + \u53ef\u4fe1\u5ea6\u6307\u6807\n- \u56fd\u9645\u5316\u591a\u8bed\u8a00\u6a21\u677f\u6269\u5c55\n\n## 14. License\nMIT License \u00a9 2025 fanrenaz\n\n## 15. English Quick Glance\n```bash\npip install bersona\n```\n```python\nfrom bersona import Bersona\nfrom datetime import datetime\nimport zoneinfo\ntz = zoneinfo.ZoneInfo('UTC')\nchart = Bersona().generate_chart(datetime(1990,5,17,14,30,tzinfo=tz), 40.0, -74.0)\nprint(chart.summary())\n```\nLLM description (if API key set):\n```python\ndesc = Bersona().astrology_describe(chart, language='en', system_prompt='You are a concise astrologer:')\nprint(desc.text)\n```\n\n## 16. System Prompt \u5b9a\u5236 (System Prompt Customization)\n\nBersona \u5728\u5b9e\u4f8b\u4e0a\u7ef4\u62a4\u4e00\u4e2a\u53ef\u8986\u76d6\u7684 system prompt\uff0c\u7528\u4e8e\u5f15\u5bfc LLM \u64b0\u5199\u89e3\u91ca\u6587\u672c\u3002\n\n\u4f18\u5148\u7ea7\uff08\u7531\u9ad8\u5230\u4f4e\uff09\uff1a\n1. \u8c03\u7528 `astrology_describe` \u65f6\u663e\u5f0f\u4f20\u5165 `system_prompt` \u53c2\u6570\n2. \u5b9e\u4f8b\u5c5e\u6027 `bersona.system_prompt`\uff08\u53ef\u901a\u8fc7 `set_system_prompt` \u8bbe\u7f6e\uff09\n3. `BASE_PROMPTS` \u4e2d\u6309\u8bed\u8a00\u4ee3\u7801\u7684\u9ed8\u8ba4\u6a21\u677f\uff08\u53d7\u73af\u5883\u53d8\u91cf `BERSONA_DEFAULT_LANG` \u5f71\u54cd\uff0c\u9ed8\u8ba4 zh\uff09\n\n\u67e5\u770b\u5f53\u524d\u5b9e\u4f8b\u7684 system prompt\uff1a\n```python\nfrom bersona import Bersona\nb = Bersona()\nprint(b.system_prompt)  # \u5f53\u524d\u4f7f\u7528\u7684 system prompt\n```\n\n\u8986\u76d6 / \u66f4\u65b0\uff1a\n```python\nb.set_system_prompt(\"\u4f60\u662f\u4e00\u4f4d\u6781\u5176\u7b80\u6d01\u7684\u5360\u661f\u5206\u6790\u5e08\uff0c\u8bf7\u7528\u8981\u70b9\u5f0f\u63cf\u8ff0\u6027\u683c\u4e0e\u6f5c\u529b\u3002\")\ndesc = b.astrology_describe(chart)  # \u5c06\u4f7f\u7528\u65b0\u7684\u81ea\u5b9a\u4e49 prompt\n```\n\n\u6062\u590d\u9ed8\u8ba4\uff08\u6e05\u9664\u8986\u76d6\uff09\uff1a\n```python\nb.set_system_prompt(\"\")  # \u6216 None\n# \u518d\u6b21\u8c03\u7528\u5c06\u56de\u9000\u5230 BASE_PROMPTS[\u9ed8\u8ba4\u8bed\u8a00]\ndesc = b.astrology_describe(chart)\n```\n\n\u4e34\u65f6\u6307\u5b9a\uff08\u4ec5\u672c\u6b21\u8c03\u7528\u751f\u6548\uff0c\u4e0d\u6539\u53d8\u5b9e\u4f8b\u5c5e\u6027\uff09\uff1a\n```python\ndesc = b.astrology_describe(chart, system_prompt=\"You are a concise astrologer. Output in English.\")\n```\n\n\u591a\u8bed\u8a00\u63d0\u793a\uff08`language` \u4f1a\u7528\u4e8e\u9009\u62e9\u9ed8\u8ba4\u6a21\u677f\uff1b\u82e5\u4f20\u5165\u81ea\u5b9a\u4e49 system_prompt \u5c06\u76f4\u63a5\u8986\u76d6\u8bed\u8a00\u903b\u8f91\uff09\uff1a\n```python\ndesc = b.astrology_describe(chart, language=\"en\")\n```\n\n\u73af\u5883\u53d8\u91cf\uff1a\n- `BERSONA_DEFAULT_LANG`\uff1a\u542f\u52a8\u65f6\u9009\u62e9\u9ed8\u8ba4\u8bed\u8a00\u7684\u57fa\u7840\u6a21\u677f\uff08\u5982 `en`, `zh`\uff09\u3002\n- \u5f53\u4f60\u9700\u8981\u52a8\u6001\u5207\u6362\u98ce\u683c\uff0c\u53ef\u5728\u591a\u5b9e\u4f8b\u4e2d\u5206\u522b\u8bbe\u7f6e\u4e0d\u540c `system_prompt`\u3002\n\n\u5feb\u901f\u8981\u70b9\uff1a\n- \u957f\u671f\u98ce\u683c\uff1a\u7528 `set_system_prompt`.\n- \u4e00\u6b21\u6027\u5b9a\u5236\uff1a\u5728 `astrology_describe` \u91cc\u4f20 `system_prompt`.\n- \u8bbe\u7a7a\u5b57\u7b26\u4e32\u5373\u53ef\u56de\u9000\u9ed8\u8ba4\u3002\n\n## 17. LLM \u5ba2\u6237\u7aef\u6ce8\u5165 (Inject Existing LLM Client)\n\n\u4f60\u53ef\u4ee5\u5728\u521d\u59cb\u5316\u65f6\u4f20\u5165\u5df2\u521b\u5efa\u7684\u517c\u5bb9 OpenAI \u63a5\u53e3\u5ba2\u6237\u7aef\uff08\u9700\u63d0\u4f9b `chat.completions.create` \u65b9\u6cd5\uff09\uff1a\n```python\nfrom openai import OpenAI\nclient = OpenAI(api_key=\"YOUR_KEY\", base_url=\"https://api.openai.com/v1\")\nb = Bersona(llm_client=client, llm_model=\"gpt-4o-mini\")\ndesc = b.astrology_describe(chart)\n```\n\n\u6216\u5728\u5b9e\u4f8b\u521b\u5efa\u540e\u52a8\u6001\u66ff\u6362\uff1a\n```python\nb.set_llm_client(client, model=\"gpt-4o\")\n```\n\n\u8981\u70b9\uff1a\n- \u672a\u4f20\u5165 `llm_client` \u65f6\uff0c\u4f1a\u6309\u73af\u5883\u53d8\u91cf\u81ea\u52a8\u521b\u5efa\uff08\u9700 `OPENAI_API_KEY`\uff09\u3002\n- `llm_model` \u672a\u6307\u5b9a\u65f6\uff0c\u56de\u9000\u8bfb\u53d6 `OPENAI_MODEL`\u3002\n- \u8c03\u7528\u524d\u53ef\u68c0\u67e5\uff1a`b.llm_available`\u3002\n\n---\n\u6b22\u8fce\u53cd\u9988\u4e0e\u5efa\u8bae\uff0c\u5171\u540c\u6539\u8fdb Bersona\u3002\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Bersona: Astrology chart generation and LLM-based interpretation",
    "version": "0.1.3",
    "project_urls": {
        "Homepage": "https://github.com/fanrenaz/Bersona",
        "Issues": "https://github.com/fanrenaz/Bersona/issues",
        "Source": "https://github.com/fanrenaz/Bersona"
    },
    "split_keywords": [
        "astrology",
        " astronomy",
        " llm",
        " chart",
        " skyfield"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "c5e634962fd129145308e316bb7db7a381c55a585152e54557a832bc7365787f",
                "md5": "f23d45fad5552efb2cfdcc779ef96947",
                "sha256": "faef9ae826de569f5e787c960de2ecd9faa67d039c0091a6d81308cd5992a5bc"
            },
            "downloads": -1,
            "filename": "bersona-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f23d45fad5552efb2cfdcc779ef96947",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 20920,
            "upload_time": "2025-10-13T08:22:56",
            "upload_time_iso_8601": "2025-10-13T08:22:56.953560Z",
            "url": "https://files.pythonhosted.org/packages/c5/e6/34962fd129145308e316bb7db7a381c55a585152e54557a832bc7365787f/bersona-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "62dd8821557df351029e5529162f2a473ddc739a74bace9f34cf371816229c2a",
                "md5": "088d6fd3d3000d19f3477123bf61f402",
                "sha256": "2f21f9940220455ea5fa33464b36f9356fdf837a4a5f031383f9f8a67bdde50e"
            },
            "downloads": -1,
            "filename": "bersona-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "088d6fd3d3000d19f3477123bf61f402",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 23256,
            "upload_time": "2025-10-13T08:22:58",
            "upload_time_iso_8601": "2025-10-13T08:22:58.353180Z",
            "url": "https://files.pythonhosted.org/packages/62/dd/8821557df351029e5529162f2a473ddc739a74bace9f34cf371816229c2a/bersona-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-13 08:22:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "fanrenaz",
    "github_project": "Bersona",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "bersona"
}
        
Elapsed time: 1.15396s