generative-redfoot 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.
- generative_redfoot-0.1.0/LICENSE +21 -0
- generative_redfoot-0.1.0/PKG-INFO +245 -0
- generative_redfoot-0.1.0/README.md +197 -0
- generative_redfoot-0.1.0/pyproject.toml +45 -0
- generative_redfoot-0.1.0/setup.cfg +4 -0
- generative_redfoot-0.1.0/src/generative_redfoot/__init__.py +1 -0
- generative_redfoot-0.1.0/src/generative_redfoot/cli.py +217 -0
- generative_redfoot-0.1.0/src/generative_redfoot/extensions/__init__.py +0 -0
- generative_redfoot-0.1.0/src/generative_redfoot/extensions/toolio.py +88 -0
- generative_redfoot-0.1.0/src/generative_redfoot/extensions/wordloom.py +64 -0
- generative_redfoot-0.1.0/src/generative_redfoot/object_pdl_model.py +489 -0
- generative_redfoot-0.1.0/src/generative_redfoot/utils.py +5 -0
- generative_redfoot-0.1.0/src/generative_redfoot.egg-info/PKG-INFO +245 -0
- generative_redfoot-0.1.0/src/generative_redfoot.egg-info/SOURCES.txt +17 -0
- generative_redfoot-0.1.0/src/generative_redfoot.egg-info/dependency_links.txt +1 -0
- generative_redfoot-0.1.0/src/generative_redfoot.egg-info/entry_points.txt +2 -0
- generative_redfoot-0.1.0/src/generative_redfoot.egg-info/requires.txt +11 -0
- generative_redfoot-0.1.0/src/generative_redfoot.egg-info/top_level.txt +1 -0
- generative_redfoot-0.1.0/tests/test_complex_input.py +46 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Chime Ogbuji
|
|
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,245 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: generative_redfoot
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A generative, conversational workflow and multi-agent system using PDL and mlx
|
|
5
|
+
Author-email: Chimezie Ogbuji <chimezie@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 Chime Ogbuji
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/chimezie/generative_redfoot
|
|
29
|
+
Project-URL: Repository, https://github.com/chimezie/generative_redfoot
|
|
30
|
+
Classifier: Development Status :: 4 - Beta
|
|
31
|
+
Classifier: Programming Language :: Python
|
|
32
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
33
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
34
|
+
Requires-Python: >=3.10
|
|
35
|
+
Description-Content-Type: text/markdown
|
|
36
|
+
License-File: LICENSE
|
|
37
|
+
Requires-Dist: pyaml
|
|
38
|
+
Requires-Dist: click
|
|
39
|
+
Requires-Dist: tqdm
|
|
40
|
+
Requires-Dist: ogbujipt
|
|
41
|
+
Requires-Dist: mlx>=0.26.3
|
|
42
|
+
Requires-Dist: mlx-lm>=0.26.0
|
|
43
|
+
Requires-Dist: pytest
|
|
44
|
+
Requires-Dist: transformers
|
|
45
|
+
Provides-Extra: gemma-aps
|
|
46
|
+
Requires-Dist: nltk; extra == "gemma-aps"
|
|
47
|
+
Dynamic: license-file
|
|
48
|
+
|
|
49
|
+
# Generative Redfoot
|
|
50
|
+
A generative, conversational workflow and multi-agent system using PDL and [mlx](https://github.com/ml-explore/mlx-examples/tree/main/llms)
|
|
51
|
+
|
|
52
|
+
Takes a minimal [Prompt Declaration Language (PDL)](https://github.com/IBM/prompt-declaration-language) file and generates a finite state generative machine
|
|
53
|
+
as Python objects for a subset of the PDL language. These objects (the "programs" in particular) can be executed.
|
|
54
|
+
|
|
55
|
+
It was mainly motivated by supporting this use case from the PDL documentation/paper:
|
|
56
|
+
|
|
57
|
+
<img src="animated_chatbot.gif" alt="Animated GIF of PDL chatbot."/>
|
|
58
|
+
|
|
59
|
+
The Model class can be extended and incorporated into how a dispatcher creates the PDL Python objects from a PDL file to incorporate the functionality for evaluating
|
|
60
|
+
the prompts against the models specified in PDL. This is done using any accumulated conversational context, prompts, and generation parameters (sampling parameters, for example),
|
|
61
|
+
(optionally) updating the context as the program execution continues and how mlx is used to implement the model loading and inference.
|
|
62
|
+
|
|
63
|
+
However, the language of the PDL file can be extended with additional custom functionality, and
|
|
64
|
+
other LLM systems can handle the evaluation.
|
|
65
|
+
|
|
66
|
+
## Usage
|
|
67
|
+
|
|
68
|
+
It depends on the PyYaml and click third-party Python libraries as well as mlx and can be run this way, where `document.pdl` is a PDL file.
|
|
69
|
+
```commandline
|
|
70
|
+
% Usage: generative_redfoot [OPTIONS] PDL_FILE
|
|
71
|
+
|
|
72
|
+
Options:
|
|
73
|
+
-t, --temperature FLOAT
|
|
74
|
+
-rp, --repetition-penalty FLOAT
|
|
75
|
+
The penalty factor for repeating tokens
|
|
76
|
+
(none if not used)
|
|
77
|
+
--top-k INTEGER Sampling top-k
|
|
78
|
+
--top-p INTEGER Sampling top-p
|
|
79
|
+
--max-tokens INTEGER Max tokens
|
|
80
|
+
--min-p FLOAT Sampling min-p
|
|
81
|
+
--verbose / --no-verbose
|
|
82
|
+
-v, --variables <TEXT TEXT>...
|
|
83
|
+
--help Show this message and exit.
|
|
84
|
+
|
|
85
|
+
generative_redfoot.py document.pdl
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The main argument is a PDL program (a YAML file), possibly with extensions of the language implemented by generative_redfoot.
|
|
89
|
+
|
|
90
|
+
You can also specify default values for sampling parameters for the LLM calls during the execution of the programs
|
|
91
|
+
using mlx.
|
|
92
|
+
|
|
93
|
+
The model _parameters_ directive in PDL can be used to specify the following mlx generation parameters: **temperature**, **top_k**, **min_p**, **max_tokens**, and **top_p**:
|
|
94
|
+
|
|
95
|
+
```yaml
|
|
96
|
+
description: ...
|
|
97
|
+
text:
|
|
98
|
+
- read:
|
|
99
|
+
message: |
|
|
100
|
+
What is your query?
|
|
101
|
+
contribute: [context]
|
|
102
|
+
- model: .. model ..
|
|
103
|
+
parameters:
|
|
104
|
+
temperature: 0.6
|
|
105
|
+
min_p: .03
|
|
106
|
+
max_tokens: 200
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Extensions
|
|
110
|
+
|
|
111
|
+
Generative Redfoot defines a number of extensions from PDL
|
|
112
|
+
|
|
113
|
+
### PDF Reading
|
|
114
|
+
|
|
115
|
+
The `PDF_read` block can be used (within a `text` block) to read content from a PDF file (uses and requires [PyPDF2](https://pypdf2.readthedocs.io/en/3.x/)).
|
|
116
|
+
You can specify where the text is constibuted to (the 'context' is the most common scenario). Below is an example
|
|
117
|
+
that reads PDF content from a run-time specified filename and uses it as context for a model evaluation:
|
|
118
|
+
|
|
119
|
+
```yaml
|
|
120
|
+
description: autocoding_from_pdf
|
|
121
|
+
text:
|
|
122
|
+
- text:
|
|
123
|
+
- PDF_read: { $context_file }
|
|
124
|
+
contribute: [context]
|
|
125
|
+
- |
|
|
126
|
+
|
|
127
|
+
Provide a list of the 5 ICD-10 codes mentioned in the document above
|
|
128
|
+
contribute: [context]
|
|
129
|
+
- model: mlx-community/medgemma-4b-it-4bit
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Toolio
|
|
133
|
+
|
|
134
|
+
[Toolio](https://github.com/OoriData/Toolio) can be used for structured output by specifying a `structured_output`
|
|
135
|
+
block like so (from [Toolio algebra tutor demo](https://github.com/OoriData/Toolio/blob/main/demo/algebra_tutor.py)):
|
|
136
|
+
|
|
137
|
+
```yaml
|
|
138
|
+
description: structured_output
|
|
139
|
+
text:
|
|
140
|
+
- structured_output: mlx-community/Llama-3.2-3B-Instruct-4bit
|
|
141
|
+
insert_schema: true
|
|
142
|
+
schema_file: ToolioGit/demo/algebra_tutor.schema.json
|
|
143
|
+
parameters:
|
|
144
|
+
temperature: 0.6
|
|
145
|
+
max_tokens: 512
|
|
146
|
+
input: |
|
|
147
|
+
solve 8x + 31 = 2. Your answer should be only JSON, according to this schema: #!JSON_SCHEMA!#"
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Beyond the approach above, its input can be specified in all the ways a PDL model can.
|
|
151
|
+
|
|
152
|
+
### Alpha One Reasoning
|
|
153
|
+
|
|
154
|
+
[AlphaOne (α)](https://alphaone-project.github.io/) reasoning modulation can be used with
|
|
155
|
+
a supported, reasoning model using [Alpha One MLX](https://github.com/chimezie/alpha-one-mlx) via providing
|
|
156
|
+
a `alpha_one` block within a model:
|
|
157
|
+
|
|
158
|
+
```yaml
|
|
159
|
+
description: alpha_one_reasoning
|
|
160
|
+
text:
|
|
161
|
+
- model: mlx-community/DeepSeek-R1-0528-Qwen3-8B-4bit-AWQ
|
|
162
|
+
parameters:
|
|
163
|
+
temperature: 0.6
|
|
164
|
+
max_tokens: 1200
|
|
165
|
+
repetition_penalty: 1.4
|
|
166
|
+
top_k: 20
|
|
167
|
+
top_p: 0.95
|
|
168
|
+
alpha_one:
|
|
169
|
+
thinking_token_length: 250
|
|
170
|
+
alpha: 1.4
|
|
171
|
+
wait_words: ["Wait"]
|
|
172
|
+
input: |
|
|
173
|
+
What question has an answer of "42?"
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
This algorithm scales the average thinking phase token length (specified by the `thinking_token_length` parameter and
|
|
177
|
+
with a default of 2,650) by the `alpha` parameter (which defaults to 1.4 per the paper). After
|
|
178
|
+
exiting this phase, it suppresses attempts to transition to slow thinking by replacing references to 'Wait' words
|
|
179
|
+
with the _"</think>"_ token. The specific list of these words can be provided via the `wait_words` parameter or the
|
|
180
|
+
defaults specified by alpha-one-mlx for each model type will be used.
|
|
181
|
+
|
|
182
|
+
### Prompt management via Wordloom
|
|
183
|
+
|
|
184
|
+
Prompt snippets can be loaded for use in a PDL file via a [word loom](https://github.com/OoriData/OgbujiPT/wiki/Word-Loom%3A-Format-%26-tools-for-managing-natural-language-for-AI-LLMs)
|
|
185
|
+
library, providing a clean separation of concerns between prompt language management, prompt construction, and
|
|
186
|
+
LLM workflow management and orchestration. This requires [OgbujiPT](https://github.com/OoriData/OgbujiPT) and below is
|
|
187
|
+
an example that constructs the system and user prompt from a word loom ([TOML](https://toml.io/en/)) file:
|
|
188
|
+
|
|
189
|
+
```yaml
|
|
190
|
+
description: wordloom_prompt_example
|
|
191
|
+
text:
|
|
192
|
+
- text:
|
|
193
|
+
- role: system
|
|
194
|
+
read_from_wordloom: prompt_library.toml
|
|
195
|
+
items: helpful_chatbot_system_prompt
|
|
196
|
+
contribute: [context]
|
|
197
|
+
- text:
|
|
198
|
+
- read_from_wordloom: prompt_library.toml
|
|
199
|
+
items: hello_prompt
|
|
200
|
+
contribute: [context]
|
|
201
|
+
- model: mlx-community/Llama-3.2-3B-Instruct-4bit
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
The `read_from_wordloom` block indicates the use of this extension mechanism and its value is a path to a Word loom.
|
|
205
|
+
|
|
206
|
+
The `items` parameter on the block is a space-separated list of language item names in the word loom. Their values are
|
|
207
|
+
joined together with `\n` and returned as a value for use (as an example from above) to construct the message for
|
|
208
|
+
conversations used by downstream PDL directives.
|
|
209
|
+
|
|
210
|
+
In the example above, the `helpful_chatbot_system_prompt` language item from the `prompt_library.toml` word loom is used
|
|
211
|
+
as the system prompt and the `hello_prompt` language item from the same file is used as the user prompt:
|
|
212
|
+
|
|
213
|
+
```JSON
|
|
214
|
+
[
|
|
215
|
+
{"role": "system", "content": ".. helpful_chatbot_system_prompt language item .. "},
|
|
216
|
+
{"role": "user", "content": ".. hello_prompt language item .. "}
|
|
217
|
+
]
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Caching
|
|
221
|
+
A PDL program can use mlx-lm's [Prompt caching](https://github.com/ml-explore/mlx-lm/blob/main/README.md#long-prompts-and-generations)
|
|
222
|
+
by specifying a top-level `cache` parameter at the top of the PDL document. If the value of this parameter is _'*'_,
|
|
223
|
+
then an internal, rotating K/V cache is used for the duration of the PDL evaluation for efficiency.
|
|
224
|
+
|
|
225
|
+
Otherwise, the value is expected to be the path to a previously saved cache, created using `mlx_lm.cache_prompt` for
|
|
226
|
+
example, which is treated as a cached prompt that is a prefix to any prompts specified in the program.
|
|
227
|
+
|
|
228
|
+
### Chain of Thought (CoT) prefix
|
|
229
|
+
If specified within a model block, the `cot_prefix` parameter takes a path to a file that captures COT few shot content
|
|
230
|
+
as a file in the [LLM chat conversation](https://model-spec.openai.com/2025-02-12.html#definitions) JSON format. This
|
|
231
|
+
will be incorporated into the conversation structure to ensure this files content is used as few shot / COT for the
|
|
232
|
+
model generation
|
|
233
|
+
|
|
234
|
+
## Complex example
|
|
235
|
+
|
|
236
|
+
Below is an example showing a PDL file constructing message contexts for prompts to chained LLM calls from fragments
|
|
237
|
+
in a [Wordloom](https://github.com/OoriData/OgbujiPT/wiki/Word-Loom%3A-Format-%26-tools-for-managing-natural-language-for-AI-LLMs)
|
|
238
|
+
library, providing a clean separation of concerns between prompt language management, prompt construction, and
|
|
239
|
+
LLM workflow management and orchestration. The keys in the YAML file in black use the PDL language. Those in
|
|
240
|
+
red are generative_redfoot extensions shown in order of appearance: (mlx) prefix caching, COT few-shot loading,
|
|
241
|
+
reading from a wordloom file, using Google's [__google/gemma-7b-aps-it__](https://huggingface.co/google/gemma-7b-aps-it)
|
|
242
|
+
model to perform ["abstractive proposition segmentation"](https://arxiv.org/abs/2406.19803) from LLM output,
|
|
243
|
+
etc.:
|
|
244
|
+
|
|
245
|
+
<img src="complex_pdl.png" alt="Animated GIF of PDL chatbot."/>
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# Generative Redfoot
|
|
2
|
+
A generative, conversational workflow and multi-agent system using PDL and [mlx](https://github.com/ml-explore/mlx-examples/tree/main/llms)
|
|
3
|
+
|
|
4
|
+
Takes a minimal [Prompt Declaration Language (PDL)](https://github.com/IBM/prompt-declaration-language) file and generates a finite state generative machine
|
|
5
|
+
as Python objects for a subset of the PDL language. These objects (the "programs" in particular) can be executed.
|
|
6
|
+
|
|
7
|
+
It was mainly motivated by supporting this use case from the PDL documentation/paper:
|
|
8
|
+
|
|
9
|
+
<img src="animated_chatbot.gif" alt="Animated GIF of PDL chatbot."/>
|
|
10
|
+
|
|
11
|
+
The Model class can be extended and incorporated into how a dispatcher creates the PDL Python objects from a PDL file to incorporate the functionality for evaluating
|
|
12
|
+
the prompts against the models specified in PDL. This is done using any accumulated conversational context, prompts, and generation parameters (sampling parameters, for example),
|
|
13
|
+
(optionally) updating the context as the program execution continues and how mlx is used to implement the model loading and inference.
|
|
14
|
+
|
|
15
|
+
However, the language of the PDL file can be extended with additional custom functionality, and
|
|
16
|
+
other LLM systems can handle the evaluation.
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
It depends on the PyYaml and click third-party Python libraries as well as mlx and can be run this way, where `document.pdl` is a PDL file.
|
|
21
|
+
```commandline
|
|
22
|
+
% Usage: generative_redfoot [OPTIONS] PDL_FILE
|
|
23
|
+
|
|
24
|
+
Options:
|
|
25
|
+
-t, --temperature FLOAT
|
|
26
|
+
-rp, --repetition-penalty FLOAT
|
|
27
|
+
The penalty factor for repeating tokens
|
|
28
|
+
(none if not used)
|
|
29
|
+
--top-k INTEGER Sampling top-k
|
|
30
|
+
--top-p INTEGER Sampling top-p
|
|
31
|
+
--max-tokens INTEGER Max tokens
|
|
32
|
+
--min-p FLOAT Sampling min-p
|
|
33
|
+
--verbose / --no-verbose
|
|
34
|
+
-v, --variables <TEXT TEXT>...
|
|
35
|
+
--help Show this message and exit.
|
|
36
|
+
|
|
37
|
+
generative_redfoot.py document.pdl
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The main argument is a PDL program (a YAML file), possibly with extensions of the language implemented by generative_redfoot.
|
|
41
|
+
|
|
42
|
+
You can also specify default values for sampling parameters for the LLM calls during the execution of the programs
|
|
43
|
+
using mlx.
|
|
44
|
+
|
|
45
|
+
The model _parameters_ directive in PDL can be used to specify the following mlx generation parameters: **temperature**, **top_k**, **min_p**, **max_tokens**, and **top_p**:
|
|
46
|
+
|
|
47
|
+
```yaml
|
|
48
|
+
description: ...
|
|
49
|
+
text:
|
|
50
|
+
- read:
|
|
51
|
+
message: |
|
|
52
|
+
What is your query?
|
|
53
|
+
contribute: [context]
|
|
54
|
+
- model: .. model ..
|
|
55
|
+
parameters:
|
|
56
|
+
temperature: 0.6
|
|
57
|
+
min_p: .03
|
|
58
|
+
max_tokens: 200
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Extensions
|
|
62
|
+
|
|
63
|
+
Generative Redfoot defines a number of extensions from PDL
|
|
64
|
+
|
|
65
|
+
### PDF Reading
|
|
66
|
+
|
|
67
|
+
The `PDF_read` block can be used (within a `text` block) to read content from a PDF file (uses and requires [PyPDF2](https://pypdf2.readthedocs.io/en/3.x/)).
|
|
68
|
+
You can specify where the text is constibuted to (the 'context' is the most common scenario). Below is an example
|
|
69
|
+
that reads PDF content from a run-time specified filename and uses it as context for a model evaluation:
|
|
70
|
+
|
|
71
|
+
```yaml
|
|
72
|
+
description: autocoding_from_pdf
|
|
73
|
+
text:
|
|
74
|
+
- text:
|
|
75
|
+
- PDF_read: { $context_file }
|
|
76
|
+
contribute: [context]
|
|
77
|
+
- |
|
|
78
|
+
|
|
79
|
+
Provide a list of the 5 ICD-10 codes mentioned in the document above
|
|
80
|
+
contribute: [context]
|
|
81
|
+
- model: mlx-community/medgemma-4b-it-4bit
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Toolio
|
|
85
|
+
|
|
86
|
+
[Toolio](https://github.com/OoriData/Toolio) can be used for structured output by specifying a `structured_output`
|
|
87
|
+
block like so (from [Toolio algebra tutor demo](https://github.com/OoriData/Toolio/blob/main/demo/algebra_tutor.py)):
|
|
88
|
+
|
|
89
|
+
```yaml
|
|
90
|
+
description: structured_output
|
|
91
|
+
text:
|
|
92
|
+
- structured_output: mlx-community/Llama-3.2-3B-Instruct-4bit
|
|
93
|
+
insert_schema: true
|
|
94
|
+
schema_file: ToolioGit/demo/algebra_tutor.schema.json
|
|
95
|
+
parameters:
|
|
96
|
+
temperature: 0.6
|
|
97
|
+
max_tokens: 512
|
|
98
|
+
input: |
|
|
99
|
+
solve 8x + 31 = 2. Your answer should be only JSON, according to this schema: #!JSON_SCHEMA!#"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Beyond the approach above, its input can be specified in all the ways a PDL model can.
|
|
103
|
+
|
|
104
|
+
### Alpha One Reasoning
|
|
105
|
+
|
|
106
|
+
[AlphaOne (α)](https://alphaone-project.github.io/) reasoning modulation can be used with
|
|
107
|
+
a supported, reasoning model using [Alpha One MLX](https://github.com/chimezie/alpha-one-mlx) via providing
|
|
108
|
+
a `alpha_one` block within a model:
|
|
109
|
+
|
|
110
|
+
```yaml
|
|
111
|
+
description: alpha_one_reasoning
|
|
112
|
+
text:
|
|
113
|
+
- model: mlx-community/DeepSeek-R1-0528-Qwen3-8B-4bit-AWQ
|
|
114
|
+
parameters:
|
|
115
|
+
temperature: 0.6
|
|
116
|
+
max_tokens: 1200
|
|
117
|
+
repetition_penalty: 1.4
|
|
118
|
+
top_k: 20
|
|
119
|
+
top_p: 0.95
|
|
120
|
+
alpha_one:
|
|
121
|
+
thinking_token_length: 250
|
|
122
|
+
alpha: 1.4
|
|
123
|
+
wait_words: ["Wait"]
|
|
124
|
+
input: |
|
|
125
|
+
What question has an answer of "42?"
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
This algorithm scales the average thinking phase token length (specified by the `thinking_token_length` parameter and
|
|
129
|
+
with a default of 2,650) by the `alpha` parameter (which defaults to 1.4 per the paper). After
|
|
130
|
+
exiting this phase, it suppresses attempts to transition to slow thinking by replacing references to 'Wait' words
|
|
131
|
+
with the _"</think>"_ token. The specific list of these words can be provided via the `wait_words` parameter or the
|
|
132
|
+
defaults specified by alpha-one-mlx for each model type will be used.
|
|
133
|
+
|
|
134
|
+
### Prompt management via Wordloom
|
|
135
|
+
|
|
136
|
+
Prompt snippets can be loaded for use in a PDL file via a [word loom](https://github.com/OoriData/OgbujiPT/wiki/Word-Loom%3A-Format-%26-tools-for-managing-natural-language-for-AI-LLMs)
|
|
137
|
+
library, providing a clean separation of concerns between prompt language management, prompt construction, and
|
|
138
|
+
LLM workflow management and orchestration. This requires [OgbujiPT](https://github.com/OoriData/OgbujiPT) and below is
|
|
139
|
+
an example that constructs the system and user prompt from a word loom ([TOML](https://toml.io/en/)) file:
|
|
140
|
+
|
|
141
|
+
```yaml
|
|
142
|
+
description: wordloom_prompt_example
|
|
143
|
+
text:
|
|
144
|
+
- text:
|
|
145
|
+
- role: system
|
|
146
|
+
read_from_wordloom: prompt_library.toml
|
|
147
|
+
items: helpful_chatbot_system_prompt
|
|
148
|
+
contribute: [context]
|
|
149
|
+
- text:
|
|
150
|
+
- read_from_wordloom: prompt_library.toml
|
|
151
|
+
items: hello_prompt
|
|
152
|
+
contribute: [context]
|
|
153
|
+
- model: mlx-community/Llama-3.2-3B-Instruct-4bit
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
The `read_from_wordloom` block indicates the use of this extension mechanism and its value is a path to a Word loom.
|
|
157
|
+
|
|
158
|
+
The `items` parameter on the block is a space-separated list of language item names in the word loom. Their values are
|
|
159
|
+
joined together with `\n` and returned as a value for use (as an example from above) to construct the message for
|
|
160
|
+
conversations used by downstream PDL directives.
|
|
161
|
+
|
|
162
|
+
In the example above, the `helpful_chatbot_system_prompt` language item from the `prompt_library.toml` word loom is used
|
|
163
|
+
as the system prompt and the `hello_prompt` language item from the same file is used as the user prompt:
|
|
164
|
+
|
|
165
|
+
```JSON
|
|
166
|
+
[
|
|
167
|
+
{"role": "system", "content": ".. helpful_chatbot_system_prompt language item .. "},
|
|
168
|
+
{"role": "user", "content": ".. hello_prompt language item .. "}
|
|
169
|
+
]
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Caching
|
|
173
|
+
A PDL program can use mlx-lm's [Prompt caching](https://github.com/ml-explore/mlx-lm/blob/main/README.md#long-prompts-and-generations)
|
|
174
|
+
by specifying a top-level `cache` parameter at the top of the PDL document. If the value of this parameter is _'*'_,
|
|
175
|
+
then an internal, rotating K/V cache is used for the duration of the PDL evaluation for efficiency.
|
|
176
|
+
|
|
177
|
+
Otherwise, the value is expected to be the path to a previously saved cache, created using `mlx_lm.cache_prompt` for
|
|
178
|
+
example, which is treated as a cached prompt that is a prefix to any prompts specified in the program.
|
|
179
|
+
|
|
180
|
+
### Chain of Thought (CoT) prefix
|
|
181
|
+
If specified within a model block, the `cot_prefix` parameter takes a path to a file that captures COT few shot content
|
|
182
|
+
as a file in the [LLM chat conversation](https://model-spec.openai.com/2025-02-12.html#definitions) JSON format. This
|
|
183
|
+
will be incorporated into the conversation structure to ensure this files content is used as few shot / COT for the
|
|
184
|
+
model generation
|
|
185
|
+
|
|
186
|
+
## Complex example
|
|
187
|
+
|
|
188
|
+
Below is an example showing a PDL file constructing message contexts for prompts to chained LLM calls from fragments
|
|
189
|
+
in a [Wordloom](https://github.com/OoriData/OgbujiPT/wiki/Word-Loom%3A-Format-%26-tools-for-managing-natural-language-for-AI-LLMs)
|
|
190
|
+
library, providing a clean separation of concerns between prompt language management, prompt construction, and
|
|
191
|
+
LLM workflow management and orchestration. The keys in the YAML file in black use the PDL language. Those in
|
|
192
|
+
red are generative_redfoot extensions shown in order of appearance: (mlx) prefix caching, COT few-shot loading,
|
|
193
|
+
reading from a wordloom file, using Google's [__google/gemma-7b-aps-it__](https://huggingface.co/google/gemma-7b-aps-it)
|
|
194
|
+
model to perform ["abstractive proposition segmentation"](https://arxiv.org/abs/2406.19803) from LLM output,
|
|
195
|
+
etc.:
|
|
196
|
+
|
|
197
|
+
<img src="complex_pdl.png" alt="Animated GIF of PDL chatbot."/>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=67.0.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "generative_redfoot"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
dependencies = [
|
|
9
|
+
"pyaml",
|
|
10
|
+
"click",
|
|
11
|
+
"tqdm",
|
|
12
|
+
"ogbujipt",
|
|
13
|
+
"mlx>=0.26.3",
|
|
14
|
+
"mlx-lm>=0.26.0",
|
|
15
|
+
"pytest",
|
|
16
|
+
"transformers"
|
|
17
|
+
]
|
|
18
|
+
description = "A generative, conversational workflow and multi-agent system using PDL and mlx"
|
|
19
|
+
readme = "README.md"
|
|
20
|
+
requires-python = ">=3.10"
|
|
21
|
+
license = {file = "LICENSE"}
|
|
22
|
+
keywords = []
|
|
23
|
+
authors = [
|
|
24
|
+
{ name = "Chimezie Ogbuji", email = "chimezie@gmail.com" }
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
classifiers = [
|
|
28
|
+
"Development Status :: 4 - Beta",
|
|
29
|
+
"Programming Language :: Python",
|
|
30
|
+
"Programming Language :: Python :: 3.11",
|
|
31
|
+
"Programming Language :: Python :: Implementation :: PyPy",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[tool.setuptools.packages.find]
|
|
35
|
+
where = ["src"]
|
|
36
|
+
|
|
37
|
+
[project.scripts]
|
|
38
|
+
generative_redfoot = "generative_redfoot.cli:main"
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Homepage = "https://github.com/chimezie/generative_redfoot"
|
|
42
|
+
Repository = "https://github.com/chimezie/generative_redfoot"
|
|
43
|
+
|
|
44
|
+
[project.optional-dependencies]
|
|
45
|
+
gemma_aps = ["nltk"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|