refactor: Change line length to apease flake8

Refs: OPS-68
This commit is contained in:
Alivecow 2025-03-23 18:09:57 +01:00
parent 2e3987ab8b
commit f17d29c39c
5 changed files with 59 additions and 29 deletions

1
.gitignore vendored
View file

@ -180,4 +180,3 @@ ollama
*.kate-swp
# sphinx rst files
docs/source/_modules

View file

@ -4,21 +4,27 @@ Haiku Generation Module
A client interface for AI-powered haiku poem generation.
This module provides the core functionality for communicating with an Ollama-based
AI service to generate three-line haiku poems. It handles the entire generation
process, from sending properly formatted requests to processing and validating
This module provides the core functionality for communicating
with an Ollama-based
AI service to generate three-line haiku poems. It handles the
entire generation
process, from sending properly formatted requests to processing
and validating
the returned poems.
Classes
-------
Haiku
A dataclass representation of a haiku poem, providing structure for storage,
A dataclass representation of a haiku poem, providing structure
for storage,
manipulation and serialization of poem data.
**Methods**:
* ``to_json()``: Converts a haiku instance to JSON format for API responses
* ``generate_haiku(seed_text)``: Creates a new haiku using the AI service
* ``to_json()``: Converts a haiku instance to JSON format for API
responses
* ``generate_haiku(seed_text)``: Creates a new haiku using
the AI service
Constants
---------
@ -40,7 +46,8 @@ Dependencies
Implementation Details
----------------------
The module implements a robust communication pattern with the AI service, including:
The module implements a robust communication pattern with the
AI service, including:
1. Proper request formatting with seed text integration
2. Multiple retry attempts for handling temporary service issues
@ -88,9 +95,11 @@ class Haiku:
@staticmethod
def request_haiku(seed: str) -> 'Haiku':
"""
Generates a haiku using an AI model based on the provided seed text.
Generates a haiku using an AI model based on the
provided seed text.
This function prompts the AI to generate a haiku based on the user input.
This function prompts the AI to generate a haiku based on the
user input.
It validates that the response contains exactly 3 lines.
The function will retry until a valid haiku is generated.
@ -99,7 +108,8 @@ class Haiku:
:return: A new Haiku object containing the generated three lines.
:rtype: Haiku
:raises: Possible JSONDecodeError which is caught and handled with retries.
:raises: Possible JSONDecodeError which is caught and handled
with retries.
"""
ai_gen_request = {
"model": "haiku",

View file

@ -4,8 +4,10 @@ Senju Haiku Web Application
A Flask-based web interface for generating, viewing, and managing haiku poetry.
This application provides a comprehensive interface between users and an AI-powered
haiku generation service, with persistent storage capabilities. Users can interact
This application provides a comprehensive interface between users
and an AI-powered
haiku generation service, with persistent storage capabilities.
Users can interact
with the system through both a web interface and a RESTful API.
Features
@ -13,13 +15,15 @@ Features
* **Landing page**: Welcome interface introducing users to the Senju service
* **Browsing interface**: Gallery-style viewing of previously generated haikus
* **Prompt interface**: Text input system for generating haikus from seed text
* **Image scanning**: Experimental interface for creating haikus from visual inputs
* **Image scanning**: Experimental interface for creating haikus
from visual inputs
* **RESTful API**: Programmatic access for integration with other services
Architecture
------------
The application implements a RESTful architecture using Flask's routing system
and template rendering. All user interactions are handled through clearly defined
and template rendering. All user interactions are handled through
clearly defined
routes, with appropriate error handling for exceptional cases.
Dependencies
@ -63,6 +67,7 @@ def index_view():
"""
return render_template("index.html", title="Senju")
@app.route("/haiku/")
def haiku_index_view():
"""
@ -77,6 +82,7 @@ def haiku_index_view():
haiku_id = 0
return redirect(url_for("haiku_view", haiku_id=haiku_id, is_default=1))
@app.route("/haiku/<int:haiku_id>")
def haiku_view(haiku_id):
"""
@ -107,6 +113,7 @@ def haiku_view(haiku_id):
context=context,
title="Haiku of the Day")
@app.route("/prompt")
def prompt_view():
"""
@ -120,6 +127,7 @@ def prompt_view():
title="Haiku generation"
)
@app.route("/scan")
def scan_view():
"""
@ -133,6 +141,7 @@ def scan_view():
title="Image scanning"
)
@app.route("/api/v1/haiku", methods=['POST'])
def generate_haiku():
"""
@ -157,6 +166,7 @@ def generate_haiku():
else:
return "Method not allowed", 405
@app.route('/favicon.ico')
def favicon():
"""

View file

@ -4,25 +4,30 @@ Senju Database Management Module
A database interaction layer for the Senju haiku management system.
This module implements a lightweight document database abstraction using TinyDB
for persistent storage of haiku poems. It provides a clean interface for storing,
This module implements a lightweight document database
abstraction using TinyDB
for persistent storage of haiku poems. It provides a
clean interface for storing,
retrieving, updating, and managing haiku entries in the system.
Classes
-------
StoreManager
The primary class responsible for all database operations. Handles connection
The primary class responsible for all database operations.
Handles connection
management, CRUD operations, and query capabilities for haiku data.
Functions
---------
utility_function
Provides simple arithmetic operations to support database functionalities.
Provides simple arithmetic operations to support
database functionalities.
Constants
---------
DEFAULT_DB_PATH
The default filesystem location for the TinyDB database file (/var/lib/senju.json).
The default filesystem location for the TinyDB database file
(/var/lib/senju.json).
Dependencies
------------
@ -38,7 +43,8 @@ Implementation Details
----------------------
The module uses TinyDB as its storage engine, providing a JSON-based document
storage solution that balances simplicity with functionality. The StoreManager
abstracts all database operations behind a clean API, handling connection lifecycle
abstracts all database operations behind a clean API,
handling connection lifecycle
and providing methods for common operations on haiku data.
"""
@ -67,9 +73,11 @@ class BadStoreManagerFileError(Exception):
class StoreManager:
"""
Manages the storage and retrieval of haiku data using TinyDB.
Manages the storage and retrieval of haiku
data using TinyDB.
This class provides an interface for saving and loading haikus from
This class provides an interface for saving and
loading haikus from
a TinyDB database file.
:ivar _db: Database instance for storing haiku data.
@ -85,7 +93,8 @@ class StoreManager:
"""
Initialize the StoreManager with a database path.
:param path_to_db: Path to the TinyDB database file. Defaults to DEFAULT_DB_PATH.
:param path_to_db: Path to the TinyDB database file.
Defaults to DEFAULT_DB_PATH.
:type path_to_db: Path, optional
:return: None
"""
@ -118,7 +127,8 @@ class StoreManager:
:rtype: Optional[dict]
.. note::
Logs a warning if document with specified ID is not found.
Logs a warning if document with specified
ID is not found.
"""
try:
return self._db.get(doc_id=id)
@ -169,7 +179,8 @@ class StoreManager:
"""
Get the ID of the most recently added haiku.
:return: The ID of the latest haiku if any exists, None otherwise.
:return: The ID of the latest haiku if any exists,
None otherwise.
:rtype: Optional[int]
.. note::