Import the pre-repair source tree as the history baseline. Runtime data (data/), virtualenvs, bytecode caches and logs are gitignored so local secrets and user state stay out of the repo.
119 lines
2.4 KiB
Python
119 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""公式渲染验收消息注入:新建「公式渲染验收」会话,写入用户原始样本 + 正/负例
|
|
|
|
运行: PYTHONIOENCODING=utf-8 python tests/inject_math_demo.py
|
|
"""
|
|
import os
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
|
from core.db_manager import DBManager # noqa: E402
|
|
|
|
USER_MSG = """帮我看看这个推导,公式渲染对不对?
|
|
|
|
上面是推导结果:
|
|
[
|
|
P_4=\\operatorname{BRF}(M_4,M_5)
|
|
]
|
|
|
|
[
|
|
P_3=\\operatorname{BRF}(S_3,P_4)
|
|
]
|
|
|
|
其中:
|
|
[
|
|
\\operatorname{BRF}(L,H)
|
|
L+
|
|
\\Gamma(L,\\operatorname{Up}(H))
|
|
\\odot
|
|
\\Phi(\\operatorname{Up}(H))
|
|
]
|
|
"""
|
|
|
|
ASSISTANT_MSG = r"""## 公式渲染验收
|
|
|
|
### 1) 你原始样本(单括号块,应渲染为独立居中公式)
|
|
|
|
上面是推导结果:
|
|
[
|
|
P_4=\operatorname{BRF}(M_4,M_5)
|
|
]
|
|
|
|
[
|
|
P_3=\operatorname{BRF}(S_3,P_4)
|
|
]
|
|
|
|
其中:
|
|
[
|
|
\operatorname{BRF}(L,H)
|
|
L+
|
|
\Gamma(L,\operatorname{Up}(H))
|
|
\odot
|
|
\Phi(\operatorname{Up}(H))
|
|
]
|
|
|
|
### 2) 标准定界符
|
|
|
|
行内混合:能量公式 $E=mc^2$ 出现在句子中间;再来一个 $x_i^2 + y_j^2 = z_{ij}^2$。
|
|
|
|
行内括号形式:\(\alpha + \beta = \gamma\)
|
|
|
|
双美元块:
|
|
$$
|
|
\int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}
|
|
$$
|
|
|
|
方括号块:
|
|
\[
|
|
\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}
|
|
\]
|
|
|
|
带矩阵与希腊字母:
|
|
[
|
|
\begin{pmatrix} a & b \\ c & d \end{pmatrix}
|
|
\begin{pmatrix} x \\ y \end{pmatrix}
|
|
=
|
|
\begin{pmatrix} ax+by \\ cx+dy \end{pmatrix}
|
|
]
|
|
|
|
### 3) 反例(不应渲染成公式)
|
|
|
|
- 编号引用:见[1]和[2]的说明。
|
|
- 链接:[KaTeX 官网](https://katex.org)
|
|
- 列表内容:[a, b] 只是一个数组。
|
|
- 货币:价格 $1,000 and $2,000 之间。
|
|
- 代码块:
|
|
|
|
```python
|
|
price = "$5"
|
|
pattern = r"$x + y$"
|
|
arr[0] = 1
|
|
```
|
|
|
|
- 行内代码:使用 `$z$` 表示变量。
|
|
|
|
### 4) 复杂嵌套(流式增量渲染路径同样适用)
|
|
|
|
$$
|
|
f(x) = \sum_{k=0}^{n} \binom{n}{k} x^k (1-x)^{n-k}
|
|
$$
|
|
"""
|
|
|
|
|
|
def main():
|
|
db = DBManager()
|
|
sess = db.create_session("公式渲染验收")
|
|
sid = sess["id"]
|
|
parent = sess.get("current_leaf_msg_id")
|
|
m1 = db.add_message(sid, "user", USER_MSG, parent_id=parent)
|
|
db.add_message(sid, "assistant", ASSISTANT_MSG, parent_id=m1["id"])
|
|
db.mark_session_has_messages(sid)
|
|
print(f"已注入会话: {sid}")
|
|
print(f"标题: 公式渲染验收")
|
|
print(f"用户消息 {len(USER_MSG)}c / 助手消息 {len(ASSISTANT_MSG)}c")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|