Skip to content

Commit abb17af

Browse files
committed
update
update
1 parent db5f469 commit abb17af

35 files changed

+362
-240
lines changed

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
> 欢迎贡献
6060
6161

62-
案例参考 ./demo 文件夹下
63-
如果你有好的案例可以提交 PR 在该目录下
62+
案例参考 [demo](./demo/) 文件夹下
63+
**如果你有跑出来好的案例可以提交 PR 在该目录下**
6464

6565
## 📖 使用教程
6666

@@ -73,7 +73,9 @@
7373
1. 配置模型
7474

7575
复制`/backend/.env.dev.example``/backend/.env.dev`(删除`.example` 后缀)
76+
7677
**配置环境变量**
78+
7779
推荐模型能力较强的、参数量大的模型。
7880

7981

@@ -114,10 +116,11 @@ pnpm i #确保电脑安装了 pnpm
114116
pnpm run dev
115117
```
116118

119+
[教程](./docs/md/tutorial.md)
117120

118121
运行的结果和产生在`backend/project/work_dir/xxx/*`目录下
119122
- notebook.ipynb: 保存运行过程中产生的代码
120-
- res.md: 保存最后运行产生的结果为 markdown 格式,使用 markdown 转 word(研究下 pandoc)
123+
- res.md: 保存最后运行产生的结果为 markdown 格式
121124

122125
## 🤝 贡献和开发
123126

@@ -134,8 +137,8 @@ clone 项目后,下载 **Todo Tree** 插件,可以查看代码中所有具
134137

135138
## 📄 版权License
136139

137-
个人免费使用,请勿商业用途,商业用途联系我(作者)
138-
禁止闭源分发
140+
个人免费使用,请勿商业用途
141+
[License](./docs/md/License.md)
139142

140143
## 🙏 Reference
141144

@@ -150,9 +153,7 @@ Thanks to the following projects:
150153

151154
### Sponsor
152155

153-
<div align="center">
154-
<img src="./docs/sponser.png" alt="Buy Me a Coffee" width="280"/>
155-
</div>
156+
[Buy Me a Coffee](./docs/sponser.md)
156157

157158
感谢赞助
158159
[danmo-tyc](https://github.com/danmo-tyc)
@@ -162,4 +163,6 @@ Thanks to the following projects:
162163
有问题可以进群问
163164
[QQ 群:699970403](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=rFKquDTSxKcWpEhRgpJD-dPhTtqLwJ9r&authKey=xYKvCFG5My4uYZTbIIoV5MIPQedW7hYzf0%2Fbs4EUZ100UegQWcQ8xEEgTczHsyU6&noverify=0&group_code=699970403)
164165

165-
<img src="./docs/qq.jpg" height="400px">
166+
<div align="center">
167+
<img src="./docs/qq.jpg" height="400px">
168+
</div>

backend/app/core/agents/coder_agent.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from app.core.agents.agent import Agent
22
from app.config.setting import settings
33
from app.utils.log_util import logger
4-
from app.utils.redis_manager import redis_manager
5-
from app.schemas.response import SystemMessage
4+
from app.services.redis_manager import redis_manager
5+
from app.schemas.response import SystemMessage, InterpreterMessage
66
from app.tools.base_interpreter import BaseCodeInterpreter
77
from app.core.llm.llm import LLM
8-
from app.models.model import CoderToWriter
8+
from app.schemas.A2A import CoderToWriter
99
from app.core.prompts import CODER_PROMPT
1010
from app.utils.common_utils import get_current_files
1111
import json
@@ -108,7 +108,16 @@ async def run(self, prompt: str, subtask_title: str) -> CoderToWriter:
108108
content=f"代码手调用{tool_call.function.name}工具"
109109
),
110110
)
111+
111112
code = json.loads(tool_call.function.arguments)["code"]
113+
114+
await redis_manager.publish_message(
115+
self.task_id,
116+
InterpreterMessage(
117+
input={"code": code},
118+
),
119+
)
120+
112121
full_content = response.choices[0].message.content
113122
# 更新对话历史 - 添加助手的响应
114123
self.append_chat_history(
@@ -197,8 +206,6 @@ async def run(self, prompt: str, subtask_title: str) -> CoderToWriter:
197206
agent_name=self.__class__.__name__,
198207
)
199208

200-
# # TODO: 压缩对话历史
201-
202209
## 没有调用工具,代表已经完成了
203210
if not (
204211
hasattr(completion_response.choices[0].message, "tool_calls")
@@ -209,10 +216,14 @@ async def run(self, prompt: str, subtask_title: str) -> CoderToWriter:
209216
return CoderToWriter(
210217
coder_response=completion_response.choices[
211218
0
212-
].message.content
219+
].message.content,
220+
created_images=await self.code_interpreter.get_created_images(
221+
subtask_title
222+
),
213223
)
214224
else:
215225
logger.info("没有工具,代表任务完成")
226+
task_completed = True
216227

217228
if retry_count >= self.max_retries:
218229
logger.error(f"超过最大尝试次数: {self.max_retries}")
@@ -224,4 +235,9 @@ async def run(self, prompt: str, subtask_title: str) -> CoderToWriter:
224235

225236
logger.info(f"{self.__class__.__name__}:完成:执行子任务: {subtask_title}")
226237

227-
return CoderToWriter(coder_response=response.choices[0].message.content)
238+
return CoderToWriter(
239+
coder_response=response.choices[0].message.content,
240+
created_images=await self.code_interpreter.get_created_images(
241+
subtask_title
242+
),
243+
)

backend/app/core/agents/coordinator_agent.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from app.core.prompts import COORDINATOR_PROMPT
44
import json
55
from app.utils.log_util import logger
6-
from app.models.model import CoordinatorToModeler
6+
from app.schemas.A2A import CoordinatorToModeler
77

88

99
class CoordinatorAgent(Agent):
@@ -18,7 +18,6 @@ def __init__(
1818

1919
async def run(self, ques_all: str) -> CoordinatorToModeler:
2020
"""用户输入问题 使用LLM 格式化 questions"""
21-
# TODO: "note": <补充说明,如果没有补充说明,请填 null>,
2221
self.append_chat_history({"role": "system", "content": self.system_prompt})
2322
self.append_chat_history({"role": "user", "content": ques_all})
2423

backend/app/core/agents/modeler_agent.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from app.core.agents.agent import Agent
22
from app.core.llm.llm import LLM
33
from app.core.prompts import MODELER_PROMPT
4-
from app.models.model import CoordinatorToModeler, ModelerToCoder
4+
from app.schemas.A2A import CoordinatorToModeler, ModelerToCoder
55
from app.utils.log_util import logger
66
import json
7+
from icecream import ic
78

89

910
class ModelerAgent(Agent): # 继承自Agent类
@@ -21,7 +22,7 @@ async def run(self, coordinator_to_modeler: CoordinatorToModeler) -> ModelerToCo
2122
self.append_chat_history(
2223
{
2324
"role": "user",
24-
"content": coordinator_to_modeler.questions.model_dump_json(),
25+
"content": json.dumps(coordinator_to_modeler.questions),
2526
}
2627
)
2728

@@ -36,9 +37,9 @@ async def run(self, coordinator_to_modeler: CoordinatorToModeler) -> ModelerToCo
3637

3738
if not json_str:
3839
raise ValueError("返回的 JSON 字符串为空,请检查输入内容。")
39-
4040
try:
4141
questions_solution = json.loads(json_str)
42+
ic(questions_solution)
4243
return ModelerToCoder(questions_solution=questions_solution)
4344
except json.JSONDecodeError as e:
4445
raise ValueError(f"JSON 解析错误: {e}")

backend/app/core/agents/writer_agent.py

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
from app.core.agents.agent import Agent
22
from app.core.llm.llm import LLM
33
from app.core.prompts import get_writer_prompt
4-
from app.utils.enums import CompTemplate, FormatOutPut
5-
from app.models.user_output import UserOutput
4+
from app.schemas.enums import CompTemplate, FormatOutPut
65
from app.tools.openalex_scholar import OpenAlexScholar
76
from app.utils.log_util import logger
8-
from app.utils.redis_manager import redis_manager
9-
from app.schemas.response import SystemMessage
7+
from app.services.redis_manager import redis_manager
8+
from app.schemas.response import SystemMessage, WriterMessage
109
import json
1110
from app.core.functions import writer_tools
12-
from app.utils.common_utils import get_footnotes
11+
from app.utils.common_utils import split_footnotes
1312
from icecream import ic
14-
from app.models.model import WriterResponse
13+
from app.schemas.A2A import WriterResponse
1514

1615

1716
# 长文本
@@ -27,13 +26,14 @@ def __init__(
2726
max_chat_turns: int = 10, # 添加最大对话轮次限制
2827
comp_template: CompTemplate = CompTemplate,
2928
format_output: FormatOutPut = FormatOutPut.Markdown,
30-
user_output: UserOutput = None,
3129
scholar: OpenAlexScholar = None,
30+
max_memory: int = 25, # 添加最大记忆轮次
3231
) -> None:
33-
super().__init__(task_id, model, max_chat_turns, user_output)
32+
super().__init__(task_id, model, max_chat_turns, max_memory)
3433
self.format_out_put = format_output
3534
self.comp_template = comp_template
3635
self.scholar = scholar
36+
self.is_first_run = True
3737
self.system_prompt = get_writer_prompt(format_output)
3838
self.available_images: list[str] = []
3939

@@ -52,19 +52,21 @@ async def run(
5252
"""
5353
logger.info(f"subtitle是:{sub_title}")
5454

55+
if self.is_first_run:
56+
self.is_first_run = False
57+
self.append_chat_history({"role": "system", "content": self.system_prompt})
58+
5559
if available_images:
5660
self.available_images = available_images
5761
# 拼接成完整URL
5862
image_list = ",".join(available_images)
5963
image_prompt = f"\n可用的图片链接列表:\n{image_list}\n请在写作时适当引用这些图片链接。"
60-
ic(image_prompt)
64+
logger.info(f"image_prompt是:{image_prompt}")
6165
prompt = prompt + image_prompt
6266

6367
logger.info(f"{self.__class__.__name__}:开始:执行对话")
6468
self.current_chat_turns += 1 # 重置对话轮次计数器
6569

66-
# 更新对话历史
67-
self.append_chat_history({"role": "system", "content": self.system_prompt})
6870
self.append_chat_history({"role": "user", "content": prompt})
6971

7072
# 获取历史消息用于本次对话
@@ -76,6 +78,8 @@ async def run(
7678
sub_title=sub_title,
7779
)
7880

81+
footnotes = []
82+
7983
if (
8084
hasattr(response.choices[0].message, "tool_calls")
8185
and response.choices[0].message.tool_calls
@@ -92,7 +96,14 @@ async def run(
9296
)
9397

9498
query = json.loads(tool_call.function.arguments)["query"]
95-
footnotes = get_footnotes(query)
99+
100+
await redis_manager.publish_message(
101+
self.task_id,
102+
WriterMessage(
103+
input={"query": query},
104+
),
105+
)
106+
96107
full_content = response.choices[0].message.content
97108
# 更新对话历史 - 添加助手的响应
98109
self.append_chat_history(
@@ -113,10 +124,13 @@ async def run(
113124
)
114125

115126
try:
116-
papers = self.scholar.search_papers(query)
127+
papers = await self.scholar.search_papers(query)
117128
except Exception as e:
118-
logger.error(f"搜索文献失败: {str(e)}")
119-
return f"搜索文献失败: {str(e)}"
129+
error_msg = f"搜索文献失败: {str(e)}"
130+
logger.error(error_msg)
131+
return WriterResponse(
132+
response_content=error_msg, footnotes=footnotes
133+
)
120134
# TODO: pass to frontend
121135
papers_str = self.scholar.papers_to_str(papers)
122136
logger.info(f"搜索文献结果\n{papers_str}")
@@ -136,6 +150,9 @@ async def run(
136150
sub_title=sub_title,
137151
)
138152
response_content = next_response.choices[0].message.content
153+
main_text, footnotes = split_footnotes(response_content)
154+
logger.info(f"使用到的footnotes: {footnotes}")
155+
response_content = main_text
139156
else:
140157
response_content = response.choices[0].message.content
141158
self.chat_history.append({"role": "assistant", "content": response_content})

backend/app/core/flows.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55

66
class Flows:
7-
def __init__(self):
7+
def __init__(self, questions: dict[str, str | int]):
88
self.flows: dict[str, dict] = {}
9+
self.questions: dict[str, str | int] = questions
910

1011
def set_flows(self, ques_count: int):
1112
ques_str = [f"ques{i}" for i in range(1, ques_count + 1)]
@@ -139,6 +140,5 @@ def get_seq(self, ques_count: int) -> dict[str, str]:
139140
*ques_str,
140141
"sensitivity_analysis",
141142
"judge",
142-
"reference",
143143
]
144144
return {key: "" for key in seq}

0 commit comments

Comments
 (0)