geekan / MetaGPT

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
https://deepwisdom.ai/
MIT License
43.93k stars 5.23k forks source link

parse_code报错 #11

Closed iRPoke closed 1 year ago

iRPoke commented 1 year ago

The specific requirements for fine-tuning algorithms for the Hua project are not clear. 2023-07-06 16:20:38.774 | INFO | metagpt.provider.openai_api:update_cost:91 - Total running cost: $0.007 | Max budget: $3.000 | Current cost: $0.004, prompt_tokens=1235, completion_tokens=561 2023-07-06 16:20:38.777 | ERROR | metagpt.utils.common:parse_code:66 - .*?\s+(.*?) not match following text: 2023-07-06 16:20:38.778 | ERROR | metagpt.utils.common:parse_code:67 - training_platform Traceback (most recent call last): File "D:\Code\MetaGPT\startup.py", line 29, in fire.Fire(main) File "D:\Anaconda\envs\metagpt\lib\site-packages\fire\core.py", line 141, in Fire component_trace = _Fire(component, args, parsed_flag_args, context, name) File "D:\Anaconda\envs\metagpt\lib\site-packages\fire\core.py", line 475, in _Fire component, remaining_args = _CallAndUpdateTrace( File "D:\Anaconda\envs\metagpt\lib\site-packages\fire\core.py", line 691, in _CallAndUpdateTrace component = fn(*varargs, **kwargs) File "D:\Code\MetaGPT\startup.py", line 25, in main asyncio.run(startup(idea, investment)) raise Exception Exception Exception ignored in: <function _ProactorBasePipeTransport.del at 0x0000021B94788E50> Traceback (most recent call last): File "D:\Anaconda\envs\metagpt\lib\asyncio\proactor_events.py", line 116, in del self.close() File "D:\Anaconda\envs\metagpt\lib\asyncio\proactor_events.py", line 108, in close self._loop.call_soon(self._call_connection_lost, None) File "D:\Anaconda\envs\metagpt\lib\asyncio\base_events.py", line 751, in call_soon self._check_closed() File "D:\Anaconda\envs\metagpt\lib\asyncio\base_events.py", line 515, in _check_closed raise RuntimeError('Event loop is closed') RuntimeError: Event loop is closed

geekan commented 1 year ago

是否可以提供更多的日志?

joisonwk commented 1 year ago

@geekan 我也遇到这个问题,测试了几次都是这个错误, 会不会因为我用的GPT3.5的原因。下面是详细的日志:

python startup.py "Write a Snake Game" 2023-07-09 17:41:28.549 | INFO | metagpt.config:init:43 - Config loading done. 2023-07-09 17:41:28.549 | INFO | metagpt.config:init:49 - Set OPENAI_API_BASE in case of network issues 2023-07-09 17:41:29.699 | INFO | metagpt.software_company:invest:39 - Investment: $3.0. 2023-07-09 17:41:29.699 | INFO | metagpt.roles.role:_act:153 - Alice(Product Manager): ready to WritePRD Sure, I can help you with that. Writing a Snake Game can be a fun project. There are several resources available to guide you through the process. Here are a few options:

  1. Snake Game Program using Pygame: This tutorial provides step-by-step instructions on creating a Snake Game using the Pygame library in Python. Pygame is a free and open-source library commonly used for game development.

  2. Create a Snake-Game using Turtle in Python: This tutorial demonstrates how to create a Snake Game using the Turtle module in Python. Turtle is a built-in module in Python that allows for easy graphics and animation.

  3. JavaScript snake game tutorial: Build a simple, interactive game: If you prefer to create the Snake Game using JavaScript, this tutorial is a great resource. It covers topics such as displaying the game board, making the snake move automatically, and handling user input.

  4. Python Snake Game in 5 minutes - YouTube: This video tutorial on YouTube walks you through creating a Snake Game in Python using Pygame. It provides a concise demonstration of the process in just 60 lines of code.

  5. Code a Snake Game with Python and Pygame - Tutorial: Another video tutorial on YouTube, this one focuses on building a Snake Game using Python and Pygame. It's a beginner-friendly project that can give you exposure to game development.

Feel free to choose the resource that best suits your preferences and programming language of choice. Happy coding! Warning: gpt-3.5-turbo may change over time. Returning num tokens assuming gpt-3.5-turbo-0301. 2023-07-09 17:42:04.270 | INFO | metagpt.provider.openai_api:update_cost:89 - Total running cost: $0.003 | Max budget: $3.000 | Current cost: $0.003, prompt_tokens=950, completion_tokens=382 2023-07-09 17:42:04.271 | INFO | metagpt.actions.writeprd:run:72 - Snake Game in Python using Pygame which is free and open-source Python library used to create games.Create snake,add food,increase snake ... [{'title': 'Snake Game Program using Pygame', 'link': 'https://www.edureka.co/blog/snake-game-with-pygame/', 'snippet': 'Snake Game in Python using Pygame which is free and open-source Python library used to create games.Create snake,add food,increase snake ...'}, {'title': 'Create a Snake-Game using Turtle in Python', 'link': 'https://www.geeksforgeeks.org/create-a-snake-game-using-turtle-in-python/', 'snippet': 'The code starts by creating a window screen. · The title of the window is “Snake Game”. · The background color of the window is blue. · Next, the ...'}, {'title': 'JavaScript snake game tutorial: Build a simple, interactive ...', 'link': 'https://www.educative.io/blog/javascript-snake-game-tutorial', 'snippet': 'JavaScript snake game tutorial: Build a simple, interactive game · Display the board and a still snake · Make the snake move automatically · Use ...'}, {'title': 'Python Snake Game in 5 minutes - YouTube', 'link': 'https://www.youtube.com/watch?v=-KjEgCLQFw', 'snippet': 'This is Pygame Tutorial on how to create a Snake Game in 60 lines of code in Python for beginners.More Python Projects: ...'}, {'title': 'Code a Snake Game with Python and Pygame - Tutorial', 'link': 'https://www.youtube.com/watch?v=8dfePlONtls', 'snippet': 'In this Python / Pygame tutorial you will build a snake and apple game. This Python project for beginners is perfect for you to get exposure ...'}, {'title': 'How to Make a Snake Game in Python', 'link': 'https://geekflare.com/snake-game-in-python/', 'snippet': 'Creating a beginner-friendly snake game tutorial by using the turtle, time, and random pre-installed modules.'}, {'title': 'How to Build a Snake Game In JavaScript', 'link': 'https://www.freecodecamp.org/news/how-to-build-a-snake-game-in-javascript/', 'snippet': 'In this article I am going to show you how to build a snake game with JavaScript. A snake game is a simple game where a snake moves around a ...'}, {'title': 'A Simple Snake Game made in Python 3', 'link': 'https://gist.github.com/wynand1004/ec105fd2f457b10d971c09586ec44900', 'snippet': 'Nice game, you can create classes for the snake body, scoreboard, food and maybe wall. Then the code will be more structured :).'}, {'title': 'Build the Snake Game with Pygame', 'link': 'https://docs.replit.com/tutorials/python/build-snake-with-pygame', 'snippet': 'Creating a New Project\u200b. Head over to Replit and create a new repl. Choose Python as your language. Now, give this repl a name, like "snake- ...'}] 2023-07-09 17:42:04.271 | INFO | metagpt.actions.write_prd:run:73 - Sure, I can help you with that. Writing a Snake Game can be a fun project. There are several resources available to guide you through the process. Here are a few options:

  1. Snake Game Program using Pygame: This tutorial provides step-by-step instructions on creating a Snake Game using the Pygame library in Python. Pygame is a free and open-source library commonly used for game development.

  2. Create a Snake-Game using Turtle in Python: This tutorial demonstrates how to create a Snake Game using the Turtle module in Python. Turtle is a built-in module in Python that allows for easy graphics and animation.

  3. JavaScript snake game tutorial: Build a simple, interactive game: If you prefer to create the Snake Game using JavaScript, this tutorial is a great resource. It covers topics such as displaying the game board, making the snake move automatically, and handling user input.

  4. Python Snake Game in 5 minutes - YouTube: This video tutorial on YouTube walks you through creating a Snake Game in Python using Pygame. It provides a concise demonstration of the process in just 60 lines of code.

  5. Code a Snake Game with Python and Pygame - Tutorial: Another video tutorial on YouTube, this one focuses on building a Snake Game using Python and Pygame. It's a beginner-friendly project that can give you exposure to game development.

Feel free to choose the resource that best suits your preferences and programming language of choice. Happy coding!

Original Requirements:

Write a Snake Game

Product Goals:

  1. Create a fun and engaging Snake Game that provides an enjoyable gaming experience.
  2. Develop a user-friendly interface that is easy to navigate and understand.
  3. Ensure the game is efficient and optimized for smooth gameplay.

User Stories:

  1. As a player, I want to be able to control the snake's movement using arrow keys.
  2. As a player, I want to see my score increase whenever the snake eats the food.
  3. As a player, I want the game to end if the snake hits the wall or its own body.
  4. As a player, I want to be able to restart the game after it ends.
  5. As a player, I want the game to have sound effects and background music for an immersive experience.

Competitive Analysis:

  1. Snake Game Program using Pygame: Provides step-by-step instructions on creating a Snake Game using the Pygame library in Python.
  2. Create a Snake-Game using Turtle in Python: Demonstrates how to create a Snake Game using the Turtle module in Python.
  3. JavaScript snake game tutorial: Build a simple, interactive game: A tutorial on building a Snake Game using JavaScript.
  4. Python Snake Game in 5 minutes - YouTube: A video tutorial on creating a Snake Game in Python using Pygame.
  5. Code a Snake Game with Python and Pygame - Tutorial: Another video tutorial on building a Snake Game using Python and Pygame.
  6. How to Make a Snake Game in Python: A beginner-friendly snake game tutorial using the turtle, time, and random pre-installed modules.
  7. How to Build a Snake Game In JavaScript: A tutorial on building a Snake Game with JavaScript.

Competitive Quadrant Chart:

quadrantChart
    title Reach and engagement of Snake Game tutorials
    x-axis Low Reach --> High Reach
    y-axis Low Engagement --> High Engagement
    quadrant-1 We should expand
    quadrant-2 Need to promote
    quadrant-3 Re-evaluate
    quadrant-4 May be improved
    "Snake Game Program using Pygame": [0.6, 0.7]
    "Create a Snake-Game using Turtle in Python": [0.4, 0.5]
    "JavaScript snake game tutorial: Build a simple, interactive game": [0.7, 0.8]
    "Python Snake Game in 5 minutes - YouTube": [0.8, 0.6]
    "Code a Snake Game with Python and Pygame - Tutorial": [0.9, 0.7]
    "How to Make a Snake Game in Python": [0.5, 0.4]
    "How to Build a Snake Game In JavaScript": [0.6, 0.6]
    "Our Target Product": [0.7, 0.7]

Requirement Analysis:

The goal is to create a Snake Game that provides an enjoyable gaming experience for users. The game should have a user-friendly interface, allowing players to control the snake's movement using arrow keys. The score should increase whenever the snake eats the food, and the game should end if the snake hits the wall or its own body. Players should be able to restart the game after it ends. Sound effects and background music should be included to enhance the immersive experience. The game should be efficient and optimized for smooth gameplay.

Requirement Pool:

  1. The game should have a start screen with instructions on how to play the game. (P0)
  2. The snake should move continuously in the direction specified by the player until it hits the wall or its own body. (P0)
  3. The game should generate food at random locations on the screen. (P0)
  4. The snake's length should increase by one whenever it eats the food. (P0)
  5. The score should be displayed on the screen and increase by one whenever the snake eats the food. (P1)

Anything UNCLEAR:

No, everything seems clear. Warning: gpt-3.5-turbo may change over time. Returning num tokens assuming gpt-3.5-turbo-0301. 2023-07-09 17:43:02.454 | INFO | metagpt.provider.openai_api:update_cost:89 - Total running cost: $0.008 | Max budget: $3.000 | Current cost: $0.005, prompt_tokens=1675, completion_tokens=833 2023-07-09 17:43:02.456 | INFO | metagpt.roles.role:_act:153 - Bob(Architect): ready to WriteDesign

Implementation approach:

Based on the requirements, we will use the Pygame library to implement the Snake Game in Python. Pygame is a popular open-source library that provides functionality for creating games and multimedia applications. It has a user-friendly interface and provides efficient and optimized performance for smooth gameplay. We will also leverage other open-source tools and libraries to enhance the gaming experience.

Python package name: snake_game

File list:

  • main.py
  • snake.py
  • food.py
  • game.py
  • sound.py
  • assets/
    • background.png
    • snake.png
    • food.png
    • sound_effects/
    • eat.wav
    • game_over.wav
    • music/
    • background_music.mp3

Data structures and interface definitions:

class Snake
- body: List[Tuple[int, int]]
- direction: Tuple[int, int]
- grow: bool

+ __init__(self, x: int, y: int, length: int)
+ move(self)
+ change_direction(self, direction: Tuple[int, int])
+ eat_food(self)
+ check_collision(self, width: int, height: int) -> bool
+ draw(self, surface: pygame.Surface)

class Food
- position: Tuple[int, int]

+ __init__(self, width: int, height: int)
+ generate(self, snake_body: List[Tuple[int, int]])
+ draw(self, surface: pygame.Surface)

class Game
- width: int
- height: int
- snake: Snake
- food: Food
- score: int
- game_over: bool

+ __init__(self, width: int, height: int)
+ handle_events(self)
+ update(self)
+ render(self, surface: pygame.Surface)
+ restart(self)

class Sound
- eat_sound: pygame.mixer.Sound
- game_over_sound: pygame.mixer.Sound
- background_music: pygame.mixer.music

+ __init__(self)
+ play_eat_sound(self)
+ play_game_over_sound(self)
+ play_background_music(self)
+ stop_background_music(self)

Program call flow:

Title: Snake Game Call Flow

main.py->Game: Initialize Game
Game->Game: Set width and height
Game->Snake: Initialize Snake
Game->Food: Initialize Food
Game->Sound: Initialize Sound
Game->Game: Main Game Loop
Game->Game: Handle Events
Game->Snake: Change Direction (if arrow key pressed)
Game->Game: Update Snake Position
Game->Snake: Move
Game->Snake: Check Collision
Game->Food: Generate Food
Game->Snake: Eat Food (if collision)
Game->Game: Update Score
Game->Game: Render Game
Game->Game: Check Game Over
Game->Game: Handle Game Over
Game->Game: Restart Game (if restart key pressed)

Anything UNCLEAR:

No, everything seems clear. Warning: gpt-3.5-turbo may change over time. Returning num tokens assuming gpt-3.5-turbo-0301. 2023-07-09 17:43:46.261 | INFO | metagpt.provider.openai_api:update_cost:89 - Total running cost: $0.011 | Max budget: $3.000 | Current cost: $0.004, prompt_tokens=1231, completion_tokens=605 2023-07-09 17:43:46.263 | ERROR | metagpt.utils.common:parse_code:67 - .*?\s+(.*?) not match following text: 2023-07-09 17:43:46.263 | ERROR | metagpt.utils.common:parse_code:68 - Traceback (most recent call last): File "/home/ant/GPT/MetaGPT/startup.py", line 29, in fire.Fire(main) File "/home/ant/GPT/tools/venv/lib/python3.10/site-packages/fire/core.py", line 141, in Fire component_trace = _Fire(component, args, parsed_flag_args, context, name) File "/home/ant/GPT/tools/venv/lib/python3.10/site-packages/fire/core.py", line 475, in _Fire component, remaining_args = _CallAndUpdateTrace( File "/home/ant/GPT/tools/venv/lib/python3.10/site-packages/fire/core.py", line 691, in _CallAndUpdateTrace component = fn(*varargs, *kwargs) File "/home/ant/GPT/MetaGPT/startup.py", line 25, in main asyncio.run(startup(idea, investment, n_round)) File "/home/ant/GPT/tools/venv/lib/python3.10/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/home/ant/GPT/tools/venv/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete return future.result() File "/home/ant/GPT/MetaGPT/startup.py", line 15, in startup await company.run(n_round=n_round) File "/home/ant/GPT/MetaGPT/metagpt/software_company.py", line 60, in run await self.environment.run() File "/home/ant/GPT/MetaGPT/metagpt/environment.py", line 58, in run await asyncio.gather(futures) File "/home/ant/GPT/MetaGPT/metagpt/roles/role.py", line 223, in run rsp = await self._react() File "/home/ant/GPT/MetaGPT/metagpt/roles/role.py", line 194, in _react return await self._act() File "/home/ant/GPT/MetaGPT/metagpt/roles/role.py", line 154, in _act response = await self._rc.todo.run(self._rc.important_memory) File "/home/ant/GPT/MetaGPT/metagpt/actions/design_api.py", line 86, in run self._save(context, system_design) File "/home/ant/GPT/MetaGPT/metagpt/actions/design_api.py", line 73, in _save ws_name = CodeParser.parse_str(block="Python package name", text=system_design) File "/home/ant/GPT/MetaGPT/metagpt/utils/common.py", line 74, in parse_str code = cls.parse_code(block, text, lang) File "/home/ant/GPT/MetaGPT/metagpt/utils/common.py", line 69, in parse_code raise Exception Exception

geekan commented 1 year ago

@iRPoke @joisonwk 是的。用4会稳定的多,3.5目前效果很不稳定

geekan commented 1 year ago

41 #43 fix this issue.

Hezhexi2002 commented 1 year ago

@iRPoke @joisonwk 是的。用4会稳定的多,3.5目前效果很不稳定

你好,我使用的chimeragpt提供的第三方gpt4 api key也出现了这个错误,是因为第三方api key访问不稳定吗? image 但是我查看我的workspace已经生成了一个文件: image

tt7292000 commented 1 year ago

我是用GPT4时也会出现这个错误,以下是我的日志 I also encountered this error when using GPT4. Here is my log

Exception ignored in: <function _ProactorBasePipeTransport.del at 0x000001BDFA0723A0> Traceback (most recent call last): File "C:\env\MetaEnv\lib\asyncio\proactor_events.py", line 116, in del self.close() File "C:\env\MetaEnv\lib\asyncio\proactor_events.py", line 108, in close self._loop.call_soon(self._call_connection_lost, None) File "C:\env\MetaEnv\lib\asyncio\base_events.py", line 751, in call_soon self._check_closed() File "C:\env\MetaEnv\lib\asyncio\base_events.py", line 515, in _check_closed raise RuntimeError('Event loop is closed') RuntimeError: Event loop is closed