「从零开始开发一个简单的ChatGPT应用」

2个月前发布 yundic
454 0 0


const model = await tf.loadGraphModel(‘https://tfhub.dev/tensorflow/tfgpt2/small/2’);
const gpt2 = new GPT2Generator(model);

document.getElementById(‘inputText’).addEventListener(‘keyup’, async function(event) {
if (event.keyCode === 13) {
const input = document.getElementById(‘inputText’);
const output = document.getElementById(‘outputText’);
output.innerHTML = await generateResponse(input.value);
input.value = ”;
}
});

async function generateResponse(input) {
const gpt2Results = await gpt2.generate({
context: input,
length: 50
});
return gpt2Results.data.lines.join(‘
‘);
}

source

© 版权声明

相关文章

暂无评论

暂无评论...