modelscope-agent icon indicating copy to clipboard operation
modelscope-agent copied to clipboard

[callback,agent] enable_no_stream_callback 永远不会触发,因为RolePlay返回的response永远是生成器

Open Yimi81 opened this issue 1 year ago • 1 comments

Initial Checks

  • [X] I have searched GitHub for a duplicate issue and I'm sure this is something new
  • [X] I have read and followed the docs & demos and still think this is a bug
  • [X] I am confident that the issue is with modelscope-agent (not my code, or another library in the ecosystem)

What happened + What you expected to happen

image 如图所示,尽管我设置RolePlay非stream, 但是当触发run方法,执行的回调还是enable_stream_callback,RolePlay不论是stream还是non-stream 返回的永远是generator, 因为_run方法中使用了yield语句,无论是否启用流模式,只要函数体内包含 yield 语句,Python 就会将这个函数视为一个生成器。正确方法应该分开处理stream与non-stream,将像BaseChatModel的chat方法,其enable_llm_callback是正确的。

Versions / Dependencies

最新版

Reproduction script

如上

Issue Severity

None

Yimi81 avatar Aug 31 '24 03:08 Yimi81

  • 是否应该仿照BaseChatModel的chat方法,在Agent基类将run方法分为_run_stream,_run_no_stream. 这样所有agent似乎都要改动
  • 还是仅仅在roleplay这个agent下区分
  • 亦或者有什么更优雅的方法解决这个问题

Yimi81 avatar Aug 31 '24 03:08 Yimi81