updated token
Browse files- index.html +12 -4
index.html
CHANGED
|
@@ -28,12 +28,13 @@
|
|
| 28 |
<div id="loadingStatus" class="loading">⚙️ Processing diff via Serverless Inference API (this can take a moment if the model is waking up)...</div>
|
| 29 |
<div id="outputBox" class="output-box"></div>
|
| 30 |
</div>
|
| 31 |
-
|
| 32 |
<script>
|
| 33 |
async function generateCommit() {
|
| 34 |
-
// Configured automatically with your username
|
| 35 |
const MODEL_ID = "nivethitha1703/developer-git-commit-agent";
|
| 36 |
|
|
|
|
|
|
|
|
|
|
| 37 |
const diffText = document.getElementById("gitDiff").value;
|
| 38 |
const outputBox = document.getElementById("outputBox");
|
| 39 |
const loadingStatus = document.getElementById("loadingStatus");
|
|
@@ -43,16 +44,22 @@ async function generateCommit() {
|
|
| 43 |
return;
|
| 44 |
}
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
outputBox.style.display = "none";
|
| 47 |
loadingStatus.style.display = "block";
|
| 48 |
|
| 49 |
-
// Construct the instruction format for your fine-tuned chat model
|
| 50 |
const prompt = `<|im_start|>system\nYou are an expert software engineer agent. Write a concise, professional Git commit message based on the provided code diff.<|im_end|>\n<|im_start|>user\nCode Diff:\n${diffText}<|im_end|>\n<|im_start|>assistant\n`;
|
| 51 |
|
| 52 |
try {
|
| 53 |
const response = await fetch(`https://huggingface.co{MODEL_ID}`, {
|
| 54 |
method: "POST",
|
| 55 |
headers: {
|
|
|
|
| 56 |
"Content-Type": "application/json"
|
| 57 |
},
|
| 58 |
body: JSON.stringify({
|
|
@@ -66,7 +73,7 @@ async function generateCommit() {
|
|
| 66 |
|
| 67 |
if (data.error) {
|
| 68 |
outputBox.innerText = "API Error: " + data.error;
|
| 69 |
-
} else if (Array.isArray(data) && data[0]
|
| 70 |
let result = data[0].generated_text;
|
| 71 |
result = result.replace(prompt, "").trim();
|
| 72 |
outputBox.innerText = result;
|
|
@@ -87,5 +94,6 @@ async function generateCommit() {
|
|
| 87 |
}
|
| 88 |
</script>
|
| 89 |
|
|
|
|
| 90 |
</body>
|
| 91 |
</html>
|
|
|
|
| 28 |
<div id="loadingStatus" class="loading">⚙️ Processing diff via Serverless Inference API (this can take a moment if the model is waking up)...</div>
|
| 29 |
<div id="outputBox" class="output-box"></div>
|
| 30 |
</div>
|
|
|
|
| 31 |
<script>
|
| 32 |
async function generateCommit() {
|
|
|
|
| 33 |
const MODEL_ID = "nivethitha1703/developer-git-commit-agent";
|
| 34 |
|
| 35 |
+
// FIX: Safely reads the hidden token from Hugging Face infrastructure without revealing it in your code
|
| 36 |
+
const HF_TOKEN = window.huggingface?.variables?.HF_TOKEN;
|
| 37 |
+
|
| 38 |
const diffText = document.getElementById("gitDiff").value;
|
| 39 |
const outputBox = document.getElementById("outputBox");
|
| 40 |
const loadingStatus = document.getElementById("loadingStatus");
|
|
|
|
| 44 |
return;
|
| 45 |
}
|
| 46 |
|
| 47 |
+
if (!HF_TOKEN) {
|
| 48 |
+
outputBox.innerText = "Error: HF_TOKEN secret not found in Space Settings. Please add it first.";
|
| 49 |
+
outputBox.style.display = "block";
|
| 50 |
+
return;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
outputBox.style.display = "none";
|
| 54 |
loadingStatus.style.display = "block";
|
| 55 |
|
|
|
|
| 56 |
const prompt = `<|im_start|>system\nYou are an expert software engineer agent. Write a concise, professional Git commit message based on the provided code diff.<|im_end|>\n<|im_start|>user\nCode Diff:\n${diffText}<|im_end|>\n<|im_start|>assistant\n`;
|
| 57 |
|
| 58 |
try {
|
| 59 |
const response = await fetch(`https://huggingface.co{MODEL_ID}`, {
|
| 60 |
method: "POST",
|
| 61 |
headers: {
|
| 62 |
+
"Authorization": `Bearer ${HF_TOKEN}`,
|
| 63 |
"Content-Type": "application/json"
|
| 64 |
},
|
| 65 |
body: JSON.stringify({
|
|
|
|
| 73 |
|
| 74 |
if (data.error) {
|
| 75 |
outputBox.innerText = "API Error: " + data.error;
|
| 76 |
+
} else if (Array.isArray(data) && data[0]?.generated_text) {
|
| 77 |
let result = data[0].generated_text;
|
| 78 |
result = result.replace(prompt, "").trim();
|
| 79 |
outputBox.innerText = result;
|
|
|
|
| 94 |
}
|
| 95 |
</script>
|
| 96 |
|
| 97 |
+
|
| 98 |
</body>
|
| 99 |
</html>
|