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  # 正确

相关推荐
Feibo20117 分钟前
管理agent
python
牛奔14 分钟前
Linux 的日志分析命令
linux·运维·服务器·python·excel
电化学仪器白超15 分钟前
20251209Ver8(精密电流源温漂特性测试报告)
python·单片机·嵌入式硬件·自动化
昵称已被吞噬~‘(*@﹏@*)’~17 分钟前
【强化学习】MacOS (M1芯片)上最新版本 MuJoCo 通用安装教程(最简洁),PS:不是 mujoco_py 的老版本
python·macos·机器学习·强化学习·mujoco
沃斯堡&蓝鸟22 分钟前
DAY33 类的装饰器
开发语言·python
Tipriest_23 分钟前
Python构建包,打包.whl文件,使用.whl文件安装包指南
python·whl
BoBoZz1930 分钟前
ColorEdges 动态有向图的动态渲染
python·vtk·图形渲染·图形处理
彼岸花开了吗1 小时前
构建AI智能体:六十九、Bootstrap采样在大模型评估中的应用:从置信区间到模型稳定性
人工智能·python·llm
echo的PHP开发1 小时前
如何获取苹果手机的 XcodeOrgId
python·智能手机·苹果手机
程序员杰哥1 小时前
Postman设置接口关联,实现参数化
自动化测试·软件测试·python·测试工具·测试用例·接口测试·postman