AskChatGPT
code:6.0.js
// ==UserScript==
// @name AskChatGPT
// @version 6.0
// @description DALL-Eアクセス用のエンドポイントを作成した
// @author gosyujin
// @grant GM_xmlhttpRequest
// ==/UserScript==
unsafeWindow.ask_dalle = (prompt = '寝ている犬', model = 'dall-e-3', n = 1, size = '1024x1024') => {
const token = 'your token';
const header = {
"Content-Type": "application/json",
Authorization: Bearer ${token}
};
const data = JSON.stringify({
model: model,
prompt: prompt,
n: n,
size: size
});
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: 'POST',
headers: header,
url: endpoint,
data: data,
onload(res) {
console.log('onload');
resolve(res);
},
onreadystatechange (readyState) {
},
onprogress(progress) {
},
onabort(err) {
console.log('onabort');
console.log(err);
reject(err);
},
ontimeout(err) {
console.log('ontimeout');
console.log(err);
reject(err);
},
onerror(err) {
console.log('onerror');
console.log(err);
reject(err);
},
withCredentials: true
});
});
}
, max_token=500
, temperature = 0.5
, model = 'gpt-3.5-turbo-0301'
, systemPrompt = {}
, isStream = false) => {
const token = 'YOUR_TOKEN';
const header = {
"Content-Type": "application/json",
Authorization: Bearer ${token}
};
const data = JSON.stringify({
temperature: temperature,
max_tokens: max_token,
model: model,
messages: conversations,
stream: isStream
});
let responseType = 'text'; // arraybuffer, blob, json or stream
if (isStream) {
responseType = 'stream';
}
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: 'POST',
headers: header,
url: endpoint,
data: data,
responseType: responseType,
onload(res) {
//console.log('onload');
resolve(res);
},
onreadystatechange (readyState) {
},
onprogress(progress) {
},
onabort(err) {
console.log('onabort');
console.log(err);
reject(err);
},
ontimeout(err) {
console.log('ontimeout');
console.log(err);
reject(err);
},
onerror(err) {
console.log('onerror');
console.log(err);
reject(err);
},
withCredentials: true
});
});
}
OpenAIのChatGPT API(/v1/chat/completions)にアクセスしてレスポンスを返してもらう 関連
更新履歴
v1.0(2023/03/15)
v2.0(2023/03/16)
v6.0