mirror of
https://github.com/jihe520/MathModelAgent.git
synced 2026-09-19 08:09:48 +08:00
fix
fix
This commit is contained in:
@@ -28,10 +28,11 @@
|
||||
- loacl Interperter: 基于 jupyter , 代码保存为 notebook 方便再编辑
|
||||
- 云端 code interperter: [E2B](https://e2b.dev/) 和 [daytona](https://app.daytona.io/)
|
||||
- 📝 生成一份编排好格式的论文
|
||||
- 🤝 muti-agents: 建模手,代码手,论文手
|
||||
- 🔄 muti-llms: 每个agent设置不同的模型
|
||||
- 🤝 muti-agents: 建模手,代码手,论文手等
|
||||
- 🔄 muti-llms: 每个 agent 设置不同的、合适的模型
|
||||
- 支持所有模型: [litellm](https://docs.litellm.ai/docs/providers)
|
||||
- 💰 成本低 agentless(单次任务成本约 1 rmb)
|
||||
- 💰 成本低 workflow agentless,不依赖 agent 框架
|
||||
- 自定义模板: prompt inject
|
||||
|
||||
## 🚀 后期计划
|
||||
|
||||
@@ -126,6 +127,10 @@ pnpm run dev
|
||||
- notebook.ipynb: 保存运行过程中产生的代码
|
||||
- res.md: 保存最后运行产生的结果为 markdown 格式
|
||||
|
||||
需要自定义自定义提示词模板 template ?
|
||||
prompt inject : [prompt](./backend/app/config/md_template.toml)
|
||||
|
||||
|
||||
## 🤝 贡献和开发
|
||||
|
||||
[DeepWiki](https://deepwiki.com/jihe520/MathModelAgent)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
ENV=dev
|
||||
# support all model, check out https://docs.litellm.ai/docs/
|
||||
# gpt-4.1,deepseek/deepseek-chat
|
||||
# 为每个 agent配置合适的模型
|
||||
# e.g. gpt-4.1,deepseek/deepseek-chat
|
||||
# 为每个 agent 配置合适的模型
|
||||
COORDINATOR_API_KEY=
|
||||
COORDINATOR_MODEL=
|
||||
# COORDINATOR_BASE_URL= 默认不需要填
|
||||
# COORDINATOR_BASE_URL= 如果需要中转自定义等
|
||||
|
||||
# 推荐 thinking model
|
||||
MODELER_API_KEY=
|
||||
|
||||
@@ -58,69 +58,83 @@ class UserOutput:
|
||||
]
|
||||
logger.debug(f"处理序列: {seq}")
|
||||
|
||||
# 收集所有内容和脚注
|
||||
# 收集所有内容
|
||||
all_content = []
|
||||
all_footnotes = []
|
||||
footnote_counter = 1
|
||||
footnote_mapping = {} # 用于存储原始编号到新编号的映射
|
||||
|
||||
# 第一遍:收集所有引用并建立映射
|
||||
logger.info("开始第一遍处理:收集引用并建立映射")
|
||||
for key in seq:
|
||||
if key not in self.res:
|
||||
logger.debug(f"跳过不存在的键: {key}")
|
||||
continue
|
||||
|
||||
content = self.res[key]["response_content"]
|
||||
footnotes = self.res[key]["footnotes"]
|
||||
|
||||
if footnotes:
|
||||
logger.debug(f"处理 {key} 的脚注,数量: {len(footnotes)}")
|
||||
for num, content in footnotes: # 直接解构元组
|
||||
if num not in footnote_mapping:
|
||||
footnote_mapping[num] = str(footnote_counter)
|
||||
footnote_counter += 1
|
||||
|
||||
logger.info(f"脚注映射完成,共有 {len(footnote_mapping)} 个脚注")
|
||||
|
||||
# 第二遍:更新内容和脚注
|
||||
logger.info("开始第二遍处理:更新内容和脚注")
|
||||
for key in seq:
|
||||
if key not in self.res:
|
||||
continue
|
||||
|
||||
content = self.res[key]["response_content"]
|
||||
footnotes = self.res[key]["footnotes"]
|
||||
|
||||
# 更新内容中的引用编号
|
||||
if footnotes:
|
||||
logger.debug(f"更新 {key} 的内容和脚注")
|
||||
# 更新正文中的引用
|
||||
for old_num, new_num in footnote_mapping.items():
|
||||
content = content.replace(f"[^{old_num}]", f"[^{new_num}]")
|
||||
|
||||
# 更新脚注
|
||||
updated_footnotes = []
|
||||
for num, content in footnotes: # 直接解构元组
|
||||
new_num = footnote_mapping[num]
|
||||
updated_footnote = f"[^{new_num}]: {content.strip()}"
|
||||
updated_footnotes.append(updated_footnote)
|
||||
|
||||
all_footnotes.extend(updated_footnotes)
|
||||
|
||||
all_content.append(content)
|
||||
|
||||
# 合并所有内容和脚注
|
||||
final_content = "\n".join(all_content)
|
||||
if all_footnotes:
|
||||
# 对脚注按编号排序
|
||||
sorted_footnotes = sorted(
|
||||
all_footnotes, key=lambda x: int(re.search(r"\[\^(\d+)\]:", x).group(1))
|
||||
)
|
||||
final_content += "\n\n" + "\n".join(sorted_footnotes)
|
||||
# 合并所有内容
|
||||
full_content = "\n".join(all_content)
|
||||
|
||||
logger.info(f"结果处理完成,最终内容长度: {len(final_content)}")
|
||||
return final_content
|
||||
# 提取所有脚注引用 [^1], [^2] 等
|
||||
footnote_refs = re.findall(r"\[\^(\d+)\]", full_content)
|
||||
|
||||
# 提取所有脚注定义 [^1]: 内容
|
||||
footnote_defs = re.findall(
|
||||
r"\[\^(\d+)\]:\s*(.+?)(?=\n\[\^|\n\n|\Z)", full_content, re.DOTALL
|
||||
)
|
||||
|
||||
logger.info(f"找到脚注引用: {set(footnote_refs)}")
|
||||
logger.info(f"找到脚注定义: {[def_num for def_num, _ in footnote_defs]}")
|
||||
|
||||
# 创建脚注映射和内容
|
||||
footnote_mapping = {}
|
||||
footnote_contents = {}
|
||||
footnote_counter = 1
|
||||
|
||||
# 收集所有唯一的脚注编号(来自引用和定义)
|
||||
all_footnote_nums = set(footnote_refs)
|
||||
for def_num, def_content in footnote_defs:
|
||||
all_footnote_nums.add(def_num)
|
||||
footnote_contents[def_num] = def_content.strip()
|
||||
|
||||
# 为每个脚注分配新编号
|
||||
for old_num in sorted(all_footnote_nums, key=int):
|
||||
footnote_mapping[old_num] = str(footnote_counter)
|
||||
footnote_counter += 1
|
||||
|
||||
logger.info(f"脚注映射: {footnote_mapping}")
|
||||
|
||||
# 更新正文中的脚注引用编号
|
||||
processed_content = full_content
|
||||
for old_num, new_num in footnote_mapping.items():
|
||||
processed_content = processed_content.replace(
|
||||
f"[^{old_num}]", f"[^{new_num}]"
|
||||
)
|
||||
|
||||
# 移除原有的脚注定义(它们会被重新添加到最后)
|
||||
processed_content = re.sub(
|
||||
r"\[\^\d+\]:\s*.+?(?=\n\[\^|\n\n|\Z)",
|
||||
"",
|
||||
processed_content,
|
||||
flags=re.DOTALL,
|
||||
)
|
||||
|
||||
# 清理多余的空行
|
||||
processed_content = re.sub(r"\n{3,}", "\n\n", processed_content)
|
||||
|
||||
# 添加统一的参考文献部分
|
||||
if footnote_mapping:
|
||||
processed_content += "\n\n## 参考文献\n\n"
|
||||
|
||||
# 按新编号顺序添加脚注
|
||||
for old_num in sorted(
|
||||
footnote_mapping.keys(), key=lambda x: int(footnote_mapping[x])
|
||||
):
|
||||
new_num = footnote_mapping[old_num]
|
||||
if old_num in footnote_contents:
|
||||
processed_content += f"[^{new_num}]: {footnote_contents[old_num]}\n"
|
||||
else:
|
||||
logger.warning(f"脚注 {old_num} 被引用但未找到定义")
|
||||
|
||||
logger.info(f"参考文献部分添加完成,共有 {len(footnote_mapping)} 个脚注")
|
||||
|
||||
logger.info(f"结果处理完成,最终内容长度: {len(processed_content)}")
|
||||
return processed_content
|
||||
|
||||
def save_result(self, ques_count):
|
||||
res_path = os.path.join(self.work_dir, "res.md")
|
||||
|
||||
Reference in New Issue
Block a user