MetaGPT icon indicating copy to clipboard operation
MetaGPT copied to clipboard

feat(core): Add stream data return and reception

Open Ley-WL opened this issue 10 months ago • 6 comments

  1. add file: utils/steam_pipe.py
  2. add demo: samples/flask_web_api.py
  3. Other core code modifications, Add and use the StreamPipe class at night
  4. Add flask library to requirements

Features

  • xx
  • yy

Feature Docs

Influence Not affecting other functions

Result

4b5a6673dfb9d9fe06dd0272ff89d39 Download this MD file here e9207c3f6e6c4bf6edb7b95736221a7

Other

Ley-WL avatar Mar 27 '24 07:03 Ley-WL

Codecov Report

Attention: Patch coverage is 0% with 17 lines in your changes are missing coverage. Please review.

Project coverage is 81.18%. Comparing base (6434503) to head (f646715). Report is 245 commits behind head on main.

Files Patch % Lines
metagpt/utils/stream_pipe.py 0.00% 17 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1118      +/-   ##
==========================================
- Coverage   81.52%   81.18%   -0.34%     
==========================================
  Files         248      249       +1     
  Lines       13895    13912      +17     
==========================================
- Hits        11328    11295      -33     
- Misses       2567     2617      +50     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Mar 27 '24 07:03 codecov-commenter

Awesome! Let’s start Code Review now!

geekan avatar Mar 27 '24 07:03 geekan

@2495165664 . This is a good example, but the introduction of stream_pipe has intruded upon the original implementation. We can optimize it. With the help of metagpt.logs.set_llm_stream_logfunc and contextvars.ContextVar, we can achieve the same functionality without modifying any code under the metagpt directory.

Update the metagpt/utils/stream_pipe.py:

...
from contextvars import ContextVar
from metagpt.logs import set_llm_stream_logfunc


stream_pipe_var: ContextVar[StreamPipe] = ContextVar("stream_pipe")


def stream_pipe_log(content):
    stream_pipe = stream_pipe_var.get(None)
    if stream_pipe :
        stream_pipe.set_message(content)


set_llm_stream_logfunc(stream_pipe_log)


def write_tutorial(message):
    async def main(idea, stream_pipe):
        stream_pipe_var.set(stream_pipe)
        role = TutorialAssistant()
        await role.run(idea)
    ...

shenchucheng avatar Mar 27 '24 08:03 shenchucheng

Hello, there are still some CRs that need to be modified. After modification, they can be merged.

geekan avatar Apr 05 '24 14:04 geekan

lgtm

better629 avatar Apr 08 '24 01:04 better629

@2495165664 there is a conflict

<<<<<<< main
    "web-api": ["flask==3.0.2"],
=======
    "android_assistant": ["pyshine==0.0.9", "opencv-python==4.6.0.66"],
>>>>>>> main

you should keep web-api and android_assistant both.

better629 avatar Apr 08 '24 01:04 better629