From 3168b250e03a88e81cb7d05fb4ac55b0e72e8b8d Mon Sep 17 00:00:00 2001 From: Alivecow Date: Fri, 21 Mar 2025 14:13:14 +0100 Subject: [PATCH 01/10] fix: Fix poem extraction from AI response Refs: OPS-64 --- .gitignore | 3 +++ senju/haiku.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a1db2f1..a2b9c12 100644 --- a/.gitignore +++ b/.gitignore @@ -174,3 +174,6 @@ pyrightconfig.json # Ollama Local Dir ollama + +# Yes i know +*.kate-swp diff --git a/senju/haiku.py b/senju/haiku.py index 2fd7a2f..66d5348 100644 --- a/senju/haiku.py +++ b/senju/haiku.py @@ -39,7 +39,7 @@ class Haiku: lines = ai_response.split("\n") - for _ in range(0, 2): + while len(lines) != 3: lines.pop() logging.warning(lines) From 44bbfa24d3eb14fb35c416da6946f67fb92a7628 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Fri, 14 Mar 2025 16:55:37 +0100 Subject: [PATCH 02/10] chore: setup a simple generation for the documentation Refs: OPS-63 --- .github/workflows/gendocs.yml | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/gendocs.yml diff --git a/.github/workflows/gendocs.yml b/.github/workflows/gendocs.yml new file mode 100644 index 0000000..d094fa1 --- /dev/null +++ b/.github/workflows/gendocs.yml @@ -0,0 +1,38 @@ +name: Build and Store Documentation Artifact + +on: + push: + branches: + - master + - devel + pull_request: + branches: + - master + - devel + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: '3.11' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install sphinx + - name: Build Sphinx documentation + run: | + cd docs + sphinx-apidoc -o source/_modules ../senju + make html + - name: Upload documentation artifact + uses: actions/upload-artifact@v4 + with: + name: documentation-artifact + path: docs/build/html + # TODO: upload artifact for gh pages + # TODO: deploy to gh pages From 57d2f31b19fd56fe221c125f5b7c7e8aeddd5b49 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Fri, 21 Mar 2025 13:51:45 +0100 Subject: [PATCH 03/10] chore: deploy docs to github pages and manual artifacts Refs: OPS-63 --- .github/workflows/gendocs.yml | 44 ++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/.github/workflows/gendocs.yml b/.github/workflows/gendocs.yml index d094fa1..a26ace9 100644 --- a/.github/workflows/gendocs.yml +++ b/.github/workflows/gendocs.yml @@ -5,14 +5,18 @@ on: branches: - master - devel - pull_request: - branches: - - master - - devel + +permissions: + contents: read + pages: write + id-token: write jobs: build: runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} steps: - name: Checkout code uses: actions/checkout@v3 @@ -23,16 +27,28 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install sphinx + pip install sphinx poetry + poetry install - name: Build Sphinx documentation run: | - cd docs - sphinx-apidoc -o source/_modules ../senju - make html - - name: Upload documentation artifact - uses: actions/upload-artifact@v4 + cd docs && ls + bash auto_docu.sh + - name: Upload documentation files as artifact + id: deployment + uses: actions/upload-pages-artifact@v3 # or specific "vX.X.X" version tag for this action with: - name: documentation-artifact - path: docs/build/html - # TODO: upload artifact for gh pages - # TODO: deploy to gh pages + path: docs/build/html/ + + deploy: + needs: build + + # Deploy to the github-pages environment + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + runs-on: ubuntu-latest + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 From 862c0d915c94a0906c3e9048ca4808dfc88ebde0 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Fri, 21 Mar 2025 15:04:30 +0100 Subject: [PATCH 04/10] fix: remove foobar functions which was only used to test if sphinx works Refs: OPS-69 --- senju/haiku.py | 7 ------- senju/main.py | 7 ------- senju/store_manager.py | 7 ------- 3 files changed, 21 deletions(-) diff --git a/senju/haiku.py b/senju/haiku.py index e112215..2fd7a2f 100644 --- a/senju/haiku.py +++ b/senju/haiku.py @@ -10,13 +10,6 @@ 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] diff --git a/senju/main.py b/senju/main.py index 663a7c5..766a5d6 100644 --- a/senju/main.py +++ b/senju/main.py @@ -15,13 +15,6 @@ 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") diff --git a/senju/store_manager.py b/senju/store_manager.py index 72a4561..e99b98e 100644 --- a/senju/store_manager.py +++ b/senju/store_manager.py @@ -12,13 +12,6 @@ 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 From a89ad5cba927017d60b37213f002d937632012ba Mon Sep 17 00:00:00 2001 From: 0xjrx Date: Fri, 21 Mar 2025 15:06:26 +0100 Subject: [PATCH 05/10] feat: Add a maximum input length fo the prompt Refs: OPS-54 --- senju/templates/prompt.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/senju/templates/prompt.html b/senju/templates/prompt.html index 218809d..a72c12f 100644 --- a/senju/templates/prompt.html +++ b/senju/templates/prompt.html @@ -8,6 +8,8 @@ From 8223437f9ea4009f85be6c9da65180f40ea3297e Mon Sep 17 00:00:00 2001 From: 0xjrx Date: Fri, 21 Mar 2025 15:23:02 +0100 Subject: [PATCH 06/10] feat: increase input length and enforce length in js as well as backend Refs: OPS-54 --- senju/main.py | 3 +++ senju/templates/prompt.html | 25 +++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/senju/main.py b/senju/main.py index 663a7c5..98ef2d8 100644 --- a/senju/main.py +++ b/senju/main.py @@ -1,5 +1,6 @@ from __future__ import annotations +from logging import raiseExceptions from pathlib import Path from flask import (Flask, redirect, render_template, request, url_for, @@ -74,6 +75,8 @@ def generate_haiku(): if request.method == 'POST': json_data = request.get_json() prompt = json_data["prompt"] + if len(prompt)>100: + return "Unprocessable Entity", 422 haiku = Haiku.request_haiku(prompt) id = store.save_haiku(haiku) return str(id) diff --git a/senju/templates/prompt.html b/senju/templates/prompt.html index a72c12f..2721a4a 100644 --- a/senju/templates/prompt.html +++ b/senju/templates/prompt.html @@ -9,7 +9,7 @@ type="text" id="user-input" minlength="0" - maxlength="25" + 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" /> @@ -34,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 !== 5) { + responseText.textContent = "Input must be exactly 5 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 = 'Error: ' + error.message; + responseText.textContent = 'Error: ' + error.message; }); - } }); - {% endblock %} From 1ca1bc525b882f29a8507f0c7a2b769c72cb600f Mon Sep 17 00:00:00 2001 From: 0xjrx Date: Fri, 21 Mar 2025 15:26:30 +0100 Subject: [PATCH 07/10] fix: remove unnecessary import Refs: OPS-54 --- senju/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/senju/main.py b/senju/main.py index 98ef2d8..b253183 100644 --- a/senju/main.py +++ b/senju/main.py @@ -1,6 +1,5 @@ from __future__ import annotations -from logging import raiseExceptions from pathlib import Path from flask import (Flask, redirect, render_template, request, url_for, From 36c3d0a83fb8fe924492204d97528d6292ced672 Mon Sep 17 00:00:00 2001 From: 0xjrx Date: Fri, 21 Mar 2025 15:31:51 +0100 Subject: [PATCH 08/10] fix: changed html error code to the correct one Refs: OPS-54 --- senju/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/senju/main.py b/senju/main.py index b253183..b35fbee 100644 --- a/senju/main.py +++ b/senju/main.py @@ -75,7 +75,7 @@ def generate_haiku(): json_data = request.get_json() prompt = json_data["prompt"] if len(prompt)>100: - return "Unprocessable Entity", 422 + return "Content Too Large", 413 haiku = Haiku.request_haiku(prompt) id = store.save_haiku(haiku) return str(id) From c705e863d144d6f9a7ed5cdccb0d536d56490ed0 Mon Sep 17 00:00:00 2001 From: 0xjrx Date: Fri, 21 Mar 2025 15:56:08 +0100 Subject: [PATCH 09/10] fix: fix js to limit user input Reps: OPS-54 --- senju/templates/prompt.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/senju/templates/prompt.html b/senju/templates/prompt.html index 2721a4a..3ce5170 100644 --- a/senju/templates/prompt.html +++ b/senju/templates/prompt.html @@ -40,8 +40,8 @@ document.getElementById("submit-btn").addEventListener("click", function() { if (userInput.trim() === "") { responseText.textContent = "Please enter a prompt!"; } - else if (userInput.length !== 5) { - responseText.textContent = "Input must be exactly 5 characters long!"; + else if (userInput.length > 100) { + responseText.textContent = "Input must under 100 characters long!"; } else if (userInput.trim() === "amogus") { responseText.textContent = "🤖 AI is thinking..."; From 740358ae72498af6a7183d6974e7449ddc292d65 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 21 Mar 2025 14:56:43 +0000 Subject: [PATCH 10/10] ci: automatic Python Formatter changes --- senju/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/senju/main.py b/senju/main.py index b35fbee..1bdfd27 100644 --- a/senju/main.py +++ b/senju/main.py @@ -74,7 +74,7 @@ def generate_haiku(): if request.method == 'POST': json_data = request.get_json() prompt = json_data["prompt"] - if len(prompt)>100: + if len(prompt) > 100: return "Content Too Large", 413 haiku = Haiku.request_haiku(prompt) id = store.save_haiku(haiku)