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

相关推荐
海兰几秒前
【应用】基于 Next.js 16 + Python mplfinance的金融K线图与技术指标可视化平台(一)
javascript·python·金融
大衛說7 分钟前
《Python 从入门到精通》系列总览与学习路线
开发语言·python·学习
小猴子爱上树21 分钟前
跨境电商翻译工具推荐:批量图片翻译、视频字幕翻译、智能抠图一站式搞定
人工智能·python·音视频
丈剑走天涯1 小时前
基于 Python 3 语法的 PyCharm 练习示例,涵盖列表操作、类型判断及数据清洗等核心知识点
windows·python·pycharm
————A1 小时前
Agent 接收用户上传文件
人工智能·笔记·python·状态模式
可乐鸡翅yeah_1 小时前
hls.js 内存泄漏实战排查,直播 M3U8 长时间播放异常定位方案
开发语言·javascript·python·django·ecmascript·m3u8·m3u8在线
可乐鸡翅yeah_1 小时前
第三方接口对接 M3U8 流媒体排坑实战,解决外部服务商流兼容难题
前端·javascript·python·django·html·m3u8·m3u8在线
金融小师妹2 小时前
多因子智能推演:黄金震荡回升,杰克逊霍尔“沃什首秀”政策如何重塑金价路径的AI预测框架
大数据·人工智能·python·线性回归
阿童木写作2 小时前
跨马翻译:AI批量图片翻译与视频字幕翻译工具推荐
人工智能·python·音视频
阿kun要赚马内2 小时前
MCP(Model Context Protocol,模型上下文协议)
人工智能·python