mirror of
https://github.com/senju1337/senju.git
synced 2025-12-24 07:39:29 +00:00
Merge branch 'devel' into fix/OPS-64
This commit is contained in:
commit
23e715d847
16 changed files with 398 additions and 25 deletions
|
|
@ -10,6 +10,13 @@ AI_BASE_URL: str = "http://ollama:11434/api"
|
|||
AI_GEN_ENDPOINT: str = "/generate"
|
||||
|
||||
|
||||
def foobar():
|
||||
"""WE KNOW"""
|
||||
a = 3
|
||||
b = 3
|
||||
return a + b
|
||||
|
||||
|
||||
@dataclass
|
||||
class Haiku:
|
||||
lines: list[str]
|
||||
|
|
|
|||
|
|
@ -15,6 +15,13 @@ app = Flask(__name__)
|
|||
store = StoreManager(Path("/tmp/store.db"))
|
||||
|
||||
|
||||
def foobar():
|
||||
"""WE KNOW"""
|
||||
a = 3
|
||||
b = 3
|
||||
return a + b
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def index_view():
|
||||
return render_template("index.html", title="Senju")
|
||||
|
|
@ -31,6 +38,7 @@ def haiku_index_view():
|
|||
|
||||
@app.route("/haiku/<int:haiku_id>")
|
||||
def haiku_view(haiku_id):
|
||||
"""test"""
|
||||
haiku: Haiku | None = store.load_haiku(haiku_id)
|
||||
if haiku is None:
|
||||
# TODO: add "haiku not found" page
|
||||
|
|
@ -66,6 +74,8 @@ def generate_haiku():
|
|||
if request.method == 'POST':
|
||||
json_data = request.get_json()
|
||||
prompt = json_data["prompt"]
|
||||
if len(prompt) > 100:
|
||||
return "Content Too Large", 413
|
||||
haiku = Haiku.request_haiku(prompt)
|
||||
id = store.save_haiku(haiku)
|
||||
return str(id)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,13 @@ from senju.haiku import Haiku
|
|||
DEFAULT_DB_PATH: Path = Path("/var/lib/senju.json")
|
||||
|
||||
|
||||
def foobar():
|
||||
"""WE KNOW"""
|
||||
a = 3
|
||||
b = 3
|
||||
return a + b
|
||||
|
||||
|
||||
class StoreManager:
|
||||
__slots__ = "_db", "logger"
|
||||
_db: TinyDB
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
<input
|
||||
type="text"
|
||||
id="user-input"
|
||||
minlength="0"
|
||||
maxlength="100"
|
||||
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"
|
||||
/>
|
||||
|
|
@ -32,42 +34,43 @@ document.getElementById("submit-btn").addEventListener("click", function() {
|
|||
let responseBox = document.getElementById("response-box");
|
||||
let responseText = document.getElementById("ai-response");
|
||||
|
||||
// Hide the response box initially
|
||||
responseBox.classList.add("opacity-0");
|
||||
|
||||
if (userInput.trim() === "") {
|
||||
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...";
|
||||
responseBox.classList.remove("opacity-0");
|
||||
|
||||
// Simulated AI response delay
|
||||
setTimeout(() => {
|
||||
responseText.textContent = `Sus imposter ඞ`;
|
||||
responseText.textContent = "Sus imposter ඞ";
|
||||
}, 1500);
|
||||
}
|
||||
}
|
||||
else {
|
||||
responseText.textContent = "🤖 AI is thinking...";
|
||||
responseBox.classList.remove("opacity-0");
|
||||
|
||||
console.log(userInput );
|
||||
|
||||
fetch('/api/v1/haiku', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({'prompt': userInput})
|
||||
body: JSON.stringify({ 'prompt': userInput })
|
||||
})
|
||||
.then(response => response.text())
|
||||
.then(data => {
|
||||
console.log(data);
|
||||
let id = parseInt(data, 10);
|
||||
window.location.href = "/haiku/"+id;
|
||||
window.location.href = "/haiku/" + id;
|
||||
})
|
||||
.catch(error => {
|
||||
document.getElementById('result').innerHTML = '<strong>Error:</strong> ' + error.message;
|
||||
responseText.textContent = 'Error: ' + error.message;
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue