Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ The resolved `samplingMode` used to create the session is exposed as a read-only

To avoid breaking existing pages, standard web page contexts can still pass `topK` and `temperature` in the options object without throwing an error (a deprecation warning will be logged in the console), but they are ignored at runtime and the corresponding properties on the session object will be `undefined` (or fallback to default values).

Furthermore, in contexts where raw parameters are supported (e.g. Web Extensions), passing both `samplingMode` and a raw parameter (`topK` or `temperature`) will reject the `create()` promise with a `TypeError`.
Furthermore, in contexts where raw parameters are supported (e.g. Web Extensions), passing both `samplingMode` and a raw parameter (`topK` or `temperature`) will reject the `create()` promise with a `TypeError`. When a session is created with `topK` or `temperature`, its `samplingMode` attribute will be `null`.
Comment thread
michaelwasserman marked this conversation as resolved.

The `LanguageModel.params()` API, only available in extensions, can be used to query the default and maximum values for these parameters.

Expand Down
16 changes: 13 additions & 3 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ interface LanguageModel : EventTarget {
readonly attribute float temperature;

// **EXPERIMENTAL**: Only available in experimental contexts.
readonly attribute LanguageModelSamplingMode samplingMode;
readonly attribute LanguageModelSamplingMode? samplingMode;

Promise<LanguageModel> clone(optional LanguageModelCloneOptions options = {});
};
Expand Down Expand Up @@ -209,6 +209,8 @@ typedef (
<div algorithm>
To <dfn>validate and canonicalize language model options</dfn> given a {{LanguageModelCreateCoreOptions}} |options|, perform the following steps. They mutate |options| in place to canonicalize and deduplicate language tags, and throw an exception if any are invalid.

1. If |options|["{{LanguageModelCreateCoreOptions/samplingMode}}"] [=map/exists=] and either |options|["{{LanguageModelCreateCoreOptions/topK}}"] [=map/exists=] or |options|["{{LanguageModelCreateCoreOptions/temperature}}"] [=map/exists=], then throw a {{TypeError}}.

1. If |options|["{{LanguageModelCreateCoreOptions/expectedInputs}}"] [=map/exists=], then [=list/for each=] |expected| of |options|["{{LanguageModelCreateCoreOptions/expectedInputs}}"]:
1. If |expected|["{{LanguageModelExpected/languages}}"] [=map/exists=], then [=Validate and canonicalize language tags=] given |expected| and "{{LanguageModelExpected/languages}}".

Expand Down Expand Up @@ -298,6 +300,9 @@ typedef (
: [=LanguageModel/temperature=]
:: |options|["{{LanguageModelCreateCoreOptions/temperature}}"] if it [=map/exists=]; otherwise an [=implementation-defined=] value

: [=LanguageModel/sampling mode=]
:: |options|["{{LanguageModelCreateCoreOptions/samplingMode}}"] if it [=map/exists=]; otherwise null if |options|["{{LanguageModelCreateCoreOptions/topK}}"] [=map/exists=] or |options|["{{LanguageModelCreateCoreOptions/temperature}}"] [=map/exists=]; otherwise "{{LanguageModelSamplingMode/balanced}}"

@michaelwasserman michaelwasserman Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that there may be implementation-specific differences in the performance of different modes (e.g. most-predicable is the fastest) I considered some alternatives here:

  • let the impl decide and just yield the result in the session interface attribute (not predictable for clients)
  • pick most-predictable as the default when unspecified (may not be the fastest in all impls)

Ultimately I think this is probably the right direction (balanced is the default), and we should consider adding a fastest mode that lets the implementation resolve any mode that is likely to yield the best performance.


: [=LanguageModel/expected inputs=]
:: |options|["{{LanguageModelCreateCoreOptions/expectedInputs}}"] if it [=map/exists=]; otherwise an empty [=list=]

Expand Down Expand Up @@ -393,6 +398,8 @@ Every {{LanguageModel}} has a <dfn for="LanguageModel">top K</dfn>, an unsigned

Every {{LanguageModel}} has a <dfn for="LanguageModel">temperature</dfn>, a float, set during creation.

Every {{LanguageModel}} has a <dfn for="LanguageModel">sampling mode</dfn>, a {{LanguageModelSamplingMode}} or null, set during creation.

Every {{LanguageModel}} has an <dfn for="LanguageModel">expected inputs</dfn>, a [=list=] of {{LanguageModelExpected}}s, set during creation.

Every {{LanguageModel}} has an <dfn for="LanguageModel">expected outputs</dfn>, a [=list=] of {{LanguageModelExpected}}s, set during creation.
Expand All @@ -417,6 +424,8 @@ The <dfn attribute for="LanguageModel">topK</dfn> getter steps are to return [=t

The <dfn attribute for="LanguageModel">temperature</dfn> getter steps are to return [=this=]'s [=LanguageModel/temperature=].

The <dfn attribute for="LanguageModel">samplingMode</dfn> getter steps are to return [=this=]'s [=LanguageModel/sampling mode=].

<hr>

The following are the [=event handlers=] (and their corresponding [=event handler event types=]) that must be supported, as [=event handler IDL attributes=], by all {{LanguageModel}} objects:
Expand Down Expand Up @@ -555,7 +564,7 @@ The following are the [=event handlers=] (and their corresponding [=event handle

1. In an [=implementation-defined=] manner, update the underlying model's internal state to include |messages|.

The process should use |model|'s [=LanguageModel/initial messages=], |model|'s [=LanguageModel/top K=], |model|'s [=LanguageModel/temperature=], |model|'s [=LanguageModel/expected inputs=], |model|'s [=LanguageModel/expected outputs=], and |model|'s [=LanguageModel/tools=] to guide how the state is updated.
The process should use |model|'s [=LanguageModel/initial messages=], |model|'s [=LanguageModel/sampling mode=], |model|'s [=LanguageModel/top K=], |model|'s [=LanguageModel/temperature=], |model|'s [=LanguageModel/expected inputs=], |model|'s [=LanguageModel/expected outputs=], and |model|'s [=LanguageModel/tools=] to guide how the state is updated.

The process must conform to the guidance given in [[#privacy]] and [[#security]].

Expand Down Expand Up @@ -587,7 +596,7 @@ The following are the [=event handlers=] (and their corresponding [=event handle

1. In an [=implementation-defined=] manner, subject to the following guidelines, begin the process of producing a response from the language model based on its current internal state.

The process should use |model|'s [=LanguageModel/initial messages=], |model|'s [=LanguageModel/top K=], |model|'s [=LanguageModel/temperature=], |model|'s [=LanguageModel/expected inputs=], |model|'s [=LanguageModel/expected outputs=], |model|'s [=LanguageModel/tools=], and |responseConstraint| to guide the model's behavior.
The process should use |model|'s [=LanguageModel/initial messages=], |model|'s [=LanguageModel/sampling mode=], |model|'s [=LanguageModel/top K=], |model|'s [=LanguageModel/temperature=], |model|'s [=LanguageModel/expected inputs=], |model|'s [=LanguageModel/expected outputs=], |model|'s [=LanguageModel/tools=], and |responseConstraint| to guide the model's behavior.

The prompting process must conform to the guidance given in [[#privacy]] and [[#security]].

Expand Down Expand Up @@ -861,6 +870,7 @@ When prompting fails, the following possible reasons may be surfaced to the web
- [=LanguageModel/initial messages=] set to |model|'s [=LanguageModel/initial messages=].
- [=LanguageModel/top K=] set to |model|'s [=LanguageModel/top K=].
- [=LanguageModel/temperature=] set to |model|'s [=LanguageModel/temperature=].
- [=LanguageModel/sampling mode=] set to |model|'s [=LanguageModel/sampling mode=].
- [=LanguageModel/expected inputs=] set to |model|'s [=LanguageModel/expected inputs=].
- [=LanguageModel/expected outputs=] set to |model|'s [=LanguageModel/expected outputs=].
- [=LanguageModel/tools=] set to |model|'s [=LanguageModel/tools=].
Expand Down
Loading