2024-11-25 11:55:47 +00:00
// chatgpt.js
// Namhyeon Go <abuse@catswords.net>
// https://github.com/gnh1201/welsonjs
//
// ***SECURITY NOTICE***
2024-11-25 16:41:21 +00:00
// ChatGPT requires an internet connection, and data may be transmitted externally. Users must adhere to the terms of use and privacy policy.
2024-11-25 11:55:47 +00:00
// - Privacy Policy: https://openai.com/policies/row-privacy-policy/
//
2023-11-27 09:03:22 +00:00
var FILE = require ( "lib/file" ) ;
var HTTP = require ( "lib/http" ) ;
2025-01-13 05:46:48 +00:00
var CRED = require ( "lib/credentials" ) ;
2023-11-27 09:03:22 +00:00
function chat ( content ) {
2024-12-27 05:52:17 +00:00
var answers = [ ] ;
2025-01-13 05:46:48 +00:00
var apikey = CRED . get ( "apikey" , "chatgpt" ) ;
2025-01-17 05:04:35 +00:00
console . log ( "OpenAI (ChatGPT) API KEY:" , apikey ) ;
2023-11-27 09:03:22 +00:00
var response = HTTP . create ( "MSXML" )
. setVariables ( {
"OPENAI_API_KEY" : apikey
} )
. setHeaders ( {
"Content-Type" : "application/json" ,
"Authorization" : "Bearer {OPENAI_API_KEY}"
} )
. setRequestBody ( {
2025-01-20 01:04:49 +00:00
"model" : "gpt-4o" ,
2023-11-27 09:03:22 +00:00
"messages" : [
2025-01-20 01:04:49 +00:00
{
"role" : "developer" ,
2025-01-20 01:18:10 +00:00
"content" : "Write all future code examples in JavaScript ES3 using the exports variable. Include a test method with the fixed name test. Respond exclusively in code without blocks."
2025-01-20 01:04:49 +00:00
} , {
"role" : "user" ,
"content" : content
}
2023-11-27 09:03:22 +00:00
]
} )
. open ( "post" , "https://api.openai.com/v1/chat/completions" )
. send ( )
. responseBody
;
2025-01-17 05:04:35 +00:00
if ( "choices" in response && response . choices . length > 0 ) {
2024-12-27 05:52:17 +00:00
response . choices . forEach ( function ( x ) {
answers . push ( x . message . content ) ;
} ) ;
2023-11-27 09:03:22 +00:00
}
return s ;
}
exports . chat = chat ;
2025-01-17 05:04:35 +00:00
exports . VERSIONINFO = "OpenAI (ChatGPT) interface version 0.1.2" ;
2023-11-27 09:03:22 +00:00
exports . AUTHOR = "abuse@catswords.net" ;
exports . global = global ;
exports . require = global . require ;