diff --git a/app.js b/app.js index c8cca45..6b9ba87 100644 --- a/app.js +++ b/app.js @@ -216,8 +216,10 @@ function require(pathname) { var T = null; var pos = FN.indexOf('://'); if (pos > -1) { + var scheme = FN.substring(0, pos); + // load script from a remote server - if (["http", "https"].indexOf(FN.substring(0, pos)) > -1) { + if (["http", "https"].indexOf(scheme) > -1) { require._addScriptProvider(function(url) { try { return require("lib/http").get(url); @@ -226,7 +228,19 @@ function require(pathname) { } }); } - + + // load script from ChatGPT (LLM based AI) service + if (["ai"].indexOf(scheme) > -1) { + require._addScriptProvider(function(url) { + try { + return require("lib/chatgpt").get(url); + } catch (e) { + return null; + } + }); + } + + // if exists the custom script providers if (require._scriptProviders.length > 0) { var i = 0; while (T == null && i < require._scriptProviders.length) { diff --git a/lib/chatgpt.js b/lib/chatgpt.js index 4515c81..31df256 100644 --- a/lib/chatgpt.js +++ b/lib/chatgpt.js @@ -25,12 +25,15 @@ function chat(content) { "Authorization": "Bearer {OPENAI_API_KEY}" }) .setRequestBody({ - "model": "gpt-3.5-turbo", + "model": "gpt-4o", "messages": [ - { - "role": "user", - "content": content - } + { + "role": "developer", + "content": "Write all future code examples in JavaScript ES3 using the exports variable. Respond exclusively in code without blocks." + }, { + "role": "user", + "content": content + } ] }) .open("post", "https://api.openai.com/v1/chat/completions")