From 5c52ec7fcea129925d49be0ded737b556454e749 Mon Sep 17 00:00:00 2001 From: Isaac Ahouma Date: Tue, 22 Sep 2026 11:22:39 -0700 Subject: [PATCH 1/3] Specify samplingMode algorithms and slot in index.bs Follow-up to #206, #210, and #215. Those PRs updated the explainer and added the LanguageModelSamplingMode WebIDL declarations, but left out the algorithm steps in index.bs. - Make LanguageModel.samplingMode nullable (LanguageModelSamplingMode?) in the IDL to match LanguageModelCreateCoreOptions.samplingMode and Chromium's behavior when samplingMode is omitted. - Throw TypeError in validate and canonicalize language model options when both samplingMode and topK/temperature are provided. - Wire sampling mode into LanguageModel's internal slots, getter, creation, prefill, generate, and clone steps alongside top K and temperature. Bug: 561753033 --- README.md | 2 +- index.bs | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 84c088a..f944ede 100644 --- a/README.md +++ b/README.md @@ -466,7 +466,7 @@ The allowed values for `samplingMode` are: * `"most-predictable"`: For tasks requiring strict consistency and reproducibility (e.g. testing, code generation, or content extraction). * `"predictable"`: For focused outputs with minimal variation. * `"slightly-predictable"`: For focused outputs with a bit more variation than `"predictable"`. -* `"balanced"` (default): The standard preset for most conversational interactions. +* `"balanced"`: The standard preset for most conversational interactions. * `"slightly-creative"`: For creative outputs that are slightly more focused than `"creative"`. * `"creative"`: For tasks where variety and creativity are preferred over strict reproducibility. * `"most-creative"`: For maximum diversity of output and creative brainstorming. diff --git a/index.bs b/index.bs index 00abf4d..3d30cfb 100644 --- a/index.bs +++ b/index.bs @@ -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 clone(optional LanguageModelCloneOptions options = {}); }; @@ -209,6 +209,8 @@ typedef (
To validate and canonicalize language model options 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}}". @@ -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 + : [=LanguageModel/expected inputs=] :: |options|["{{LanguageModelCreateCoreOptions/expectedInputs}}"] if it [=map/exists=]; otherwise an empty [=list=] @@ -393,6 +398,8 @@ Every {{LanguageModel}} has a top K, an unsigned Every {{LanguageModel}} has a temperature, a float, set during creation. +Every {{LanguageModel}} has a sampling mode, a {{LanguageModelSamplingMode}} or null, set during creation. + Every {{LanguageModel}} has an expected inputs, a [=list=] of {{LanguageModelExpected}}s, set during creation. Every {{LanguageModel}} has an expected outputs, a [=list=] of {{LanguageModelExpected}}s, set during creation. @@ -417,6 +424,8 @@ The topK getter steps are to return [=t The temperature getter steps are to return [=this=]'s [=LanguageModel/temperature=]. +The samplingMode getter steps are to return [=this=]'s [=LanguageModel/sampling mode=]. +
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: @@ -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]]. @@ -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]]. @@ -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=]. From f01981d7922e8cb9beb400a631f6452d1d150f2e Mon Sep 17 00:00:00 2001 From: Isaac Ahouma Date: Tue, 22 Sep 2026 17:05:52 -0700 Subject: [PATCH 2/3] Default samplingMode to balanced unless legacy params are used --- README.md | 2 +- index.bs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f944ede..84c088a 100644 --- a/README.md +++ b/README.md @@ -466,7 +466,7 @@ The allowed values for `samplingMode` are: * `"most-predictable"`: For tasks requiring strict consistency and reproducibility (e.g. testing, code generation, or content extraction). * `"predictable"`: For focused outputs with minimal variation. * `"slightly-predictable"`: For focused outputs with a bit more variation than `"predictable"`. -* `"balanced"`: The standard preset for most conversational interactions. +* `"balanced"` (default): The standard preset for most conversational interactions. * `"slightly-creative"`: For creative outputs that are slightly more focused than `"creative"`. * `"creative"`: For tasks where variety and creativity are preferred over strict reproducibility. * `"most-creative"`: For maximum diversity of output and creative brainstorming. diff --git a/index.bs b/index.bs index 3d30cfb..6f863a3 100644 --- a/index.bs +++ b/index.bs @@ -301,7 +301,7 @@ typedef ( :: |options|["{{LanguageModelCreateCoreOptions/temperature}}"] if it [=map/exists=]; otherwise an [=implementation-defined=] value : [=LanguageModel/sampling mode=] - :: |options|["{{LanguageModelCreateCoreOptions/samplingMode}}"] if it [=map/exists=]; otherwise null + :: |options|["{{LanguageModelCreateCoreOptions/samplingMode}}"] if it [=map/exists=]; otherwise null if |options|["{{LanguageModelCreateCoreOptions/topK}}"] [=map/exists=] or |options|["{{LanguageModelCreateCoreOptions/temperature}}"] [=map/exists=]; otherwise "{{LanguageModelSamplingMode/balanced}}" : [=LanguageModel/expected inputs=] :: |options|["{{LanguageModelCreateCoreOptions/expectedInputs}}"] if it [=map/exists=]; otherwise an empty [=list=] From 2d40636dc0bebd2d08f0eed2d291c058bc9e37d4 Mon Sep 17 00:00:00 2001 From: Isaac Ahouma Date: Wed, 23 Sep 2026 10:01:48 -0700 Subject: [PATCH 3/3] Document null samplingMode when legacy params are used in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 84c088a..4c4bdd7 100644 --- a/README.md +++ b/README.md @@ -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`. The `LanguageModel.params()` API, only available in extensions, can be used to query the default and maximum values for these parameters.