Stop sequences not being matched when using PHP/CURL

Trying to get a PHP/Curl solution to mirror the results from the Playground and all good bar one issue.

If I add a stop sequence of “\n” (one new line) or “\n\n” (two new lines), I get no text back from the call. If I remove the “stop” parameter I either get replication or the start of a new paragraph. I’d like to stop at a new line but no matter what I try I cannot replicate the new line stop sequence from the playground.

Any help would be appreciated.

-H “Content-Type: application/json”
-H “Authorization: Bearer $OPENAI_API_KEY”
-d ‘{
“prompt”: “What are Xylo-oligosaccharides?”,
“temperature”: 0,
“max_tokens”: 100,
“top_p”: 1,
“frequency_penalty”: 0,
“presence_penalty”: 0,
“stop”: ["\n"]

Xylo-oligosaccharides are a prebiotic fiber that is derived from the enzymatic hydrolysis of xylan-rich plant material. Xylo-oligosaccharides are a type of soluble fiber that is fermented by intestinal bacteria.

PHP/CURL result:
Xylo-oligosaccharides are a prebiotic, which means they are a food source for the good bacteria in the gut. They are a source of food for the good bacteria in the gut, which helps to maintain a healthy balance of bacteria in the gut.

What are the benefits of Xylo-oligosaccharides?

Xylo-oligosaccharides are a prebiotic, which means they are

Notice there are new lines but the stop sequence didn’t work?

1 Like

Thanks for the reply.

The two responses are the same, its just that the playground does stop on a new line, while the same response via the API with no stop sequence shows multiple lines and with the stop sequence returns nothing as if there is a newline at the very start of the response.

I see a few people with similar issues but nothing to say how they resolved the issue.

Will keep testing.

1 Like

Hi @martin1 -
Your prompt is

What are Xylo-oligosaccharides?

which doesn’t end with a newline. It’s likely trying to generate a newline ‘\n’ immediately in the curl response and that’s why it wouldn’t be generating anything because it hits the stop sequence immediately.

Are you going to the next line before continuing in playground?

Changing the prompt to

“What are Xylo-oligosaccharides?\n”

may help address the issue. Also, in playground there’s the inject restart/start text parameters which add additional text after each input which you might need to include in your query.


Cheers Matt, problem was indeed no newline at the end of the question