mirror of
https://github.com/senju1337/senju.git
synced 2025-12-24 07:39:29 +00:00
docs: Add docstrings for the haiku class
Refs: OPS-68
This commit is contained in:
parent
1022baa886
commit
3c3cf80aaf
1 changed files with 30 additions and 2 deletions
|
|
@ -19,15 +19,43 @@ def foobar():
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Haiku:
|
class Haiku:
|
||||||
|
"""
|
||||||
|
A class representing a haiku poem with three lines.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
lines (list[str]): A list containing the three lines of the haiku.
|
||||||
|
"""
|
||||||
lines: list[str]
|
lines: list[str]
|
||||||
|
|
||||||
def get_json(self):
|
def get_json(self):
|
||||||
|
"""
|
||||||
|
Converts the haiku lines to a JSON string.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: A JSON string representation of the haiku lines.
|
||||||
|
"""
|
||||||
return json.dumps(self.lines)
|
return json.dumps(self.lines)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def request_haiku(seed: str) -> Haiku:
|
def request_haiku(seed: str) -> Haiku:
|
||||||
"""This function prompts the ai to generate
|
"""
|
||||||
the hauku based on the user input"""
|
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.
|
||||||
|
It validates that the response:
|
||||||
|
- Contains exactly 3 lines
|
||||||
|
|
||||||
|
The function will retry until a valid haiku is generated.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
seed (str): The input text used to inspire the haiku generation.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Haiku: A new Haiku object containing the generated three lines.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
Possible JSONDecodeError which is caught and handled with retries.
|
||||||
|
"""
|
||||||
|
|
||||||
ai_gen_request = {
|
ai_gen_request = {
|
||||||
"model": "haiku",
|
"model": "haiku",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue