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
14 changes: 0 additions & 14 deletions ai-session-management/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ const promptInput = document.querySelector('.prompt-input');

const assistants = {};

const DEFAULT_PARMS = {
defaultTopK: 3,
defaultTemperature: 1.0,
};

let controller = null;

stopButton.addEventListener('click', () => {
Expand All @@ -45,13 +40,6 @@ async function createLanguageModel(options) {
}

(async function init() {
// Get the default parameters.
// The new API shape, currently behind a flag in Canary has a `params()` method that returs
// the default and maximing topK and temperature. A hardcoded value, DEFAULT_PARAMS is used
// for the previous API shape.
const { defaultTopK: topK, defaultTemperature: temperature } = "LanguageModel" in self ?
await LanguageModel.params() : DEFAULT_PARMS;

const uuids = getUUIDs();

if (uuids.length) {
Expand All @@ -76,8 +64,6 @@ async function createLanguageModel(options) {

const options = storedOptions || {
initialPrompts: [],
topK,
temperature,
conversationSummary: 'New conversation',
};

Expand Down
7 changes: 0 additions & 7 deletions firebase-ai-logic/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
const model = getGenerativeModel(ai, {
mode: 'prefer_on_device',
model: 'gemini-2.5-flash',
// Temporarily removing until b/428712667 gets fixed.
/*
onDeviceParams: {
temperature: 0.8,
topK: 10,
},
*/
});

const [pre1, pre2] = Array.from(document.querySelectorAll('pre'));
Expand Down
5 changes: 1 addition & 4 deletions mediarecorder-audio-prompt/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,9 @@ inputFile.oninput = async (event) => {

async function transcribe(blob) {
const arrayBuffer = await blob.arrayBuffer();

const params = await LanguageModel.params();

const session = await LanguageModel.create({
expectedInputs: [{ type: "audio" }],
temperature: 0.1,
topK: params.defaultTopK,
});

const stream = session.promptStreaming([
Expand Down
19 changes: 0 additions & 19 deletions prompt-api-playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,18 @@ <h1>✨ Prompt API Playground</h1>
<button type="submit" id="submit-button">Submit prompt</button>
<button type="button" id="reset-button">Reset session</button>
<span id="cost"></span>
<div class="settings">
<label for="session-top-k">Top-k</label>
<input
id="session-top-k"
min="1"
type="number"
>
<label for="session-temperature">Temperature</label>
<input
id="session-temperature"
type="number"
step="0.1"
min="0"
>
</div>
</form>
<h2>Session stats</h2>
<table>
<thead>
<tr>
<th>Temperature</th>
<th>Top-k</th>
<th>Tokens so far</th>
<th>Tokens left</th>
<th>Total tokens</th>
</tr>
</thead>
<tbody>
<tr>
<td id="temperature">&nbsp;</td>
<td id="top-k">&nbsp;</td>
<td id="tokens-so-far">&nbsp;</td>
<td id="tokens-left">&nbsp;</td>
<td id="max-tokens">&nbsp;</td>
Expand Down
26 changes: 0 additions & 26 deletions prompt-api-playground/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ const SYSTEM_PROMPT = "You are a helpful and friendly assistant.";
const rawResponse = document.querySelector("details div");
const form = document.querySelector("form");
const maxTokensInfo = document.getElementById("max-tokens");
const temperatureInfo = document.getElementById("temperature");
const tokensLeftInfo = document.getElementById("tokens-left");
const tokensSoFarInfo = document.getElementById("tokens-so-far");
const topKInfo = document.getElementById("top-k");
const sessionTemperature = document.getElementById("session-temperature");
const sessionTopK = document.getElementById("session-top-k");

responseArea.style.display = "none";

Expand Down Expand Up @@ -101,9 +97,6 @@ const SYSTEM_PROMPT = "You are a helpful and friendly assistant.";
{ minimumFractionDigits: 1, maximumFractionDigits: 1 },
);

temperatureInfo.textContent = decimalNumberFormat.format(session.temperature);
topKInfo.textContent = numberFormat.format(session.topK);

// In the new API shape, currently in Chrome Canary, `session.maxTokens` was renamed to
// `session.inputQuota` and `session.tokensSoFar` was renamed to `session.inputUsage`.
// `session.tokensSoFar` was removed, but the value can be calculated by subtracting
Expand Down Expand Up @@ -169,10 +162,8 @@ const SYSTEM_PROMPT = "You are a helpful and friendly assistant.";
copyLinkButton.style.display = "none";
copyHelper.style.display = "none";
maxTokensInfo.textContent = "";
temperatureInfo.textContent = "";
tokensLeftInfo.textContent = "";
tokensSoFarInfo.textContent = "";
topKInfo.textContent = "";
promptInput.focus();
};

Expand Down Expand Up @@ -208,8 +199,6 @@ const SYSTEM_PROMPT = "You are a helpful and friendly assistant.";
const updateSession = async () => {
if (self.LanguageModel) {
session = await LanguageModel.create({
temperature: Number(sessionTemperature.value),
topK: Number(sessionTopK.value),
initialPrompts: [
{
role: 'system',
Expand All @@ -222,22 +211,7 @@ const SYSTEM_PROMPT = "You are a helpful and friendly assistant.";
updateStats();
};

sessionTemperature.addEventListener("input", async () => {
await updateSession();
});

sessionTopK.addEventListener("input", async () => {
await updateSession();
});

if (!session) {
let { defaultTopK, maxTopK, defaultTemperature, maxTemperature } = "LanguageModel" in self ?
await LanguageModel.params() : {defaultTopK: 3, maxTopK: 128, defaultTemperature: 1, maxTemperature: 2};
defaultTopK ||= 3; // https://crbug.com/441711146
sessionTemperature.value = defaultTemperature;
sessionTemperature.max = maxTemperature;
sessionTopK.value = defaultTopK;
sessionTopK.max = maxTopK;
await updateSession();
}
})();