GPT Auto Fixer
Enter your GPT API key:
Enter your code:
Fixed code:
ご要望いただいたアプリケーションを実現するには、以下の手順に従って実装することができます。
1. HTMLファイルを作成します。このファイルには、GPT APIキーを入力するためのテキストボックスと、修正対象のコードを入力するテキストエリアを作成します。
2. JavaScriptコードを記述します。このコードは、APIキーを取得し、入力されたコードをGPT APIに送信して修正を行います。修正が完了したら、修正されたコードを出力する処理を記述します。
3. セキュリティ対策として、evalを使ったコードの実行や、他のサイトへの遷移、リダイレクトのような危険な処理については、禁止するようにします。
以下に個人的なジョークを交えた実装例を示しますが、GPT APIに関する知識が必要であることをご了承ください。
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>GPT Auto Fixer</title>
</head>
<body>
<h1>GPT Auto Fixer</h1>
<p>Enter your GPT API key:</p>
<input id="api-key" type="text">
<p>Enter your code:</p>
<textarea id="input-code"></textarea>
<button id="fix-button">Fix my code!</button>
<p>Fixed code:</p>
<textarea id="output-code"></textarea>
<script>
function fixMyCode() {
const apiKey = document.getElementById("api-key").value;
const inputCode = document.getElementById("input-code").value;
// セキュリティ対策
if (inputCode.includes("eval")) {
alert("Sorry, we cannot fix code that uses eval.");
return;
}
if (inputCode.includes("window.location") || inputCode.includes("location.href")) {
alert("Sorry, we cannot fix code that tries to redirect the page.");
return;
}
if (inputCode.includes("document.cookie") || inputCode.includes("localStorage") || inputCode.includes("sessionStorage")) {
alert("Sorry, we cannot fix code that tries to access sensitive information.");
return;
}
// GPT APIにリクエストを送信
fetch("https://api.openai.com/v1/engines/davinci-codex/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + apiKey
},
body: JSON.stringify({ prompt: inputCode })
})
.then(response => response.json())
.then(data => {
const outputCode = data.choices[0].text;
// セキュリティ対策
if (outputCode.includes("window.location") || outputCode.includes("location.href")) {
alert("Sorry, we cannot fix code that tries to redirect the page.");
return;
}
if (outputCode.includes("document.cookie") || outputCode.includes("localStorage") || outputCode.includes("sessionStorage")) {
alert("Sorry, we cannot fix code that tries to access sensitive information.");
return;
}
document.getElementById("output-code").value = outputCode;
alert("Your code is fixed!");
})
.catch(error => console.error(error));
}
document.getElementById("fix-button").addEventListener("click", fixMyCode);
</script>
</body>
</html>
```