// Only available when using the Prompt API for Chrome Extensions. await LanguageModel.params(); // {defaultTopK: 3, maxTopK: 128, defaultTemperature: 1, maxTemperature: 2}
// Only available when using the Prompt API for Chrome Extensions. await LanguageModel.params(); // {defaultTopK: 3, maxTopK: 128, defaultTemperature: 1, maxTemperature: 2}
セッションを作成する
Prompt API を実行できるようになったら、create() 関数を使用してセッションを作成します。
create()
const session = await LanguageModel.create();
const session = await LanguageModel.create();
Chrome 拡張機能の Prompt API を使用する場合、各セッションはオプションの options オブジェクトを使用して topK と temperature でカスタマイズできます。これらのパラメータのデフォルト値は、LanguageModel.params() から返されます。
topK
temperature
LanguageModel.params()
// Only available when using the Prompt API for Chrome Extensions. const params = await LanguageModel.params(); // Initializing a new session must either specify both topK and // temperature or neither of them. // Only available when using the Prompt API for Chrome Extensions. const slightlyHighTemperatureSession = await LanguageModel.create({ temperature: Math.max(params.defaultTemperature * 1.2, 2.0), topK: params.defaultTopK, });
// Only available when using the Prompt API for Chrome Extensions. const params = await LanguageModel.params(); // Initializing a new session must either specify both topK and // temperature or neither of them. // Only available when using the Prompt API for Chrome Extensions. const slightlyHighTemperatureSession = await LanguageModel.create({ temperature: Math.max(params.defaultTemperature * 1.2, 2.0), topK: params.defaultTopK, });
create() 関数のオプションの options オブジェクトは signal フィールドも受け取ります。これにより、AbortSignal を渡してセッションを破棄できます。
const session = await LanguageModel.create({ initialPrompts: [ { role: 'system', content: 'You are a helpful and friendly assistant.' }, { role: 'user', content: 'What is the capital of Italy?' }, { role: 'assistant', content: 'The capital of Italy is Rome.' }, { role: 'user', content: 'What language is spoken there?' }, { role: 'assistant', content: 'The official language of Italy is Italian. [...]', }, ], });
const session = await LanguageModel.create({ initialPrompts: [ { role: 'system', content: 'You are a helpful and friendly assistant.' }, { role: 'user', content: 'What is the capital of Italy?' }, { role: 'assistant', content: 'The capital of Italy is Rome.' }, { role: 'user', content: 'What language is spoken there?' }, { role: 'assistant', content: 'The official language of Italy is Italian. [...]', }, ], });
const session = await LanguageModel.create(); const schema = { "type": "boolean" }; const post = "Mugs and ramen bowls, both a bit smaller than intended, but that happens with reclaim. Glaze crawled the first time around, but pretty happy with it after refiring."; const result = await session.prompt( Is this post about pottery?\n\n${post}, { responseConstraint: schema, } ); console.log(JSON.parse(result)); // true
const session = await LanguageModel.create(); const schema = { "type": "boolean" }; const post = "Mugs and ramen bowls, both a bit smaller than intended, but that happens with reclaim. Glaze crawled the first time around, but pretty happy with it after refiring."; const result = await session.prompt( Is this post about pottery?\n\n${post}, { responseConstraint: schema, } ); console.log(JSON.parse(result)); // true
const result = await session.prompt( Summarize this feedback into a rating between 0-5. Only output a JSON object { rating }, with a single property whose value is a number: The food was delicious, service was excellent, will recommend. , { responseConstraint: schema, omitResponseConstraintInput: true });
const result = await session.prompt( Summarize this feedback into a rating between 0-5. Only output a JSON object { rating }, with a single property whose value is a number: The food was delicious, service was excellent, will recommend. , { responseConstraint: schema, omitResponseConstraintInput: true });
// Start by checking if it's possible to create a session based on the // availability of the model, and the characteristics of the device. const available = await LanguageModel.availability({ expectedInputs: [{type: 'text', languages: ['en']}], expectedOutputs: [{type: 'text', languages: ['en']}], }); if (available !== 'unavailable') { const session = await LanguageModel.create(); // Prompt the model and wait for the whole result to come back. const result = await session.prompt('Write me a poem!'); console.log(result); }
// Start by checking if it's possible to create a session based on the // availability of the model, and the characteristics of the device. const available = await LanguageModel.availability({ expectedInputs: [{type: 'text', languages: ['en']}], expectedOutputs: [{type: 'text', languages: ['en']}], }); if (available !== 'unavailable') { const session = await LanguageModel.create(); // Prompt the model and wait for the whole result to come back. const result = await session.prompt('Write me a poem!'); console.log(result); }
// Only available when using the Prompt API for Chrome Extensions. await LanguageModel.params(); // {defaultTopK: 3, maxTopK: 128, defaultTemperature: 1, maxTemperature: 2}
// Only available when using the Prompt API for Chrome Extensions. await LanguageModel.params(); // {defaultTopK: 3, maxTopK: 128, defaultTemperature: 1, maxTemperature: 2}
セッションを作成する
Prompt API を実行できるようになったら、create() 関数を使用してセッションを作成します。
create()
const session = await LanguageModel.create();
const session = await LanguageModel.create();
Chrome 拡張機能の Prompt API を使用する場合、各セッションはオプションの options オブジェクトを使用して topK と temperature でカスタマイズできます。これらのパラメータのデフォルト値は、LanguageModel.params() から返されます。
topK
temperature
LanguageModel.params()
// Only available when using the Prompt API for Chrome Extensions. const params = await LanguageModel.params(); // Initializing a new session must either specify both topK and // temperature or neither of them. // Only available when using the Prompt API for Chrome Extensions. const slightlyHighTemperatureSession = await LanguageModel.create({ temperature: Math.max(params.defaultTemperature * 1.2, 2.0), topK: params.defaultTopK, });
// Only available when using the Prompt API for Chrome Extensions. const params = await LanguageModel.params(); // Initializing a new session must either specify both topK and // temperature or neither of them. // Only available when using the Prompt API for Chrome Extensions. const slightlyHighTemperatureSession = await LanguageModel.create({ temperature: Math.max(params.defaultTemperature * 1.2, 2.0), topK: params.defaultTopK, });
create() 関数のオプションの options オブジェクトは signal フィールドも受け取ります。これにより、AbortSignal を渡してセッションを破棄できます。
const session = await LanguageModel.create({ initialPrompts: [ { role: 'system', content: 'You are a helpful and friendly assistant.' }, { role: 'user', content: 'What is the capital of Italy?' }, { role: 'assistant', content: 'The capital of Italy is Rome.' }, { role: 'user', content: 'What language is spoken there?' }, { role: 'assistant', content: 'The official language of Italy is Italian. [...]', }, ], });
const session = await LanguageModel.create({ initialPrompts: [ { role: 'system', content: 'You are a helpful and friendly assistant.' }, { role: 'user', content: 'What is the capital of Italy?' }, { role: 'assistant', content: 'The capital of Italy is Rome.' }, { role: 'user', content: 'What language is spoken there?' }, { role: 'assistant', content: 'The official language of Italy is Italian. [...]', }, ], });
const session = await LanguageModel.create(); const schema = { "type": "boolean" }; const post = "Mugs and ramen bowls, both a bit smaller than intended, but that happens with reclaim. Glaze crawled the first time around, but pretty happy with it after refiring."; const result = await session.prompt( Is this post about pottery?\n\n${post}, { responseConstraint: schema, } ); console.log(JSON.parse(result)); // true
const session = await LanguageModel.create(); const schema = { "type": "boolean" }; const post = "Mugs and ramen bowls, both a bit smaller than intended, but that happens with reclaim. Glaze crawled the first time around, but pretty happy with it after refiring."; const result = await session.prompt( Is this post about pottery?\n\n${post}, { responseConstraint: schema, } ); console.log(JSON.parse(result)); // true
const result = await session.prompt( Summarize this feedback into a rating between 0-5. Only output a JSON object { rating }, with a single property whose value is a number: The food was delicious, service was excellent, will recommend. , { responseConstraint: schema, omitResponseConstraintInput: true });
const result = await session.prompt( Summarize this feedback into a rating between 0-5. Only output a JSON object { rating }, with a single property whose value is a number: The food was delicious, service was excellent, will recommend. , { responseConstraint: schema, omitResponseConstraintInput: true });
// Start by checking if it's possible to create a session based on the // availability of the model, and the characteristics of the device. const available = await LanguageModel.availability({ expectedInputs: [{type: 'text', languages: ['en']}], expectedOutputs: [{type: 'text', languages: ['en']}], }); if (available !== 'unavailable') { const session = await LanguageModel.create(); // Prompt the model and wait for the whole result to come back. const result = await session.prompt('Write me a poem!'); console.log(result); }
// Start by checking if it's possible to create a session based on the // availability of the model, and the characteristics of the device. const available = await LanguageModel.availability({ expectedInputs: [{type: 'text', languages: ['en']}], expectedOutputs: [{type: 'text', languages: ['en']}], }); if (available !== 'unavailable') { const session = await LanguageModel.create(); // Prompt the model and wait for the whole result to come back. const result = await session.prompt('Write me a poem!'); console.log(result); }