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

qianfan.ChatCompletion支持close操作吗? #293

Open
flyingjohn opened this issue Feb 26, 2024 · 2 comments
Open

qianfan.ChatCompletion支持close操作吗? #293

flyingjohn opened this issue Feb 26, 2024 · 2 comments

Comments

@flyingjohn
Copy link

Issue you'd like to raise.

resp = qianfan.ChatCompletion.do(stream=True)操作支持提前终止流式对话吗?

Suggestion:

No response

@danielhjz
Copy link
Collaborator

Issue you'd like to raise.

resp = qianfan.ChatCompletion.do(stream=True)操作支持提前终止流式对话吗?

Suggestion:

No response

您好,谢谢反馈,请问是指支持停止字符串吗:

from qianfan import Completion

c = Completion("ERNIE-Bot")
for r in c.do(prompt="hi", stream=True, stop=["hi","好"]):
    print(r["body"])

output:

{'id': 'as-yp1jc8nevt', 'object': 'completion', 'created': 1709020272, 'sentence_id': 0, 'is_end': True, 'is_truncated': False, 'result': '', 'need_clear_history': False, 'finish_reason': 'stop', 'usage': {'prompt_tokens': 1, 'completion_tokens': 1, 'total_tokens': 2}}

@danielhjz danielhjz reopened this Feb 27, 2024
@hellohejinyu
Copy link

image

@danielhjz 应该是指像 OpenAI 这种,可以提前 abort。这样会更省钱一点,毕竟如果前台用户不满意当前结果可以立即终止模型继续生成 token。

image

我在使用 http 请求的形式对接千帆时,用了 AbortController 来终止(当然我不知道百度后台是否真的停止生成token了)。今天切换到 @baidu/qianfan,不知道有没有什么好的办法提前终止呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants