add stop word on openai api ChatCompletion

This commit is contained in:
cyente
2023-08-23 16:30:53 +08:00
parent e494489bf1
commit a3a5b3de47
3 changed files with 28 additions and 9 deletions

View File

@@ -323,6 +323,7 @@ for chunk in openai.ChatCompletion.create(
{"role": "user", "content": "你好"}
],
stream=True
# 流式输出的自定义stopwords功能尚未支持正在开发中
):
if hasattr(chunk.choices[0].delta, "content"):
print(chunk.choices[0].delta.content, end="", flush=True)
@@ -333,7 +334,8 @@ response = openai.ChatCompletion.create(
messages=[
{"role": "user", "content": "你好"}
],
stream=False
stream=False,
stop=[] # 在此处添加自定义的stop words 例如ReAct prompting时需要增加 stop=["Observation:"]。
)
print(response.choices[0].message.content)
```