mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-06 06:54:58 +00:00
ChatGPT + MS Office
This commit is contained in:
parent
848bded217
commit
796918e07e
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -108,3 +108,6 @@ bin/
|
|||
packages/
|
||||
config.xml
|
||||
staticip.xml
|
||||
|
||||
# ChatGPT API Key
|
||||
data/chatgpt-apikey.txt
|
||||
|
|
49
lib/chatgpt.js
Normal file
49
lib/chatgpt.js
Normal file
|
@ -0,0 +1,49 @@
|
|||
var FILE = require("lib/file");
|
||||
var HTTP = require("lib/http");
|
||||
|
||||
function loadApiKey() {
|
||||
var s = FILE.readFile("data/chatgpt-apikey.txt", FILE.CdoCharset.CdoUTF_8);
|
||||
return s.trim();
|
||||
}
|
||||
|
||||
function chat(content) {
|
||||
var s = '';
|
||||
|
||||
var apikey = loadApiKey();
|
||||
console.log("ChatGPT API KEY:", apikey);
|
||||
|
||||
var response = HTTP.create("MSXML")
|
||||
.setVariables({
|
||||
"OPENAI_API_KEY": apikey
|
||||
})
|
||||
.setHeaders({
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Bearer {OPENAI_API_KEY}"
|
||||
})
|
||||
.setRequestBody({
|
||||
"model": "gpt-3.5-turbo",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": content
|
||||
}
|
||||
]
|
||||
})
|
||||
.open("post", "https://api.openai.com/v1/chat/completions")
|
||||
.send()
|
||||
.responseBody
|
||||
;
|
||||
|
||||
if (response.choices.length > 0) {
|
||||
s += response.choices[0].message.content;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
exports.chat = chat;
|
||||
|
||||
exports.VERSIONINFO = "ChatGPT interface (chatgpt.js) version 0.1";
|
||||
exports.AUTHOR = "abuse@catswords.net";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
|
@ -1,13 +1,17 @@
|
|||
var Office = require("lib/msoffice");
|
||||
var ChatGPT = require("lib/chatgpt");
|
||||
|
||||
function main(args) {
|
||||
var excel = new Office.Excel();
|
||||
|
||||
excel.open();
|
||||
|
||||
excel.getValueByPosition(1, 1, "hello world");
|
||||
var message = ChatGPT.chat("Say this is a test!");
|
||||
console.log(message);
|
||||
|
||||
excel.close();
|
||||
excel.setValueByPosition(1, 1, message);
|
||||
|
||||
//excel.close();
|
||||
}
|
||||
|
||||
exports.main = main;
|
Loading…
Reference in New Issue
Block a user