Rock YouTube channel with real views, likes and subscribers
Get Free YouTube Subscribers, Views and Likes

I Coded Working AI in Scratch!

Follow
Donutask

Not just a bunch of ifs and say blocks this is real AI.


Scratch Profile: https://scratch.mit.edu/users/charles...
Email: [email protected]
Website: donutask.com

I can't publish this extension because it requires an API key. Here are the resources you need to create it yourself. The OpenAI API, ironically, requires real money to use.
Scratch mod used: https://sheeptester.github.io/scratch...
OpenAI Documentation: https://platform.openai.com/docs/api...
Get API Key (requires account and billing details): https://platform.openai.com/account/a...
JavaScript Code (You need to provide an API key):
class AIBlock {
getInfo() {
//Metadata for block
return {
"id": "AI",
"name": "AI",
"blocks": [{
"opcode": "completePrompt",
"blockType": "reporter",
"text": "complete prompt [string]",
"arguments": {
"string": {
"type": "string",
"defaultValue": "Explain quantum computing in simple terms"
}
}
}],
//don't worry about it
"menus": {}
};
}

async completePrompt({ string }) {
//Remove trailing spaces, required for model to work properly
const text = string.trim();
//Request text completion using Davinci3
const url = `https://api.openai.com/v1/engines/tex...`;

const options = {
//Has to be post for some reason
method: "POST",
//Input prompt and a decent length
body: JSON.stringify({
prompt: text,
max_tokens: 300,
}),
//API key, and JSON content type
headers: {
Authorization: "Bearer " + API_KEY,
"Contenttype": "application/json; charset=UTF8"
},
};

console.log("REQUEST:" + url);

//Fetch and await promise.
const response = await fetch(url, options);
//Get JSON data
const jsonData = await response.json();

//The ai response will be the first (and only) choices text
const output = jsonData.choices[0].text;
return output;
}

}

//Register block with Scratch
Scratch.extensions.register(new AIBlock());

Sound effects from ZapSplat.com
Some images generated by DALLE
Images and videos from Unsplash.com and Pexels.com
Music by Kevin MacLeod (incompetech.com)
Licensed under Creative Commons: By Attribution 4.0 License
http://creativecommons.org/licenses/b...

Subscribe!
Oh, and if you want to support me financially, consider becoming a member :)
   / @donut_ask  

posted by ntikoak