BUG: gradio RuntimeError: async generator raised StopAsyncIteration

BUG: gradio RuntimeError: async generator raised StopAsyncIteration

环境

python 复制代码
gradio                        4.20.0

详情

在使用gradio编写大模型可视化demo的时候,大模型正常输出,但gradio弹出此错误。

经过排除,发现是返回方式的问题,gradio传输信息给web网页的时候,我使用了return,但实际上应该 使用yield

解决方法

return改为yield

例子

python 复制代码
# 旧
def generate(message: str) -> Iterator[str]:
    stream = False
    response = "你好"
    if stream:
        for _ in range(5):
		        response += response
            yield response
    else:
        return response  # 错误

# 新
def generate(message: str) -> Iterator[str]:
    stream = False
    response = "你好"
    if stream:
        for _ in range(5):
		        response += response
            yield response
    else:
        yield response  # 正确

相关推荐
李永奉1 小时前
杰理可视化SDK开发-【BUG】配置“TWS两边同时按消息使能”功能后,按键单击功能无效失灵
开发语言·单片机·嵌入式硬件·物联网·bug
m0_617493941 小时前
Python OpenCV 透视变换(Perspective Transform)详解与实战
开发语言·python·opencv
小李不困还能学1 小时前
PyCharm下载安装与配置教程
ide·python·pycharm
博观而约取厚积而薄发1 小时前
Pytest 从入门到精通,一篇就够(超详细实战教程)
python·测试工具·单元测试·自动化·pytest
imzed2 小时前
使用 Playwright + Pytest 构建 Web UI 自动化测试框架
python·自动化·pytest
普通网友2 小时前
pytest一些常见的插件
开发语言·python·pytest
时空系2 小时前
Python 高性能高压缩打包器 —— 基于 JianPy 语义分析引擎
python
cndes2 小时前
给Miniconda换源,让包下载更迅速
开发语言·python
Metaphor6923 小时前
使用 Python 添加、隐藏和删除 PDF 图层
python·pdf·图层