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 @@ -638,7 +638,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`. When a session is created with `topK` or `temperature`, its `samplingMode` attribute will be `null`.
Furthermore, in contexts where raw parameters are supported (e.g. Web Extensions), if both `samplingMode` and a raw parameter (`topK` or `temperature`) are provided, `samplingMode` takes precedence and the raw parameters are ignored. When a session is created with `topK` or `temperature` (and without `samplingMode`), 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.

Expand Down
18 changes: 8 additions & 10 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ typedef (DOMString or sequence<LanguageModelMessageContent>) LanguageModelPrompt
interface LanguageModel : EventTarget {
static Promise<LanguageModel> create(optional LanguageModelCreateOptions options = {});
static Promise<Availability> availability(optional LanguageModelCreateCoreOptions options = {});
// **EXPERIMENTAL**: Only available in extension and experimental contexts.
// **DEPRECATED**: This method will be removed; use samplingMode instead. Only available in extension contexts.
static Promise<LanguageModelParams?> params();

// These will throw a TypeError if role = "system"
Expand Down Expand Up @@ -86,9 +86,9 @@ interface LanguageModel : EventTarget {
// **DEPRECATED**: This attribute is only available in extension contexts.
attribute EventHandler onquotaoverflow;

// **DEPRECATED**: This attribute is only available in extension contexts.
// **DEPRECATED**: This attribute will be removed; use samplingMode instead. Only available in extension contexts.
readonly attribute unsigned long topK;
// **DEPRECATED**: This attribute is only available in extension contexts.
// **DEPRECATED**: This attribute will be removed; use samplingMode instead. Only available in extension contexts.
readonly attribute float temperature;

// **EXPERIMENTAL**: Only available in experimental contexts.
Expand All @@ -98,7 +98,7 @@ interface LanguageModel : EventTarget {
};
LanguageModel includes DestroyableModel;

// **DEPRECATED**: Only available in extension contexts.
// **DEPRECATED**: This interface will be removed; use samplingMode instead. Only available in extension contexts.
[Exposed=Window, SecureContext]
interface LanguageModelParams {
readonly attribute unsigned long defaultTopK;
Expand All @@ -121,9 +121,9 @@ dictionary LanguageModelToolDeclaration {
dictionary LanguageModelCreateCoreOptions {
// Note: these two have custom out-of-range handling behavior, not in the IDL layer.
// They are unrestricted double so as to allow +Infinity without failing.
// **DEPRECATED**: Only available in extension contexts.
// **DEPRECATED**: This option will be removed; use samplingMode instead. Only available in extension contexts.
unrestricted double topK;
// **DEPRECATED**: Only available in extension contexts.
// **DEPRECATED**: This option will be removed; use samplingMode instead. Only available in extension contexts.
unrestricted double temperature;

// **EXPERIMENTAL**: Only available in experimental contexts.
Expand Down Expand Up @@ -268,8 +268,6 @@ typedef (LanguageModelToolSuccess or LanguageModelToolError) LanguageModelToolRe
<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 @@ -378,10 +376,10 @@ typedef (LanguageModelToolSuccess or LanguageModelToolError) LanguageModelToolRe
:: |initialMessages|

: [=LanguageModel/top K=]
:: |options|["{{LanguageModelCreateCoreOptions/topK}}"] if it [=map/exists=]; otherwise an [=implementation-defined=] value
:: |options|["{{LanguageModelCreateCoreOptions/topK}}"] if it [=map/exists=] and |options|["{{LanguageModelCreateCoreOptions/samplingMode}}"] does not [=map/exist=]; otherwise an [=implementation-defined=] value

: [=LanguageModel/temperature=]
:: |options|["{{LanguageModelCreateCoreOptions/temperature}}"] if it [=map/exists=]; otherwise an [=implementation-defined=] value
:: |options|["{{LanguageModelCreateCoreOptions/temperature}}"] if it [=map/exists=] and |options|["{{LanguageModelCreateCoreOptions/samplingMode}}"] does not [=map/exist=]; 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}}"
Expand Down
Loading