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

相关推荐
李可以量化3 分钟前
QMT 量化实践:两种方式获取个股上市日期(内置 Python + 原生 Python 完整可运行代码)
python
是多巴胺不是尼古丁12 分钟前
期末java复习--string
java·开发语言·python
garmin Chen28 分钟前
从 Transformer 到 Agent:大模型技术全景解析
java·人工智能·python·深度学习·transformer
没有钱的钱仔34 分钟前
pytorch_cuda安装
人工智能·pytorch·python
Full Stack Developme40 分钟前
Apache Tika 教程
java·开发语言·python·apache
笨笨没好名字1 小时前
Leetcode刷题python版第一周
python·算法·leetcode
Cthy_hy1 小时前
斯特林数:组合划分的递归经典,一二两类全解
python·算法·斯特林数
青春:一叶知秋1 小时前
【Python】python基本语法和使用
开发语言·python
SilentSamsara1 小时前
向量数据库实战:Chroma/Milvus/Qdrant 选型与语义搜索应用
开发语言·数据库·人工智能·python·青少年编程·milvus
沪漂阿龙2 小时前
Embedding:文本怎么变成向量?语义检索为什么能工作?
人工智能·python·embedding