mirror of
https://github.com/senju1337/senju.git
synced 2025-12-24 07:39:29 +00:00
Merge pull request #37 from senju1337/feat/OPS-54
Feat/ops-54: Add a maximum input length fo the prompt
This commit is contained in:
commit
7880919e06
2 changed files with 16 additions and 11 deletions
|
|
@ -74,6 +74,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 "Content Too Large", 413
|
||||||
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)
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
id="user-input"
|
id="user-input"
|
||||||
|
minlength="0"
|
||||||
|
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"
|
||||||
/>
|
/>
|
||||||
|
|
@ -32,24 +34,28 @@ 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.length > 100) {
|
||||||
|
responseText.textContent = "Input must under 100 characters long!";
|
||||||
|
}
|
||||||
else if (userInput.trim() === "amogus") {
|
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: {
|
||||||
|
|
@ -59,15 +65,12 @@ document.getElementById("submit-btn").addEventListener("click", function() {
|
||||||
})
|
})
|
||||||
.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