Streaming Stop Sequence
Implement truncate_at_stop(chunks, stop) where chunks are successive string fragments from a model and stop is a nonempty string. Concatenate chunks until the first complete occurrence of stop, then return all text before it. If the delimiter never occurs, return the full concatenation. A delimiter may be split across chunk boundaries. Return a string and do not include the delimiter itself.
Examples
EXAMPLE WALKTHROUGHsplit delimiter
A guided view of the published example, not a trace of your code.
INPUT
[["hello<","/end>","ignored"],"</end>"]TASKtruncate_at_stop()
EXPECTED OUTPUT
"hello"Start with the input values shown in this example.
Example 1 of 2
Input: chunks = ["hello<","/end>","ignored"], stop = "</end>"
Output: "hello"
Explanation: split delimiter
Input: chunks = ["abc","def"], stop = "STOP"
Output: "abcdef"
Explanation: no delimiter
Hint 1
The stop string can cross a chunk boundary.