mirror of
https://github.com/senju1337/senju.git
synced 2025-12-24 07:39:29 +00:00
feat: increase input length and enforce length in js as well as backend
Refs: OPS-54
This commit is contained in:
parent
a89ad5cba9
commit
8223437f9e
2 changed files with 16 additions and 12 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from logging import raiseExceptions
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from flask import (Flask, redirect, render_template, request, url_for,
|
from flask import (Flask, redirect, render_template, request, url_for,
|
||||||
|
|
@ -74,6 +75,8 @@ def generate_haiku():
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
json_data = request.get_json()
|
json_data = request.get_json()
|
||||||
prompt = json_data["prompt"]
|
prompt = json_data["prompt"]
|
||||||
|
if len(prompt)>100:
|
||||||
|
return "Unprocessable Entity", 422
|
||||||
haiku = Haiku.request_haiku(prompt)
|
haiku = Haiku.request_haiku(prompt)
|
||||||
id = store.save_haiku(haiku)
|
id = store.save_haiku(haiku)
|
||||||
return str(id)
|
return str(id)
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
type="text"
|
type="text"
|
||||||
id="user-input"
|
id="user-input"
|
||||||
minlength="0"
|
minlength="0"
|
||||||
maxlength="25"
|
maxlength="100"
|
||||||
placeholder="Type your prompt here..."
|
placeholder="Type your prompt here..."
|
||||||
class="w-full px-4 py-3 text-lg border-2 border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-violet-600"
|
class="w-full px-4 py-3 text-lg border-2 border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-violet-600"
|
||||||
/>
|
/>
|
||||||
|
|
@ -34,42 +34,43 @@ document.getElementById("submit-btn").addEventListener("click", function() {
|
||||||
let responseBox = document.getElementById("response-box");
|
let responseBox = document.getElementById("response-box");
|
||||||
let responseText = document.getElementById("ai-response");
|
let responseText = document.getElementById("ai-response");
|
||||||
|
|
||||||
|
// Hide the response box initially
|
||||||
|
responseBox.classList.add("opacity-0");
|
||||||
|
|
||||||
if (userInput.trim() === "") {
|
if (userInput.trim() === "") {
|
||||||
responseText.textContent = "Please enter a prompt!";
|
responseText.textContent = "Please enter a prompt!";
|
||||||
}
|
}
|
||||||
else if (userInput.trim()==="amogus"){
|
else if (userInput.length !== 5) {
|
||||||
|
responseText.textContent = "Input must be exactly 5 characters long!";
|
||||||
|
}
|
||||||
|
else if (userInput.trim() === "amogus") {
|
||||||
responseText.textContent = "🤖 AI is thinking...";
|
responseText.textContent = "🤖 AI is thinking...";
|
||||||
responseBox.classList.remove("opacity-0");
|
responseBox.classList.remove("opacity-0");
|
||||||
|
|
||||||
// Simulated AI response delay
|
// Simulated AI response delay
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
responseText.textContent = `Sus imposter ඞ`;
|
responseText.textContent = "Sus imposter ඞ";
|
||||||
}, 1500);
|
}, 1500);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
responseText.textContent = "🤖 AI is thinking...";
|
responseText.textContent = "🤖 AI is thinking...";
|
||||||
responseBox.classList.remove("opacity-0");
|
responseBox.classList.remove("opacity-0");
|
||||||
|
|
||||||
console.log(userInput );
|
|
||||||
|
|
||||||
fetch('/api/v1/haiku', {
|
fetch('/api/v1/haiku', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({'prompt': userInput})
|
body: JSON.stringify({ 'prompt': userInput })
|
||||||
})
|
})
|
||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
console.log(data);
|
|
||||||
let id = parseInt(data, 10);
|
let id = parseInt(data, 10);
|
||||||
window.location.href = "/haiku/"+id;
|
window.location.href = "/haiku/" + id;
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
document.getElementById('result').innerHTML = '<strong>Error:</strong> ' + error.message;
|
responseText.textContent = 'Error: ' + error.message;
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue