Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何将响应保存到工作空间,我调用相应的api错误信息也不是很明确 #1761

Open
youbiaokachi123 opened this issue Mar 13, 2025 · 0 comments

Comments

@youbiaokachi123
Copy link

Bug description
我想在Action响应的时候,将相应结果保存为一个文件,我调用了这行代码
await self.repo.resources.code_summary.save(filename="prd.md", content=response),我却得到一个错误
`2025-03-13 20:21:05.436 | ERROR | metagpt.utils.common:wrapper:631 - Exception occurs, start to serialize the project, exp:
Traceback (most recent call last):
File "/Users/huanhu/PycharmProjects/hello_metagpt/.venv/lib/python3.11/site-packages/metagpt/utils/common.py", line 640, in wrapper
return await func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/huanhu/PycharmProjects/hello_metagpt/.venv/lib/python3.11/site-packages/metagpt/roles/role.py", line 550, in run
rsp = await self.react()
^^^^^^^^^^^^^^^^^^
ValueError: Invalid root

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/huanhu/PycharmProjects/hello_metagpt/.venv/lib/python3.11/site-packages/metagpt/utils/common.py", line 626, in wrapper
result = await func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/huanhu/PycharmProjects/hello_metagpt/.venv/lib/python3.11/site-packages/metagpt/team.py", line 134, in run
await self.env.run()
Exception: Traceback (most recent call last):
File "/Users/huanhu/PycharmProjects/hello_metagpt/.venv/lib/python3.11/site-packages/metagpt/utils/common.py", line 640, in wrapper
return await func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/huanhu/PycharmProjects/hello_metagpt/.venv/lib/python3.11/site-packages/metagpt/roles/role.py", line 550, in run
rsp = await self.react()
^^^^^^^^^^^^^^^^^^
File "/Users/huanhu/PycharmProjects/hello_metagpt/.venv/lib/python3.11/site-packages/metagpt/roles/role.py", line 517, in react
rsp = await self._react()
^^^^^^^^^^^^^^^^^^^
File "/Users/huanhu/PycharmProjects/hello_metagpt/.venv/lib/python3.11/site-packages/metagpt/roles/role.py", line 463, in _react
rsp = await self._act()
^^^^^^^^^^^^^^^^^
File "/Users/huanhu/PycharmProjects/hello_metagpt/huhuan_soft_company.py", line 41, in _act
response = await todo.run(msg.content)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/huanhu/PycharmProjects/hello_metagpt/huhuan_soft_company.py", line 24, in run
await self.repo.resources.code_summary.save(filename="prd.md", content=response)
^^^^^^^^^
File "/Users/huanhu/PycharmProjects/hello_metagpt/.venv/lib/python3.11/site-packages/metagpt/actions/action.py", line 42, in repo
self.context.repo = ProjectRepo(self.context.git_repo)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/huanhu/PycharmProjects/hello_metagpt/.venv/lib/python3.11/site-packages/metagpt/utils/project_repo.py", line 97, in init
raise ValueError("Invalid root")
ValueError: Invalid root
`

code
`from metagpt.actions import Action
from metagpt.roles import Role
from metagpt.schema import Message
from metagpt.logs import logger
import asyncio

from metagpt.team import Team

class WritePrd(Action):
PROMPT_TEMPLATE: str = "{instruction}"

name: str = "编写项目需求文档"

async def run(self, instruction: str):
    prompt = self.PROMPT_TEMPLATE.format(instruction=instruction)
    response = await self._aask(prompt)
    await self.repo.resources.code_summary.save(filename="prd.md", content=response)
    return response

class ProductManage(Role):
name: str = "huhuan"

profile: str = "ProductManage"

def __init__(self, **kwargs):
    super().__init__(**kwargs)
    self.set_actions([WritePrd])

async def _act(self) -> Message:
    logger.info(f"{self._setting}: to do {self.rc.todo}({self.rc.todo.name})")
    todo = self.todo
    msg = self.get_memories(k=1)[0]
    response = await todo.run(msg.content)
    msg = Message(content=response, role=self.profile, cause_by=type(todo))

    return msg

async def main():
company = Team()
company.hire([
ProductManage()
])
company.invest(investment=3)

idea = "你好"
company.run_project(idea)
await company.run(n_round=5)

if name == 'main':
asyncio.run(main())
`

@youbiaokachi123 youbiaokachi123 changed the title 如何将相应保存到工作空间,我调用相应的api错误信息也不是很明确 如何将响应保存到工作空间,我调用相应的api错误信息也不是很明确 Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant