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

@@ -318,7 +318,8 @@ for chunk in openai.ChatCompletion.create(
messages=[
{"role": "user", "content": "你好"}
],
stream=True
stream=True
# Specifying stop words in streaming output format is not yet supported and is under development.
):
if hasattr(chunk.choices[0].delta, "content"):
print(chunk.choices[0].delta.content, end="", flush=True)
@@ -329,7 +330,8 @@ response = openai.ChatCompletion.create(
messages=[
{"role": "user", "content": "你好"}
],
stream=False
stream=False,
stop=[] # You can add custom stop words here, e.g., stop=["Observation:"] for ReAct prompting.
)
print(response.choices[0].message.content)
```