#I'm getting too many responses in my API request

2 messages · Page 1 of 1 (latest)

frozen goblet
#

I'm using this code

import os

openai.api_key = os.environ["OPENAI_API_KEY"]

prompt = input("What question do you want to know?")

response = openai.Completion.create(
    engine="ada",
    prompt=prompt,
    temperature=0.1,
    max_tokens=1024,
    n=1,
    stop=None,
    timeout=5,
)

print(response.choices[0].text.strip())

But it gives way too many answers, for example with the question "How are you?" It'll respond with:


“I’m fine.”

“I’m sorry. I didn’t mean to scare you.”

“I’m not scared.”

“I’m sorry.”

“I’m fine.”

“I’m sorry.”

“I’m fine.”

“I’m fine.”

“I’m fine.”

“I’m fine.”

“I’m fine.”

``` etc etc it keeps going on for a long long time, I'm pretty new so does anybody know what I'm doing wrong?
acoustic prairie
#

The completion is designed to just continue your text. You need to tell the model when to stop. https://platform.openai.com/docs/api-reference/completions/create#completions/create-stop
For example you can tell it to stop when it makes a new line with "/n" as stop. You have just stop to None at the moment.

A better trick you can use is to start every live with who is saying the message. Like in my picture I start with User: and Assistant: and my stop sequence is User: so as soon as the model writes "User:" it will stop.