-
Notifications
You must be signed in to change notification settings - Fork 53
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
[New Feature] 支持 stream agent 流式返回step和message #345
Conversation
Thanks for your contribution! |
求求大佬有空review一下,真的太需要了😭 |
检查一下代码的格式:
|
好嘞,已经使用 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
除了常规修改,还抽象出_first_tool_step
方法用于处理最开始的tool step
代码格式没过: ![]() ERNIE-SDK/erniebot-agent/Makefile Line 12 in 8de8fdb
你可以执行命令:make format-check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make format-check
All done! ✨ 🍰 ✨
检查一下代码规范:
ERNIE-SDK/erniebot-agent/Makefile Line 21 in 8de8fdb
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python -m mypy src
Success: no issues found in 73 source files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感谢贡献!我觉得这是一个不错的实现agent流式输出的想法~
对于代码实现我没有大的疑问,一些小问题留在评论里了。另外想和大家讨论一下,从实用性的角度出发,我们是否有必要为流式输出增加新的callback时点?
This method should yield a sequence of (AgentStep, List[Message]) tuples based on the given | ||
prompt and optionally accompanying files. | ||
""" | ||
if False: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是为什么呀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
特别不好意思,这个是对mypy
的妥协:
这里直接pass
或者raise
都会mypy
编译器报错,原因应该是返回AsyncIterator
时,如果内部没有yield
就认为返回值是Coroutine
,从而导致和子类重载函数返回值类型(FunctionAgent._run_stream
)不同而报错;由于我一直没能找到通过mypy
检测的抽象方法@abc.abstractmethod async def _run_stream
的返回值数据类型,就很丑陋的if False:
了,哭哭
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
噢噢,好吧,那我觉得可以先保留这个(不过或许if False
可以用if typing.TYPE_CHECKING
代替,顺带可以在注释里加个HACK
标记)~
erniebot-agent/tests/integration_tests/agents/test_functional_agent_stream.py
Outdated
Show resolved
Hide resolved
erniebot-agent/tests/integration_tests/agents/test_functional_agent_stream.py
Outdated
Show resolved
Hide resolved
请在提交前检查一下格式:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已经使用python -m black --check
检查格式啦
感谢贡献~ |
使得
FunctionAgent
支持流式调用,返回step
和message
,注意:EndStep
会返回一次;EndStep
会返回多次,每次返回新的短句,和ERNIEBot
的stream=True
效果相同output:
也有类似的issue需求#335