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. diff --git a/index.bs b/index.bs index 00abf4d..6f863a3 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 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=] @@ -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=].