vercel / ai

Build AI-powered applications with React, Svelte, Vue, and Solid
https://sdk.vercel.ai/docs
Other
10.07k stars 1.5k forks source link

Append stop sequence to the end of the generate text result #3459

Open williamlmao opened 1 week ago

williamlmao commented 1 week ago

Feature Description

Biggest use case we've had for stop sequences is to prevent the model from generating more text after finishing some structured data, like XML.

It would be nice to have an option appendStopSequence to add it back on in the .text result, as that field is currently read-only.

Use Case

Sometimes the model will do something like

<root>
... content
</root>

I've generated this XML for you!

stopSequences: ['</root'>] is a good example. We know the model will always output this. We can't reliably predict what it will say after the XML, so is the best option.

However, it means the output we get always looks like this:

<root>
... content

For now, we just append the text back on, but it would be really nice to have this built in!

Additional context

No response

lgrammel commented 1 week ago

You can have multiple stop sequences. How do you know which one to pick?