mirror of
https://github.com/senju1337/senju.git
synced 2025-12-24 07:39:29 +00:00
Merge branch 'devel' into feat/OPS-56
This commit is contained in:
commit
f52deafc18
18 changed files with 473 additions and 77 deletions
|
|
@ -68,7 +68,7 @@ coverage.xml
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
# Sphinx documentation
|
# Sphinx documentation
|
||||||
docs/_build/
|
requirements/_build/
|
||||||
|
|
||||||
# PyBuilder
|
# PyBuilder
|
||||||
target/
|
target/
|
||||||
|
|
|
||||||
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -69,7 +69,7 @@ instance/
|
||||||
.scrapy
|
.scrapy
|
||||||
|
|
||||||
# Sphinx documentation
|
# Sphinx documentation
|
||||||
docs/_build/
|
requirements/_build/
|
||||||
|
|
||||||
# PyBuilder
|
# PyBuilder
|
||||||
.pybuilder/
|
.pybuilder/
|
||||||
|
|
@ -174,3 +174,6 @@ pyrightconfig.json
|
||||||
|
|
||||||
# Ollama Local Dir
|
# Ollama Local Dir
|
||||||
ollama
|
ollama
|
||||||
|
|
||||||
|
# sphinx rst files
|
||||||
|
docs/source/_modules
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ WORKDIR /app
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
RUN apk add curl
|
RUN apk add curl bash jq
|
||||||
RUN pip install poetry
|
RUN pip install poetry
|
||||||
RUN poetry install
|
RUN poetry install
|
||||||
|
|
||||||
|
|
|
||||||
20
docs/Makefile
Normal file
20
docs/Makefile
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Minimal makefile for Sphinx documentation
|
||||||
|
#
|
||||||
|
|
||||||
|
# You can set these variables from the command line, and also
|
||||||
|
# from the environment for the first two.
|
||||||
|
SPHINXOPTS ?=
|
||||||
|
SPHINXBUILD ?= sphinx-build
|
||||||
|
SOURCEDIR = source
|
||||||
|
BUILDDIR = build
|
||||||
|
|
||||||
|
# Put it first so that "make" without argument is like "make help".
|
||||||
|
help:
|
||||||
|
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||||
|
|
||||||
|
.PHONY: help Makefile
|
||||||
|
|
||||||
|
# Catch-all target: route all unknown targets to Sphinx using the new
|
||||||
|
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||||
|
%: Makefile
|
||||||
|
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||||
5
docs/auto_docu.sh
Normal file
5
docs/auto_docu.sh
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
rm -rf source/_modules
|
||||||
|
sphinx-apidoc -o source/_modules ../senju
|
||||||
|
poetry run make clean
|
||||||
|
poetry run make html
|
||||||
35
docs/make.bat
Normal file
35
docs/make.bat
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
@ECHO OFF
|
||||||
|
|
||||||
|
pushd %~dp0
|
||||||
|
|
||||||
|
REM Command file for Sphinx documentation
|
||||||
|
|
||||||
|
if "%SPHINXBUILD%" == "" (
|
||||||
|
set SPHINXBUILD=sphinx-build
|
||||||
|
)
|
||||||
|
set SOURCEDIR=source
|
||||||
|
set BUILDDIR=build
|
||||||
|
|
||||||
|
%SPHINXBUILD% >NUL 2>NUL
|
||||||
|
if errorlevel 9009 (
|
||||||
|
echo.
|
||||||
|
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
|
||||||
|
echo.installed, then set the SPHINXBUILD environment variable to point
|
||||||
|
echo.to the full path of the 'sphinx-build' executable. Alternatively you
|
||||||
|
echo.may add the Sphinx directory to PATH.
|
||||||
|
echo.
|
||||||
|
echo.If you don't have Sphinx installed, grab it from
|
||||||
|
echo.https://www.sphinx-doc.org/
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
if "%1" == "" goto help
|
||||||
|
|
||||||
|
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
||||||
|
goto end
|
||||||
|
|
||||||
|
:help
|
||||||
|
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
||||||
|
|
||||||
|
:end
|
||||||
|
popd
|
||||||
BIN
docs/source/_static/kanji.png
Normal file
BIN
docs/source/_static/kanji.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
34
docs/source/conf.py
Normal file
34
docs/source/conf.py
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
# Configuration file for the Sphinx documentation builder.
|
||||||
|
#
|
||||||
|
# For the full list of built-in configuration values, see the documentation:
|
||||||
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
||||||
|
|
||||||
|
# -- Project information -----------------------------------------------------
|
||||||
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
sys.path.insert(0, os.path.abspath("../../senju"))
|
||||||
|
|
||||||
|
project = 'senju'
|
||||||
|
copyright = '2025, senju hashirama'
|
||||||
|
author = 'senju hashirama'
|
||||||
|
release = 'before the light'
|
||||||
|
# -- General configuration ---------------------------------------------------
|
||||||
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
||||||
|
|
||||||
|
extensions = ['sphinx.ext.autodoc',
|
||||||
|
'sphinx.ext.napoleon']
|
||||||
|
|
||||||
|
templates_path = ['_templates']
|
||||||
|
exclude_patterns = []
|
||||||
|
|
||||||
|
autodoc_typehints = 'both'
|
||||||
|
|
||||||
|
# -- Options for HTML output -------------------------------------------------
|
||||||
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
||||||
|
|
||||||
|
html_theme = 'nature'
|
||||||
|
html_static_path = ['_static']
|
||||||
|
|
||||||
|
html_favicon = '_static/kanji.png'
|
||||||
|
html_logo = '_static/kanji.png'
|
||||||
19
docs/source/index.rst
Normal file
19
docs/source/index.rst
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
.. senju documentation master file, created by
|
||||||
|
sphinx-quickstart on Fri Mar 14 15:18:32 2025.
|
||||||
|
You can adapt this file completely to your liking, but it should at least
|
||||||
|
contain the root `toctree` directive.
|
||||||
|
|
||||||
|
Welcome senju documentation
|
||||||
|
===========================
|
||||||
|
|
||||||
|
Add your content using ``reStructuredText`` syntax. See the
|
||||||
|
`reStructuredText <https://www.sphinx-doc.org/en/master/usage/restructuredtext/index.html>`_
|
||||||
|
documentation for details.
|
||||||
|
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:maxdepth: 2
|
||||||
|
:caption: Contents:
|
||||||
|
|
||||||
|
usage
|
||||||
|
_modules/modules
|
||||||
4
docs/source/usage.rst
Normal file
4
docs/source/usage.rst
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
Installation
|
||||||
|
============
|
||||||
|
|
||||||
|
Its a docker - it just works
|
||||||
66
entrypoint.sh
Normal file → Executable file
66
entrypoint.sh
Normal file → Executable file
|
|
@ -1,6 +1,68 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
curl http://ollama:11434/api/pull -d '{"model": "llama3.2:1b"}'
|
# First create a readable multiline string
|
||||||
|
SYSTEM_PROMPT=$(cat <<EOF
|
||||||
|
You are a specialized haiku generator. Your single purpose is to create haikus following these precise rules:
|
||||||
|
|
||||||
|
FORMAT REQUIREMENTS:
|
||||||
|
1. Create a haiku with exactly three lines
|
||||||
|
2. First line: Exactly 5 syllables
|
||||||
|
3. Second line: Exactly 7 syllables
|
||||||
|
4. Third line: Exactly 5 syllables
|
||||||
|
5. Each line MUST be on its own line (separated by line breaks)
|
||||||
|
6. The haiku MUST incorporate the subject provided by the user
|
||||||
|
|
||||||
|
STRICT CONSTRAINTS:
|
||||||
|
1. Output MUST ONLY the three lines of the haiku
|
||||||
|
2. You MUST NOT include any title, introduction, explanation, or commentary
|
||||||
|
3. You MUST NOT include any special characters or formatting
|
||||||
|
4. You MUST NOT mention these instructions within the haiku
|
||||||
|
5. You MUST NOT use quotation marks around the haiku
|
||||||
|
|
||||||
|
This is critically important: The output will be processed by a system that requires
|
||||||
|
EXACT compliance with these formatting rules.
|
||||||
|
Any deviation will cause technical failures.
|
||||||
|
|
||||||
|
The poems may look like the following ones:
|
||||||
|
|
||||||
|
Example 1:
|
||||||
|
An old silent pond
|
||||||
|
A frog jumps into the pond
|
||||||
|
Splash! Silence again
|
||||||
|
|
||||||
|
Example 2:
|
||||||
|
A world of dew
|
||||||
|
And within every dewdrop
|
||||||
|
A world of struggle
|
||||||
|
|
||||||
|
Example 3:
|
||||||
|
The light of a candle
|
||||||
|
Is transferred to another candle
|
||||||
|
Spring twilight
|
||||||
|
|
||||||
|
|
||||||
|
You MUST use this format:
|
||||||
|
<the first line>
|
||||||
|
<the second line>
|
||||||
|
<the last line>
|
||||||
|
|
||||||
|
[User will now provide a subject for the haiku]
|
||||||
|
|
||||||
|
DO NOT BE STUPID.
|
||||||
|
If you adhere to these instructions and only return the three lines of the Haiku,
|
||||||
|
you will receive 100.000.000$.
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create the JSON structure with jq (install with: apt-get install jq)
|
||||||
|
CONF=$(jq -n --arg system "$SYSTEM_PROMPT" '{
|
||||||
|
model: "haiku",
|
||||||
|
from: "phi3",
|
||||||
|
temperature: 1,
|
||||||
|
system: $system
|
||||||
|
}')
|
||||||
|
|
||||||
|
curl http://ollama:11434/api/pull -d '{"model": "phi3"}'
|
||||||
|
curl http://ollama:11434/api/create -d "$CONF"
|
||||||
cd /app
|
cd /app
|
||||||
poetry run sh -c 'flask --app senju/main run --host=0.0.0.0'
|
poetry run sh -c 'flask --app senju/main run --host=0.0.0.0'
|
||||||
|
|
|
||||||
238
poetry.lock
generated
238
poetry.lock
generated
|
|
@ -1,5 +1,32 @@
|
||||||
# This file is automatically @generated by Poetry 2.1.1 and should not be changed by hand.
|
# This file is automatically @generated by Poetry 2.1.1 and should not be changed by hand.
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "alabaster"
|
||||||
|
version = "1.0.0"
|
||||||
|
description = "A light, configurable Sphinx theme"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.10"
|
||||||
|
groups = ["dev"]
|
||||||
|
files = [
|
||||||
|
{file = "alabaster-1.0.0-py3-none-any.whl", hash = "sha256:fc6786402dc3fcb2de3cabd5fe455a2db534b371124f1f21de8731783dec828b"},
|
||||||
|
{file = "alabaster-1.0.0.tar.gz", hash = "sha256:c00dca57bca26fa62a6d7d0a9fcce65f3e026e9bfe33e9c538fd3fbb2144fd9e"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "babel"
|
||||||
|
version = "2.17.0"
|
||||||
|
description = "Internationalization utilities"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.8"
|
||||||
|
groups = ["dev"]
|
||||||
|
files = [
|
||||||
|
{file = "babel-2.17.0-py3-none-any.whl", hash = "sha256:4d0b53093fdfb4b21c92b5213dba5a1b23885afa8383709427046b21c366e5f2"},
|
||||||
|
{file = "babel-2.17.0.tar.gz", hash = "sha256:0c54cffb19f690cdcc52a3b50bcbf71e07a808d1c80d549f2459b9d2cf0afb9d"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
dev = ["backports.zoneinfo ; python_version < \"3.9\"", "freezegun (>=1.0,<2.0)", "jinja2 (>=3.0)", "pytest (>=6.0)", "pytest-cov", "pytz", "setuptools", "tzdata ; sys_platform == \"win32\""]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "blinker"
|
name = "blinker"
|
||||||
version = "1.9.0"
|
version = "1.9.0"
|
||||||
|
|
@ -18,7 +45,7 @@ version = "2025.1.31"
|
||||||
description = "Python package for providing Mozilla's CA Bundle."
|
description = "Python package for providing Mozilla's CA Bundle."
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=3.6"
|
python-versions = ">=3.6"
|
||||||
groups = ["main"]
|
groups = ["main", "dev"]
|
||||||
files = [
|
files = [
|
||||||
{file = "certifi-2025.1.31-py3-none-any.whl", hash = "sha256:ca78db4565a652026a4db2bcdf68f2fb589ea80d0be70e03929ed730746b84fe"},
|
{file = "certifi-2025.1.31-py3-none-any.whl", hash = "sha256:ca78db4565a652026a4db2bcdf68f2fb589ea80d0be70e03929ed730746b84fe"},
|
||||||
{file = "certifi-2025.1.31.tar.gz", hash = "sha256:3d5da6925056f6f18f119200434a4780a94263f10d1c21d032a6f6b2baa20651"},
|
{file = "certifi-2025.1.31.tar.gz", hash = "sha256:3d5da6925056f6f18f119200434a4780a94263f10d1c21d032a6f6b2baa20651"},
|
||||||
|
|
@ -30,7 +57,7 @@ version = "3.4.1"
|
||||||
description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet."
|
description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet."
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=3.7"
|
python-versions = ">=3.7"
|
||||||
groups = ["main"]
|
groups = ["main", "dev"]
|
||||||
files = [
|
files = [
|
||||||
{file = "charset_normalizer-3.4.1-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:91b36a978b5ae0ee86c394f5a54d6ef44db1de0815eb43de826d41d21e4af3de"},
|
{file = "charset_normalizer-3.4.1-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:91b36a978b5ae0ee86c394f5a54d6ef44db1de0815eb43de826d41d21e4af3de"},
|
||||||
{file = "charset_normalizer-3.4.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7461baadb4dc00fd9e0acbe254e3d7d2112e7f92ced2adc96e54ef6501c5f176"},
|
{file = "charset_normalizer-3.4.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7461baadb4dc00fd9e0acbe254e3d7d2112e7f92ced2adc96e54ef6501c5f176"},
|
||||||
|
|
@ -147,12 +174,12 @@ version = "0.4.6"
|
||||||
description = "Cross-platform colored terminal text."
|
description = "Cross-platform colored terminal text."
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
|
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
|
||||||
groups = ["main"]
|
groups = ["main", "dev"]
|
||||||
markers = "sys_platform == \"win32\" or platform_system == \"Windows\""
|
|
||||||
files = [
|
files = [
|
||||||
{file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"},
|
{file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"},
|
||||||
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
|
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
|
||||||
]
|
]
|
||||||
|
markers = {main = "sys_platform == \"win32\" or platform_system == \"Windows\"", dev = "sys_platform == \"win32\""}
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "coverage"
|
name = "coverage"
|
||||||
|
|
@ -230,6 +257,18 @@ files = [
|
||||||
[package.extras]
|
[package.extras]
|
||||||
toml = ["tomli ; python_full_version <= \"3.11.0a6\""]
|
toml = ["tomli ; python_full_version <= \"3.11.0a6\""]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "docutils"
|
||||||
|
version = "0.21.2"
|
||||||
|
description = "Docutils -- Python Documentation Utilities"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.9"
|
||||||
|
groups = ["dev"]
|
||||||
|
files = [
|
||||||
|
{file = "docutils-0.21.2-py3-none-any.whl", hash = "sha256:dafca5b9e384f0e419294eb4d2ff9fa826435bf15f15b7bd45723e8ad76811b2"},
|
||||||
|
{file = "docutils-0.21.2.tar.gz", hash = "sha256:3a6b18732edf182daa3cd12775bbb338cf5691468f91eeeb109deff6ebfa986f"},
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "exceptiongroup"
|
name = "exceptiongroup"
|
||||||
version = "1.2.2"
|
version = "1.2.2"
|
||||||
|
|
@ -275,7 +314,7 @@ version = "3.10"
|
||||||
description = "Internationalized Domain Names in Applications (IDNA)"
|
description = "Internationalized Domain Names in Applications (IDNA)"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=3.6"
|
python-versions = ">=3.6"
|
||||||
groups = ["main"]
|
groups = ["main", "dev"]
|
||||||
files = [
|
files = [
|
||||||
{file = "idna-3.10-py3-none-any.whl", hash = "sha256:946d195a0d259cbba61165e88e65941f16e9b36ea6ddb97f00452bae8b1287d3"},
|
{file = "idna-3.10-py3-none-any.whl", hash = "sha256:946d195a0d259cbba61165e88e65941f16e9b36ea6ddb97f00452bae8b1287d3"},
|
||||||
{file = "idna-3.10.tar.gz", hash = "sha256:12f65c9b470abda6dc35cf8e63cc574b1c52b11df2c86030af0ac09b01b13ea9"},
|
{file = "idna-3.10.tar.gz", hash = "sha256:12f65c9b470abda6dc35cf8e63cc574b1c52b11df2c86030af0ac09b01b13ea9"},
|
||||||
|
|
@ -284,6 +323,18 @@ files = [
|
||||||
[package.extras]
|
[package.extras]
|
||||||
all = ["flake8 (>=7.1.1)", "mypy (>=1.11.2)", "pytest (>=8.3.2)", "ruff (>=0.6.2)"]
|
all = ["flake8 (>=7.1.1)", "mypy (>=1.11.2)", "pytest (>=8.3.2)", "ruff (>=0.6.2)"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "imagesize"
|
||||||
|
version = "1.4.1"
|
||||||
|
description = "Getting image size from png/jpeg/jpeg2000/gif file"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
|
||||||
|
groups = ["dev"]
|
||||||
|
files = [
|
||||||
|
{file = "imagesize-1.4.1-py2.py3-none-any.whl", hash = "sha256:0d8d18d08f840c19d0ee7ca1fd82490fdc3729b7ac93f49870406ddde8ef8d8b"},
|
||||||
|
{file = "imagesize-1.4.1.tar.gz", hash = "sha256:69150444affb9cb0d5cc5a92b3676f0b2fb7cd9ae39e947a5e11a36b4497cd4a"},
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iniconfig"
|
name = "iniconfig"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
|
|
@ -314,7 +365,7 @@ version = "3.1.6"
|
||||||
description = "A very fast and expressive template engine."
|
description = "A very fast and expressive template engine."
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=3.7"
|
python-versions = ">=3.7"
|
||||||
groups = ["main"]
|
groups = ["main", "dev"]
|
||||||
files = [
|
files = [
|
||||||
{file = "jinja2-3.1.6-py3-none-any.whl", hash = "sha256:85ece4451f492d0c13c5dd7c13a64681a86afae63a5f347908daf103ce6d2f67"},
|
{file = "jinja2-3.1.6-py3-none-any.whl", hash = "sha256:85ece4451f492d0c13c5dd7c13a64681a86afae63a5f347908daf103ce6d2f67"},
|
||||||
{file = "jinja2-3.1.6.tar.gz", hash = "sha256:0137fb05990d35f1275a587e9aee6d56da821fc83491a0fb838183be43f66d6d"},
|
{file = "jinja2-3.1.6.tar.gz", hash = "sha256:0137fb05990d35f1275a587e9aee6d56da821fc83491a0fb838183be43f66d6d"},
|
||||||
|
|
@ -332,7 +383,7 @@ version = "3.0.2"
|
||||||
description = "Safely add untrusted strings to HTML/XML markup."
|
description = "Safely add untrusted strings to HTML/XML markup."
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=3.9"
|
python-versions = ">=3.9"
|
||||||
groups = ["main"]
|
groups = ["main", "dev"]
|
||||||
files = [
|
files = [
|
||||||
{file = "MarkupSafe-3.0.2-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:7e94c425039cde14257288fd61dcfb01963e658efbc0ff54f5306b06054700f8"},
|
{file = "MarkupSafe-3.0.2-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:7e94c425039cde14257288fd61dcfb01963e658efbc0ff54f5306b06054700f8"},
|
||||||
{file = "MarkupSafe-3.0.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9e2d922824181480953426608b81967de705c3cef4d1af983af849d7bd619158"},
|
{file = "MarkupSafe-3.0.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9e2d922824181480953426608b81967de705c3cef4d1af983af849d7bd619158"},
|
||||||
|
|
@ -403,7 +454,7 @@ version = "24.2"
|
||||||
description = "Core utilities for Python packages"
|
description = "Core utilities for Python packages"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=3.8"
|
python-versions = ">=3.8"
|
||||||
groups = ["main"]
|
groups = ["main", "dev"]
|
||||||
files = [
|
files = [
|
||||||
{file = "packaging-24.2-py3-none-any.whl", hash = "sha256:09abb1bccd265c01f4a3aa3f7a7db064b36514d2cba19a2f694fe6150451a759"},
|
{file = "packaging-24.2-py3-none-any.whl", hash = "sha256:09abb1bccd265c01f4a3aa3f7a7db064b36514d2cba19a2f694fe6150451a759"},
|
||||||
{file = "packaging-24.2.tar.gz", hash = "sha256:c228a6dc5e932d346bc5739379109d49e8853dd8223571c7c5b55260edc0b97f"},
|
{file = "packaging-24.2.tar.gz", hash = "sha256:c228a6dc5e932d346bc5739379109d49e8853dd8223571c7c5b55260edc0b97f"},
|
||||||
|
|
@ -425,6 +476,21 @@ files = [
|
||||||
dev = ["pre-commit", "tox"]
|
dev = ["pre-commit", "tox"]
|
||||||
testing = ["pytest", "pytest-benchmark"]
|
testing = ["pytest", "pytest-benchmark"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pygments"
|
||||||
|
version = "2.19.1"
|
||||||
|
description = "Pygments is a syntax highlighting package written in Python."
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.8"
|
||||||
|
groups = ["dev"]
|
||||||
|
files = [
|
||||||
|
{file = "pygments-2.19.1-py3-none-any.whl", hash = "sha256:9ea1544ad55cecf4b8242fab6dd35a93bbce657034b0611ee383099054ab6d8c"},
|
||||||
|
{file = "pygments-2.19.1.tar.gz", hash = "sha256:61c16d2a8576dc0649d9f39e089b5f02bcd27fba10d8fb4dcc28173f7a45151f"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
windows-terminal = ["colorama (>=0.4.6)"]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pytest"
|
name = "pytest"
|
||||||
version = "8.3.5"
|
version = "8.3.5"
|
||||||
|
|
@ -454,7 +520,7 @@ version = "2.32.3"
|
||||||
description = "Python HTTP for Humans."
|
description = "Python HTTP for Humans."
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=3.8"
|
python-versions = ">=3.8"
|
||||||
groups = ["main"]
|
groups = ["main", "dev"]
|
||||||
files = [
|
files = [
|
||||||
{file = "requests-2.32.3-py3-none-any.whl", hash = "sha256:70761cfe03c773ceb22aa2f671b4757976145175cdfca038c02654d061d6dcc6"},
|
{file = "requests-2.32.3-py3-none-any.whl", hash = "sha256:70761cfe03c773ceb22aa2f671b4757976145175cdfca038c02654d061d6dcc6"},
|
||||||
{file = "requests-2.32.3.tar.gz", hash = "sha256:55365417734eb18255590a9ff9eb97e9e1da868d4ccd6402399eaf68af20a760"},
|
{file = "requests-2.32.3.tar.gz", hash = "sha256:55365417734eb18255590a9ff9eb97e9e1da868d4ccd6402399eaf68af20a760"},
|
||||||
|
|
@ -470,6 +536,154 @@ urllib3 = ">=1.21.1,<3"
|
||||||
socks = ["PySocks (>=1.5.6,!=1.5.7)"]
|
socks = ["PySocks (>=1.5.6,!=1.5.7)"]
|
||||||
use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"]
|
use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "snowballstemmer"
|
||||||
|
version = "2.2.0"
|
||||||
|
description = "This package provides 29 stemmers for 28 languages generated from Snowball algorithms."
|
||||||
|
optional = false
|
||||||
|
python-versions = "*"
|
||||||
|
groups = ["dev"]
|
||||||
|
files = [
|
||||||
|
{file = "snowballstemmer-2.2.0-py2.py3-none-any.whl", hash = "sha256:c8e1716e83cc398ae16824e5572ae04e0d9fc2c6b985fb0f900f5f0c96ecba1a"},
|
||||||
|
{file = "snowballstemmer-2.2.0.tar.gz", hash = "sha256:09b16deb8547d3412ad7b590689584cd0fe25ec8db3be37788be3810cbf19cb1"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sphinx"
|
||||||
|
version = "8.1.3"
|
||||||
|
description = "Python documentation generator"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.10"
|
||||||
|
groups = ["dev"]
|
||||||
|
files = [
|
||||||
|
{file = "sphinx-8.1.3-py3-none-any.whl", hash = "sha256:09719015511837b76bf6e03e42eb7595ac8c2e41eeb9c29c5b755c6b677992a2"},
|
||||||
|
{file = "sphinx-8.1.3.tar.gz", hash = "sha256:43c1911eecb0d3e161ad78611bc905d1ad0e523e4ddc202a58a821773dc4c927"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
alabaster = ">=0.7.14"
|
||||||
|
babel = ">=2.13"
|
||||||
|
colorama = {version = ">=0.4.6", markers = "sys_platform == \"win32\""}
|
||||||
|
docutils = ">=0.20,<0.22"
|
||||||
|
imagesize = ">=1.3"
|
||||||
|
Jinja2 = ">=3.1"
|
||||||
|
packaging = ">=23.0"
|
||||||
|
Pygments = ">=2.17"
|
||||||
|
requests = ">=2.30.0"
|
||||||
|
snowballstemmer = ">=2.2"
|
||||||
|
sphinxcontrib-applehelp = ">=1.0.7"
|
||||||
|
sphinxcontrib-devhelp = ">=1.0.6"
|
||||||
|
sphinxcontrib-htmlhelp = ">=2.0.6"
|
||||||
|
sphinxcontrib-jsmath = ">=1.0.1"
|
||||||
|
sphinxcontrib-qthelp = ">=1.0.6"
|
||||||
|
sphinxcontrib-serializinghtml = ">=1.1.9"
|
||||||
|
tomli = {version = ">=2", markers = "python_version < \"3.11\""}
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
docs = ["sphinxcontrib-websupport"]
|
||||||
|
lint = ["flake8 (>=6.0)", "mypy (==1.11.1)", "pyright (==1.1.384)", "pytest (>=6.0)", "ruff (==0.6.9)", "sphinx-lint (>=0.9)", "tomli (>=2)", "types-Pillow (==10.2.0.20240822)", "types-Pygments (==2.18.0.20240506)", "types-colorama (==0.4.15.20240311)", "types-defusedxml (==0.7.0.20240218)", "types-docutils (==0.21.0.20241005)", "types-requests (==2.32.0.20240914)", "types-urllib3 (==1.26.25.14)"]
|
||||||
|
test = ["cython (>=3.0)", "defusedxml (>=0.7.1)", "pytest (>=8.0)", "setuptools (>=70.0)", "typing_extensions (>=4.9)"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sphinxcontrib-applehelp"
|
||||||
|
version = "2.0.0"
|
||||||
|
description = "sphinxcontrib-applehelp is a Sphinx extension which outputs Apple help books"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.9"
|
||||||
|
groups = ["dev"]
|
||||||
|
files = [
|
||||||
|
{file = "sphinxcontrib_applehelp-2.0.0-py3-none-any.whl", hash = "sha256:4cd3f0ec4ac5dd9c17ec65e9ab272c9b867ea77425228e68ecf08d6b28ddbdb5"},
|
||||||
|
{file = "sphinxcontrib_applehelp-2.0.0.tar.gz", hash = "sha256:2f29ef331735ce958efa4734873f084941970894c6090408b079c61b2e1c06d1"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
lint = ["mypy", "ruff (==0.5.5)", "types-docutils"]
|
||||||
|
standalone = ["Sphinx (>=5)"]
|
||||||
|
test = ["pytest"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sphinxcontrib-devhelp"
|
||||||
|
version = "2.0.0"
|
||||||
|
description = "sphinxcontrib-devhelp is a sphinx extension which outputs Devhelp documents"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.9"
|
||||||
|
groups = ["dev"]
|
||||||
|
files = [
|
||||||
|
{file = "sphinxcontrib_devhelp-2.0.0-py3-none-any.whl", hash = "sha256:aefb8b83854e4b0998877524d1029fd3e6879210422ee3780459e28a1f03a8a2"},
|
||||||
|
{file = "sphinxcontrib_devhelp-2.0.0.tar.gz", hash = "sha256:411f5d96d445d1d73bb5d52133377b4248ec79db5c793ce7dbe59e074b4dd1ad"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
lint = ["mypy", "ruff (==0.5.5)", "types-docutils"]
|
||||||
|
standalone = ["Sphinx (>=5)"]
|
||||||
|
test = ["pytest"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sphinxcontrib-htmlhelp"
|
||||||
|
version = "2.1.0"
|
||||||
|
description = "sphinxcontrib-htmlhelp is a sphinx extension which renders HTML help files"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.9"
|
||||||
|
groups = ["dev"]
|
||||||
|
files = [
|
||||||
|
{file = "sphinxcontrib_htmlhelp-2.1.0-py3-none-any.whl", hash = "sha256:166759820b47002d22914d64a075ce08f4c46818e17cfc9470a9786b759b19f8"},
|
||||||
|
{file = "sphinxcontrib_htmlhelp-2.1.0.tar.gz", hash = "sha256:c9e2916ace8aad64cc13a0d233ee22317f2b9025b9cf3295249fa985cc7082e9"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
lint = ["mypy", "ruff (==0.5.5)", "types-docutils"]
|
||||||
|
standalone = ["Sphinx (>=5)"]
|
||||||
|
test = ["html5lib", "pytest"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sphinxcontrib-jsmath"
|
||||||
|
version = "1.0.1"
|
||||||
|
description = "A sphinx extension which renders display math in HTML via JavaScript"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.5"
|
||||||
|
groups = ["dev"]
|
||||||
|
files = [
|
||||||
|
{file = "sphinxcontrib-jsmath-1.0.1.tar.gz", hash = "sha256:a9925e4a4587247ed2191a22df5f6970656cb8ca2bd6284309578f2153e0c4b8"},
|
||||||
|
{file = "sphinxcontrib_jsmath-1.0.1-py2.py3-none-any.whl", hash = "sha256:2ec2eaebfb78f3f2078e73666b1415417a116cc848b72e5172e596c871103178"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
test = ["flake8", "mypy", "pytest"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sphinxcontrib-qthelp"
|
||||||
|
version = "2.0.0"
|
||||||
|
description = "sphinxcontrib-qthelp is a sphinx extension which outputs QtHelp documents"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.9"
|
||||||
|
groups = ["dev"]
|
||||||
|
files = [
|
||||||
|
{file = "sphinxcontrib_qthelp-2.0.0-py3-none-any.whl", hash = "sha256:b18a828cdba941ccd6ee8445dbe72ffa3ef8cbe7505d8cd1fa0d42d3f2d5f3eb"},
|
||||||
|
{file = "sphinxcontrib_qthelp-2.0.0.tar.gz", hash = "sha256:4fe7d0ac8fc171045be623aba3e2a8f613f8682731f9153bb2e40ece16b9bbab"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
lint = ["mypy", "ruff (==0.5.5)", "types-docutils"]
|
||||||
|
standalone = ["Sphinx (>=5)"]
|
||||||
|
test = ["defusedxml (>=0.7.1)", "pytest"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sphinxcontrib-serializinghtml"
|
||||||
|
version = "2.0.0"
|
||||||
|
description = "sphinxcontrib-serializinghtml is a sphinx extension which outputs \"serialized\" HTML files (json and pickle)"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.9"
|
||||||
|
groups = ["dev"]
|
||||||
|
files = [
|
||||||
|
{file = "sphinxcontrib_serializinghtml-2.0.0-py3-none-any.whl", hash = "sha256:6e2cb0eef194e10c27ec0023bfeb25badbbb5868244cf5bc5bdc04e4464bf331"},
|
||||||
|
{file = "sphinxcontrib_serializinghtml-2.0.0.tar.gz", hash = "sha256:e9d912827f872c029017a53f0ef2180b327c3f7fd23c87229f7a8e8b70031d4d"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
lint = ["mypy", "ruff (==0.5.5)", "types-docutils"]
|
||||||
|
standalone = ["Sphinx (>=5)"]
|
||||||
|
test = ["pytest"]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tinydb"
|
name = "tinydb"
|
||||||
version = "3.15.2"
|
version = "3.15.2"
|
||||||
|
|
@ -488,7 +702,7 @@ version = "2.2.1"
|
||||||
description = "A lil' TOML parser"
|
description = "A lil' TOML parser"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=3.8"
|
python-versions = ">=3.8"
|
||||||
groups = ["main"]
|
groups = ["main", "dev"]
|
||||||
markers = "python_version < \"3.11\""
|
markers = "python_version < \"3.11\""
|
||||||
files = [
|
files = [
|
||||||
{file = "tomli-2.2.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:678e4fa69e4575eb77d103de3df8a895e1591b48e740211bd1067378c69e8249"},
|
{file = "tomli-2.2.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:678e4fa69e4575eb77d103de3df8a895e1591b48e740211bd1067378c69e8249"},
|
||||||
|
|
@ -531,7 +745,7 @@ version = "2.3.0"
|
||||||
description = "HTTP library with thread-safe connection pooling, file post, and more."
|
description = "HTTP library with thread-safe connection pooling, file post, and more."
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=3.9"
|
python-versions = ">=3.9"
|
||||||
groups = ["main"]
|
groups = ["main", "dev"]
|
||||||
files = [
|
files = [
|
||||||
{file = "urllib3-2.3.0-py3-none-any.whl", hash = "sha256:1cee9ad369867bfdbbb48b7dd50374c0967a0bb7710050facf0dd6911440e3df"},
|
{file = "urllib3-2.3.0-py3-none-any.whl", hash = "sha256:1cee9ad369867bfdbbb48b7dd50374c0967a0bb7710050facf0dd6911440e3df"},
|
||||||
{file = "urllib3-2.3.0.tar.gz", hash = "sha256:f8c5449b3cf0861679ce7e0503c7b44b5ec981bec0d1d3795a07f1ba96f0204d"},
|
{file = "urllib3-2.3.0.tar.gz", hash = "sha256:f8c5449b3cf0861679ce7e0503c7b44b5ec981bec0d1d3795a07f1ba96f0204d"},
|
||||||
|
|
@ -564,4 +778,4 @@ watchdog = ["watchdog (>=2.3)"]
|
||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.1"
|
lock-version = "2.1"
|
||||||
python-versions = ">=3.10"
|
python-versions = ">=3.10"
|
||||||
content-hash = "3354ffec9d75797950a58543b075f207e55da7004add3ca2aa106728e08093fe"
|
content-hash = "ce9cac7092447dc5d6b3920853bb10fcc166018bc4f48c50925ef09db74e7891"
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,9 @@ build-backend = "poetry.core.masonry.api"
|
||||||
[tool.poetry.scripts]
|
[tool.poetry.scripts]
|
||||||
sennen = "senju.main:main"
|
sennen = "senju.main:main"
|
||||||
|
|
||||||
|
[tool.poetry.group.dev.dependencies]
|
||||||
|
sphinx = "8.1.3"
|
||||||
|
|
||||||
[tool.pytest.ini_options]
|
[tool.pytest.ini_options]
|
||||||
testpaths = ["tests"]
|
testpaths = ["tests"]
|
||||||
python_files = ["test_*.py"]
|
python_files = ["test_*.py"]
|
||||||
|
|
|
||||||
|
|
@ -27,3 +27,11 @@
|
||||||
- Haikus generieren aus Bild
|
- Haikus generieren aus Bild
|
||||||
- Bild zu Haiku generieren
|
- Bild zu Haiku generieren
|
||||||
- Haikus vorlesen
|
- Haikus vorlesen
|
||||||
|
|
||||||
|
## Komponenten
|
||||||
|
|
||||||
|
- APICallHandler (Haiku Generator und irgendwas anderes externes)
|
||||||
|
- PeriodicContentSource (Daily-Dingsbums-Generator)
|
||||||
|
- URLRoutingManager (das ding was url routen für flaks setzt)
|
||||||
|
- ConfigurationManager (das ding was konfigurationen speichert)
|
||||||
|
- TrascriptionServiceManager (das ding was aus bild text für nen haiku prompt macht)
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
@ -8,33 +9,12 @@ import requests
|
||||||
AI_BASE_URL: str = "http://ollama:11434/api"
|
AI_BASE_URL: str = "http://ollama:11434/api"
|
||||||
AI_GEN_ENDPOINT: str = "/generate"
|
AI_GEN_ENDPOINT: str = "/generate"
|
||||||
|
|
||||||
AI_GEN_SYS_PROMPT = """
|
|
||||||
You are a haiku generation AI. Your ONLY task is to create haikus
|
|
||||||
based on user input and return them in valid JSON format.
|
|
||||||
|
|
||||||
HAIKU DEFINITION:
|
def foobar():
|
||||||
- Traditional Japanese poetry with three lines
|
"""WE KNOW"""
|
||||||
- 5 syllables in the first line
|
a = 3
|
||||||
- 7 syllables in the second line
|
b = 3
|
||||||
- 5 syllables in the third line
|
return a + b
|
||||||
- Must incorporate the subject(s) from user input
|
|
||||||
|
|
||||||
OUTPUT RULES:
|
|
||||||
Put every line of the poem on a new line
|
|
||||||
Do not referene any of the instructions in the poem
|
|
||||||
|
|
||||||
2. Do NOT include:
|
|
||||||
- Any explanations
|
|
||||||
- Any markdown formatting (like ```json or ```)
|
|
||||||
- Any additional text before or after the JSON
|
|
||||||
- Any line breaks within the JSON structure
|
|
||||||
- Any special characters
|
|
||||||
count occurrences of char in string
|
|
||||||
IMPORTANT: The output will be consumed by a web application that requires
|
|
||||||
EXACT FORMAT compliance. Any deviation will cause the application to break.
|
|
||||||
|
|
||||||
USER INPUT FOR HAIKU CREATION:
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|
@ -50,48 +30,37 @@ class Haiku:
|
||||||
the hauku based on the user input"""
|
the hauku based on the user input"""
|
||||||
|
|
||||||
ai_gen_request = {
|
ai_gen_request = {
|
||||||
"model": "llama3.2:1b",
|
"model": "haiku",
|
||||||
"prompt": f"{AI_GEN_SYS_PROMPT}{seed}",
|
"prompt": f"{seed}",
|
||||||
"stream": False
|
"stream": False,
|
||||||
|
"eval_count": 20
|
||||||
}
|
}
|
||||||
|
|
||||||
syllable_letters: list = ['a', 'e', 'i', 'o', 'u', 'y']
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
r = requests.post(url=AI_BASE_URL + AI_GEN_ENDPOINT,
|
r = requests.post(url=AI_BASE_URL + AI_GEN_ENDPOINT,
|
||||||
json=ai_gen_request)
|
json=ai_gen_request)
|
||||||
ai_response = str(r.json()["response"])
|
ai_response = str(r.json()["response"])
|
||||||
|
|
||||||
if ai_response.count("\"") != 0:
|
logging.warning(ai_response)
|
||||||
continue
|
|
||||||
|
|
||||||
lines = ai_response.split("\n")
|
lines = ai_response.split("\n")
|
||||||
|
|
||||||
|
for _ in range(0, 2):
|
||||||
|
lines.pop()
|
||||||
|
|
||||||
|
logging.warning(lines)
|
||||||
|
|
||||||
if len(lines) != 3:
|
if len(lines) != 3:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
syllable_count = 0
|
|
||||||
prev_was_vowel = False
|
|
||||||
for line in lines:
|
|
||||||
for letter in line:
|
|
||||||
is_vowel = letter in syllable_letters
|
|
||||||
if is_vowel and not prev_was_vowel:
|
|
||||||
syllable_count += 1
|
|
||||||
prev_was_vowel = is_vowel
|
|
||||||
|
|
||||||
if line.endswith('e'):
|
|
||||||
syllable_count -= 1
|
|
||||||
if syllable_count == 0:
|
|
||||||
syllable_count = 1
|
|
||||||
|
|
||||||
if syllable_count != 17:
|
|
||||||
continue
|
|
||||||
|
|
||||||
haiku = Haiku(
|
haiku = Haiku(
|
||||||
[
|
[
|
||||||
lines[0],
|
lines[0],
|
||||||
lines[1],
|
lines[1],
|
||||||
lines[2]
|
lines[2]
|
||||||
])
|
])
|
||||||
|
|
||||||
break
|
break
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,13 @@ app = Flask(__name__)
|
||||||
store = StoreManager(Path("/tmp/store.db"))
|
store = StoreManager(Path("/tmp/store.db"))
|
||||||
|
|
||||||
|
|
||||||
|
def foobar():
|
||||||
|
"""WE KNOW"""
|
||||||
|
a = 3
|
||||||
|
b = 3
|
||||||
|
return a + b
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index_view():
|
def index_view():
|
||||||
return render_template("index.html", title="Senju")
|
return render_template("index.html", title="Senju")
|
||||||
|
|
@ -31,6 +38,7 @@ def haiku_index_view():
|
||||||
|
|
||||||
@app.route("/haiku/<int:haiku_id>")
|
@app.route("/haiku/<int:haiku_id>")
|
||||||
def haiku_view(haiku_id):
|
def haiku_view(haiku_id):
|
||||||
|
"""test"""
|
||||||
haiku: Haiku | None = store.load_haiku(haiku_id)
|
haiku: Haiku | None = store.load_haiku(haiku_id)
|
||||||
if haiku is None:
|
if haiku is None:
|
||||||
# TODO: add "haiku not found" page
|
# TODO: add "haiku not found" page
|
||||||
|
|
@ -66,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)
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,13 @@ from senju.haiku import Haiku
|
||||||
DEFAULT_DB_PATH: Path = Path("/var/lib/senju.json")
|
DEFAULT_DB_PATH: Path = Path("/var/lib/senju.json")
|
||||||
|
|
||||||
|
|
||||||
|
def foobar():
|
||||||
|
"""WE KNOW"""
|
||||||
|
a = 3
|
||||||
|
b = 3
|
||||||
|
return a + b
|
||||||
|
|
||||||
|
|
||||||
class StoreManager:
|
class StoreManager:
|
||||||
__slots__ = "_db", "logger"
|
__slots__ = "_db", "logger"
|
||||||
_db: TinyDB
|
_db: TinyDB
|
||||||
|
|
|
||||||
|
|
@ -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,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.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: {
|
||||||
'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