Skip to content
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

流式支持 #14

Closed
yuanjie-ai opened this issue Sep 7, 2023 · 5 comments · Fixed by #15
Closed

流式支持 #14

yuanjie-ai opened this issue Sep 7, 2023 · 5 comments · Fixed by #15
Assignees
Labels
bug Something isn't working

Comments

@yuanjie-ai
Copy link

https://github.com/yuanjie-ai/ChatLLM/blob/master/LLMS.md#%E7%99%BE%E5%BA%A6%E6%96%87%E5%BF%83

@Bobholamovic
Copy link
Member

请问可以更详细地描述你的需求/问题吗?

从标题来看,ERNIE-Bot-SDK目前支持流式接口(处理server-sent events),只需要在调用erniebot.ChatCompletion时指定stream=True即可。详情请参考API文档

@yuanjie-ai
Copy link
Author

yuanjie-ai commented Sep 7, 2023 via email

@Bobholamovic
Copy link
Member

参考文档中的描述,我写了一个例子,在自己的环境里测试是可用的。设置好鉴权参数之后执行:

python -c "import operator; import erniebot; response = erniebot.ChatCompletion.create(model='ernie-bot-turbo', messages=[{'role': 'user', 'content': '深圳周末上哪玩?'}], stream=True); print(''.join(map(operator.attrgetter('result'), response)))"

会打印类似如下结果:

深圳周末有很多好玩的地方,以下是一些推荐:

1. 海上世界:海上世界是一个集娱乐、餐饮、购物于一体的综合性娱乐场所,位于深圳市南山区蛇口海景广场。这里有着豪华游轮、酒吧、餐厅、水族馆、海洋公园等众多娱乐设施,是深圳周末休闲的好去处。
2. 华侨城:华侨城是一个集旅游、文化、娱乐等多种功能于一体的综合性主题公园,包括欢乐谷、世界之窗、锦绣中华民俗文化村等多个主题公园。这里适合家庭出游,可以体验各种不同的文化氛围和娱乐活动。
3. 深圳湾公园:深圳湾公园是一个以自然风光为主的城市公园,位于深圳市南山区深圳湾畔。这里有着广阔的草坪、湖泊、河流等自然景观,还有各种户外运动设施和休闲场所,是深圳周末休闲的好去处。
4. 世界之窗:世界之窗是一个以世界著名景点为主题的旅游景区,位于深圳市南山区深南大道。这里有着100多个世界著名景点的微缩模型,包括埃菲尔铁塔、比萨斜塔等,是拍照留念的好地方。
5. 华强北电子科技广场:华强北电子科技广场是一个以电子产品为主的购物广场,位于深圳市福田区。这里有着各种各样的电子产品,包括手机、电脑、相机等,是科技爱好者的天堂。

以上是一些深圳周末休闲的好去处,希望能对你有所帮助。

看起来是符合预期的。

我不太明白你给出的链接和本issue的关联。链接的页面看起来是一个大模型相关的开源Python库的文档,包含了一些API使用示例,但其中并没有明确提到和“流式调用”相关的内容。如果你想要提出的问题和链接页面的内容有关,请做出进一步解释~

@yuanjie-ai
Copy link
Author

yuanjie-ai commented Sep 7, 2023 via email

@Bobholamovic
Copy link
Member

我注意到在流式接口的实现中确实存在一个bug,导致流式接口事实上以非流式的方式工作(效率甚至低于非流式接口)。我在上面提到的PR中修复了这个问题。

感谢反馈bug~

@Bobholamovic Bobholamovic self-assigned this Sep 7, 2023
@Bobholamovic Bobholamovic added the bug Something isn't working label Sep 7, 2023
qingzhong1 pushed a commit to qingzhong1/ERNIE-Bot-SDK that referenced this issue Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants