Skip to content

Commit 0a79d68

Browse files
committed
Specify adjacent text-collapsing behavior
Also note that we are protected from prefix appearing on messages containing image or audio content.
1 parent 9df9109 commit 0a79d68

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

index.bs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ typedef (
190190

191191
1. If |message|["{{LanguageModelMessage/role}}"] is not "{{LanguageModelMessageRole/assistant}}", then throw a "{{SyntaxError}}" {{DOMException}}.
192192

193+
<p class="note">Per the below validation steps, this will also guarantee that |message|["{{LanguageModelMessage/content}}"] only contains text content.
194+
193195
1. If |message| is not the last item in |messages|, then throw a "{{SyntaxError}}" {{DOMException}}.
194196

195197
1. [=list/For each=] |content| of |message|["{{LanguageModelMessage/content}}"]:
@@ -218,6 +220,32 @@ typedef (
218220

219221
1. If |content|["{{LanguageModelMessageContent/value}}"] is not an {{AudioBuffer}}, {{BufferSource}}, or {{Blob}}, then throw a {{TypeError}}.
220222

223+
1. Let |contentWithContiguousTextCollapsed| be an empty [=list=] of {{LanguageModelMessageContent}}s.
224+
225+
1. Let |lastTextContent| be null.
226+
227+
1. [=list/For each=] |content| of |message|["{{LanguageModelMessage/content}}"]:
228+
229+
1. If |content|["{{LanguageModelMessageContent/type}}"] is "{{LanguageModelMessageType/text}}":
230+
231+
1. If |lastTextContent| is null:
232+
233+
1. [=list/Append=] |content| to |contentWithContiguousTextCollapsed|.
234+
235+
1. Set |lastTextContent| to |content|.
236+
237+
1. Otherwise, set |lastTextContent|["{{LanguageModelMessageContent/value}}"] to the concatenation of |lastTextContent|["{{LanguageModelMessageContent/value}}"] and |content|["{{LanguageModelMessageContent/value}}"].
238+
239+
<p class="note">No space or other character is added. Thus, « «[ "{{LanguageModelMessageContent/type}}" → "{{LanguageModelMessageType/text}}", "`foo`" ]», «[ "{{LanguageModelMessageContent/type}}" → "{{LanguageModelMessageType/text}}", "`bar`" ]» » is canonicalized to « «[ "{{LanguageModelMessageContent/type}}" → "{{LanguageModelMessageType/text}}", "`foobar`" ]».</p>
240+
241+
1. Otherwise:
242+
243+
1. [=list/Append=] |content| to |contentWithContiguousTextCollapsed|.
244+
245+
1. Set |lastTextContent| to null.
246+
247+
1. Set |message|["{{LanguageModelMessage/content}}"] to |contentWithContiguousTextCollapsed|.
248+
221249
1. [=list/Append=] |message| to |messages|.
222250

223251
1. If |messages| [=list/is empty=], then throw a "{{SyntaxError}}" {{DOMException}}.

0 commit comments

Comments
 (0)