INNER CODE UNIT · JavaScript
start
eugeneyan/obsidian-copilot · plugin/main.js:90
start = end + 1;
try {
const messageWithoutPrefix = message.replace("data: ", "");
const json = JSON.parse(messageWithoutPrefix);
let lastToken = "";
if (json.choices && json.choices.length > 0 && json.choices[0].delta && json.choices[0].delta.content) {
let token = json.choices[0].delta.content;
if (token === " ") {
lastToken += token;
token = lastToken;
} else {
lastToken = token;
}
editor.replaceSelection(token);
}
} catch (err) {
}
end = buffer.indexOf("\n", start);