basejenerator 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Warren Davies
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,51 @@
1
+ Metadata-Version: 2.4
2
+ Name: basejenerator
3
+ Version: 0.1.0
4
+ Summary: Abstract base class and return formats for AI Generator classes within the Jeneratorverse.
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Author: Warren Davies
8
+ Requires-Python: >=3.10,<3.15
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Project-URL: Homepage, https://github.com/WarrenDavies/base-jenerator
17
+ Project-URL: Repository, https://github.com/WarrenDavies/base-jenerator
18
+ Description-Content-Type: text/markdown
19
+
20
+ # Base Jenerator
21
+
22
+ Abstract base class and return formats for AI Generator classes within the Jeneratorverse, providing a unified API across different media formats.
23
+
24
+ The idea is, whether you're running Stable Diffusion 1.5 with imagejenerator, or Llama 3.2 with textjenerator, you'll always call the same methods, and get outputs returned to you in the same format.
25
+
26
+ ## BaseGenerator class
27
+
28
+ Contract for generator classes that run model inference.
29
+
30
+ Abstract methods that must be implmented by subclasses are:
31
+
32
+ * `load`: load the model into memory, and assign the pipeline/model/engine to `self.model`.
33
+ * `prepare`: Reset lifecycle without tearing down the model - e.g., reset torch generators, clear cache, etc.
34
+ * `generate`: The public method that is called to run inference.
35
+ * `generate_impl`: Subclasses must implement this to run inference. Called by `.generate()`.
36
+ * `_quick_wrap`: Helper for subclasses to wrap artifacts into the Artfact class.
37
+ * `teardown`: Purge the model from memory, empty cache, run garbage collector, etc.
38
+
39
+ ## GeneratorOutput
40
+
41
+ Wrapper for artifacts generated. Will always return artifacts in a list in the `.artifacts` attribute, even for pipelines that return a single artifact (e.g., LLMs, non-batch image generation, etc.). Generation level metadata can be returned in `.extras`, however you should reserve this for things really cannot be captured anywhere else. The generator classes are meant to be stateless, besides the model/pipline.
42
+
43
+ They are like toasters - prompt in, artifact out.
44
+
45
+ ## Artifact
46
+
47
+ Represents a single artifact created by the generator. One image, text response, wav file, or whatever.
48
+
49
+ As with GeneratorOutput you can bundle metadata into `.item_extras` but again, I recommend leaving that responsibility to the calling app.
50
+
51
+
@@ -0,0 +1,31 @@
1
+ # Base Jenerator
2
+
3
+ Abstract base class and return formats for AI Generator classes within the Jeneratorverse, providing a unified API across different media formats.
4
+
5
+ The idea is, whether you're running Stable Diffusion 1.5 with imagejenerator, or Llama 3.2 with textjenerator, you'll always call the same methods, and get outputs returned to you in the same format.
6
+
7
+ ## BaseGenerator class
8
+
9
+ Contract for generator classes that run model inference.
10
+
11
+ Abstract methods that must be implmented by subclasses are:
12
+
13
+ * `load`: load the model into memory, and assign the pipeline/model/engine to `self.model`.
14
+ * `prepare`: Reset lifecycle without tearing down the model - e.g., reset torch generators, clear cache, etc.
15
+ * `generate`: The public method that is called to run inference.
16
+ * `generate_impl`: Subclasses must implement this to run inference. Called by `.generate()`.
17
+ * `_quick_wrap`: Helper for subclasses to wrap artifacts into the Artfact class.
18
+ * `teardown`: Purge the model from memory, empty cache, run garbage collector, etc.
19
+
20
+ ## GeneratorOutput
21
+
22
+ Wrapper for artifacts generated. Will always return artifacts in a list in the `.artifacts` attribute, even for pipelines that return a single artifact (e.g., LLMs, non-batch image generation, etc.). Generation level metadata can be returned in `.extras`, however you should reserve this for things really cannot be captured anywhere else. The generator classes are meant to be stateless, besides the model/pipline.
23
+
24
+ They are like toasters - prompt in, artifact out.
25
+
26
+ ## Artifact
27
+
28
+ Represents a single artifact created by the generator. One image, text response, wav file, or whatever.
29
+
30
+ As with GeneratorOutput you can bundle metadata into `.item_extras` but again, I recommend leaving that responsibility to the calling app.
31
+
@@ -0,0 +1,19 @@
1
+ [tool.poetry]
2
+ name = "basejenerator"
3
+ version = "0.1.0"
4
+ description = "Abstract base class and return formats for AI Generator classes within the Jeneratorverse."
5
+ authors = ["Warren Davies"]
6
+ license = "MIT"
7
+ readme = "README.md"
8
+ homepage = "https://github.com/WarrenDavies/base-jenerator"
9
+ repository = "https://github.com/WarrenDavies/base-jenerator"
10
+ packages = [
11
+ { include = "basejenerator", from = "src" }
12
+ ]
13
+
14
+ [tool.poetry.dependencies]
15
+ python = ">=3.10,<3.15"
16
+
17
+ [build-system]
18
+ requires = ["poetry-core>=1.0.0"]
19
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,15 @@
1
+ from dataclasses import dataclass
2
+
3
+ @dataclass
4
+ class Artifact:
5
+ """
6
+ An individual item generated by a class within the Jenerator ecosystem.
7
+
8
+ Attributes:
9
+ data (any): E.g., PIL image from imagejenerator, string/dict from textjenerator, etc.
10
+ item_extras (dict): any additional metadata related to this artifact (e.g., seed, token count
11
+ if this is not derivable outside the generator itself, etc.)
12
+ """
13
+ data: Any
14
+ item_extras: dict = field(default_factory=dict)
15
+
@@ -0,0 +1,87 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import List, Dict, Any, Tuple
3
+
4
+ from basejenerator.generator_output import GeneratorOutput
5
+ from basejenerator.artifact import Artifact
6
+
7
+ class BaseGenerator(ABC):
8
+ """
9
+ Base class with common attributes and methods GenAI models locally.
10
+ """
11
+
12
+ def __init__(self, config: Dict[str, Any]):
13
+ """
14
+ Initializes the generator with a config dict.
15
+
16
+ Args:
17
+ config (dict): Configuration dictionary.
18
+ """
19
+ self.config = config
20
+ self.model = None
21
+
22
+
23
+ @abstractmethod
24
+ def load(self):
25
+ """
26
+ Abstract method to load the model into memory, and run any other initialisation
27
+ steps needed.
28
+
29
+ Subclasses must implement this to load the specific model and assign
30
+ it to `self.model`.
31
+ """
32
+ pass
33
+
34
+
35
+ @abstractmethod
36
+ def prepare(self):
37
+ """
38
+ Reset lifecycle without tearing down the model - e.g., reset torch generators,
39
+ clear cache, etc.
40
+ """
41
+ pass
42
+
43
+
44
+ def generate(self) -> GeneratorOutput:
45
+ """
46
+ The public API that runs inference.
47
+
48
+ Returns:
49
+ GeneratorOutput
50
+ """
51
+ artifacts, global_extras = self.generate_impl()
52
+
53
+ return GeneratorOutput(
54
+ batch=artifacts,
55
+ extras=global_extras
56
+ )
57
+
58
+
59
+ @abstractmethod
60
+ def generate_impl(self) -> Tuple[List[Artifact], Dict[str, Any]]:
61
+ """
62
+ Abstract method containing the core generation logic.
63
+
64
+ Subclasses must implement this to run the inference and return artifacts and params.
65
+
66
+ Returns:
67
+ artifacts (List[Artifact]): A list of Artifact objects containing the artifacts generated by the model
68
+ global_extras (Dict): Dictionary of any generation (i.e., not artifact specific) metadata
69
+ """
70
+ pass
71
+
72
+
73
+ def _quick_wrap(self, raw_data: list) -> List[Artifact]:
74
+ """
75
+ Helper for subclasses to wrap artifacts into the Artfact class.
76
+ """
77
+ return [Artifact(data=item, item_extras={}) for item in raw_data]
78
+
79
+
80
+ @abstractmethod
81
+ def teardown(self):
82
+ """
83
+ Purge the model from memory, empty cache, run garbage collector, etc.
84
+ Clears the slate to avoid bleed between inference runs.
85
+ """
86
+ pass
87
+
@@ -0,0 +1,11 @@
1
+ from dataclasses import dataclass
2
+
3
+ from basejenerator.artifact import Artifact
4
+
5
+ @dataclass
6
+ class GeneratorOutput:
7
+ """
8
+ Standardized return type for all GenAI pipelines within the Jenerator ecosystem
9
+ """
10
+ batch: List[Artifact]
11
+ extras: dict = field(default_factory=dict)