Skip to content

Commit

Permalink
Improve prediction
Browse files Browse the repository at this point in the history
  • Loading branch information
adzialocha committed Nov 4, 2019
1 parent 7ab3bd1 commit 134ad58
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions assets/scripts/app.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const GPT_URL = 'https://gpt-rm5crmv2sq-ew.a.run.app';

const TEMPERATURE = 0.7;
const LENGTH = 30;
const LENGTH_MAX = 30;
const LENGTH_MIN = 60;

function predict(prefix) {
return window.fetch(`${GPT_URL}?length=${LENGTH}&prefix=${prefix}&temperature=${TEMPERATURE}&include_prefix=false`)
function predict(prefix, length, temperature) {
return window.fetch(`${GPT_URL}?include_prefix=false&length=${length}&prefix=${prefix}&temperature=${temperature}`)
.then(response => {
return response.json();
})
Expand All @@ -21,8 +22,9 @@ const textElems = document.querySelectorAll('main > p');
for (let i = 0; i < 3; i += 1) {
const elem = textElems[i];
const prefix = elem.innerText;
const length = MATH_MIN + Math.floor(Math.random() * (LENGTH_MAX - LENGTH_MIN));

predict(prefix)
predict(prefix, length, TEMPERATURE)
.then(text => {
const lastChar = text[text.length - 1];

Expand All @@ -33,6 +35,7 @@ for (let i = 0; i < 3; i += 1) {
}

const cleanedText = text.replace(prefix, '');

elem.innerHTML = `${prefix} <span class="predicted">${cleanedText}</span>`;
});
}
Expand Down

0 comments on commit 134ad58

Please sign in to comment.