markdown-flow 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,246 @@
1
+ Metadata-Version: 2.4
2
+ Name: markdown-flow
3
+ Version: 0.1.0
4
+ Summary: An agent library designed to parse and process MarkdownFlow documents
5
+ Project-URL: Homepage, https://github.com/ai-shifu/markdown-flow-agent-py
6
+ Project-URL: Bug Tracker, https://github.com/ai-shifu/markdown-flow-agent-py/issues
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Intended Audience :: Developers
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
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+
17
+ # MarkdownFlow
18
+
19
+ A powerful Python library for parsing and processing specially formatted Markdown documents with LLM integration capabilities.
20
+
21
+ MarkdownFlow enables you to create interactive Markdown documents with custom syntax for user interactions, variable management, and seamless LLM integration.
22
+
23
+ ## ✨ Key Features
24
+
25
+ - **Interactive Syntax**: Support for 5 types of user interactions using `?[]` syntax
26
+ - **Variable System**: Dual variable formats (`{{var}}` and `%{{var}}`) for flexible content management
27
+ - **LLM Integration**: Built-in support for Large Language Model providers
28
+ - **Three-layer Parsing**: Robust parsing architecture for complex interaction formats
29
+ - **Multiple Processing Modes**: PROMPT_ONLY, COMPLETE, and STREAM modes
30
+ - **Block-based Structure**: Document segmentation using `---` separators
31
+
32
+ ## 🚀 Quick Start
33
+
34
+ ### Installation
35
+
36
+ ```bash
37
+ pip install markdownflow
38
+ ```
39
+
40
+ ### Basic Usage
41
+
42
+ ```python
43
+ from markdown_flow import MarkdownFlow, ProcessMode
44
+
45
+ # Your markdown document with interactive syntax
46
+ document = """
47
+ Hello {{name}}! Welcome to MarkdownFlow.
48
+
49
+ ---
50
+
51
+ ?[%{{user_choice}} Continue | Learn More | ...custom input]
52
+
53
+ ---
54
+
55
+ Based on your choice: %{{user_choice}}
56
+ Your next step is ready!
57
+ """
58
+
59
+ # Initialize with LLM provider
60
+ mf = MarkdownFlow(document, llm_provider=your_llm_provider)
61
+
62
+ # Extract variables
63
+ variables = mf.extract_variables()
64
+ print(variables) # ['name', 'user_choice']
65
+
66
+ # Process blocks
67
+ result = await mf.process(
68
+ block_index=0,
69
+ variables={'name': 'John'},
70
+ mode=ProcessMode.COMPLETE
71
+ )
72
+ ```
73
+
74
+ ## 📝 Interactive Syntax Reference
75
+
76
+ MarkdownFlow supports 5 types of interactions using `?[]` syntax:
77
+
78
+ ### 1. Text Input Only
79
+ ```markdown
80
+ ?[%{{variable}}...question text]
81
+ ?[%{{name}}] # Simple input without prompt
82
+ ```
83
+ User provides text input for variable assignment.
84
+
85
+ ### 2. Button Selection Only
86
+ ```markdown
87
+ ?[%{{choice}} Option1 | Option2 | Option3]
88
+ ?[%{{action}} Confirm//yes | Cancel//no] # With custom values
89
+ ```
90
+ User selects from predefined options.
91
+
92
+ ### 3. Buttons + Text Input Combined
93
+ ```markdown
94
+ ?[%{{variable}} Button1 | Button2 | ...custom input hint]
95
+ ```
96
+ User can either click buttons or provide text input.
97
+
98
+ ### 4. Button with Display/Value Separation
99
+ ```markdown
100
+ ?[%{{variable}} Display Text//actual_value | Another Option//option2]
101
+ ```
102
+ Buttons show display text but assign different values.
103
+
104
+ ### 5. Non-Assignment Buttons (Display Only)
105
+ ```markdown
106
+ ?[Continue]
107
+ ?[Continue | Cancel]
108
+ ```
109
+ Buttons for user interaction without variable assignment.
110
+
111
+ **Note**: `?[text](url)` format is treated as standard Markdown links, not interaction components.
112
+
113
+ ## 🔧 Variable System
114
+
115
+ MarkdownFlow supports two types of variables:
116
+
117
+ - **`{{variable}}`** - Regular variables: Replaced with actual values during processing
118
+ - **`%{{variable}}`** - Preserved variables: Kept in original format for LLM understanding
119
+
120
+ ```python
121
+ # Variable extraction and replacement
122
+ from markdown_flow import extract_variables_from_text, replace_variables_in_text
123
+
124
+ text = "Hello {{name}}, your status is %{{status}}"
125
+ variables = extract_variables_from_text(text)
126
+ # Returns: ['name', 'status']
127
+
128
+ replaced = replace_variables_in_text(text, {'name': 'John', 'status': 'active'})
129
+ # Returns: "Hello John, your status is %{{status}}"
130
+ ```
131
+
132
+ ## 🎮 Processing Modes
133
+
134
+ MarkdownFlow offers three processing modes:
135
+
136
+ ```python
137
+ from markdown_flow import ProcessMode
138
+
139
+ # Get built prompt without LLM call
140
+ prompt_result = await mf.process(0, mode=ProcessMode.PROMPT_ONLY)
141
+
142
+ # Full processing with LLM (non-streaming)
143
+ complete_result = await mf.process(0, mode=ProcessMode.COMPLETE)
144
+
145
+ # Streaming LLM processing
146
+ async for chunk in await mf.process(0, mode=ProcessMode.STREAM):
147
+ print(chunk.content)
148
+ ```
149
+
150
+ ## 🏗️ Core Components
151
+
152
+ ### MarkdownFlow Class
153
+ The main processing class with unified `process()` interface:
154
+
155
+ ```python
156
+ class MarkdownFlow:
157
+ async def process(
158
+ self,
159
+ block_index: int,
160
+ mode: ProcessMode = ProcessMode.COMPLETE,
161
+ variables: Optional[Dict[str, str]] = None,
162
+ user_input: Optional[str] = None,
163
+ ) -> Union[LLMResult, AsyncGenerator[LLMResult, None]]
164
+ ```
165
+
166
+ ### LLM Provider Integration
167
+ Implement the `LLMProvider` interface for custom LLM integration:
168
+
169
+ ```python
170
+ from markdown_flow import LLMProvider, LLMResult
171
+
172
+ class YourLLMProvider(LLMProvider):
173
+ async def generate_response(self, messages: List[Dict], **kwargs) -> LLMResult:
174
+ # Your LLM implementation
175
+ pass
176
+
177
+ async def generate_stream(self, messages: List[Dict], **kwargs):
178
+ # Your streaming implementation
179
+ pass
180
+ ```
181
+
182
+ ## 📖 Advanced Usage
183
+
184
+ ### Document Structure
185
+ ```markdown
186
+ # Document Title
187
+ This is regular content that will be processed.
188
+
189
+ ---
190
+
191
+ ?[%{{user_name}}...What's your name?]
192
+
193
+ ---
194
+
195
+ Hello %{{user_name}}! This block uses your input.
196
+
197
+ ---
198
+
199
+ ===Preserved Content===
200
+ This content is preserved as-is without processing.
201
+ ===
202
+ ```
203
+
204
+ ### Block Processing
205
+ ```python
206
+ # Get all blocks
207
+ blocks = mf.get_all_blocks()
208
+
209
+ for i, block in enumerate(blocks):
210
+ print(f"Block {i}: {block.block_type}")
211
+ if block.block_type == BlockType.INTERACTION:
212
+ # Process interaction
213
+ result = await mf.process(i, mode=ProcessMode.COMPLETE)
214
+ ```
215
+
216
+ ### Interaction Processing
217
+ ```python
218
+ # Process user interaction
219
+ interaction_result = await mf.process(
220
+ block_index=1, # interaction block index
221
+ user_input="user response",
222
+ mode=ProcessMode.COMPLETE
223
+ )
224
+ ```
225
+
226
+ ## 🤝 Contributing
227
+
228
+ We welcome contributions! Please see our [GitHub repository](https://github.com/ai-shifu/markdown-flow) for more information.
229
+
230
+ ## 📄 License
231
+
232
+ This project is licensed under the MIT License - see the LICENSE file for details.
233
+
234
+ ## 🔗 Links
235
+
236
+ - **Homepage**: https://github.com/ai-shifu/markdown-flow
237
+ - **Bug Tracker**: https://github.com/ai-shifu/markdown-flow/issues
238
+ - **Documentation**: Coming soon
239
+
240
+ ## 🏷️ Version
241
+
242
+ Current version: 0.1.0
243
+
244
+ ---
245
+
246
+ **MarkdownFlow** - Making interactive Markdown documents simple and powerful! 🚀
@@ -0,0 +1,230 @@
1
+ # MarkdownFlow
2
+
3
+ A powerful Python library for parsing and processing specially formatted Markdown documents with LLM integration capabilities.
4
+
5
+ MarkdownFlow enables you to create interactive Markdown documents with custom syntax for user interactions, variable management, and seamless LLM integration.
6
+
7
+ ## ✨ Key Features
8
+
9
+ - **Interactive Syntax**: Support for 5 types of user interactions using `?[]` syntax
10
+ - **Variable System**: Dual variable formats (`{{var}}` and `%{{var}}`) for flexible content management
11
+ - **LLM Integration**: Built-in support for Large Language Model providers
12
+ - **Three-layer Parsing**: Robust parsing architecture for complex interaction formats
13
+ - **Multiple Processing Modes**: PROMPT_ONLY, COMPLETE, and STREAM modes
14
+ - **Block-based Structure**: Document segmentation using `---` separators
15
+
16
+ ## 🚀 Quick Start
17
+
18
+ ### Installation
19
+
20
+ ```bash
21
+ pip install markdownflow
22
+ ```
23
+
24
+ ### Basic Usage
25
+
26
+ ```python
27
+ from markdown_flow import MarkdownFlow, ProcessMode
28
+
29
+ # Your markdown document with interactive syntax
30
+ document = """
31
+ Hello {{name}}! Welcome to MarkdownFlow.
32
+
33
+ ---
34
+
35
+ ?[%{{user_choice}} Continue | Learn More | ...custom input]
36
+
37
+ ---
38
+
39
+ Based on your choice: %{{user_choice}}
40
+ Your next step is ready!
41
+ """
42
+
43
+ # Initialize with LLM provider
44
+ mf = MarkdownFlow(document, llm_provider=your_llm_provider)
45
+
46
+ # Extract variables
47
+ variables = mf.extract_variables()
48
+ print(variables) # ['name', 'user_choice']
49
+
50
+ # Process blocks
51
+ result = await mf.process(
52
+ block_index=0,
53
+ variables={'name': 'John'},
54
+ mode=ProcessMode.COMPLETE
55
+ )
56
+ ```
57
+
58
+ ## 📝 Interactive Syntax Reference
59
+
60
+ MarkdownFlow supports 5 types of interactions using `?[]` syntax:
61
+
62
+ ### 1. Text Input Only
63
+ ```markdown
64
+ ?[%{{variable}}...question text]
65
+ ?[%{{name}}] # Simple input without prompt
66
+ ```
67
+ User provides text input for variable assignment.
68
+
69
+ ### 2. Button Selection Only
70
+ ```markdown
71
+ ?[%{{choice}} Option1 | Option2 | Option3]
72
+ ?[%{{action}} Confirm//yes | Cancel//no] # With custom values
73
+ ```
74
+ User selects from predefined options.
75
+
76
+ ### 3. Buttons + Text Input Combined
77
+ ```markdown
78
+ ?[%{{variable}} Button1 | Button2 | ...custom input hint]
79
+ ```
80
+ User can either click buttons or provide text input.
81
+
82
+ ### 4. Button with Display/Value Separation
83
+ ```markdown
84
+ ?[%{{variable}} Display Text//actual_value | Another Option//option2]
85
+ ```
86
+ Buttons show display text but assign different values.
87
+
88
+ ### 5. Non-Assignment Buttons (Display Only)
89
+ ```markdown
90
+ ?[Continue]
91
+ ?[Continue | Cancel]
92
+ ```
93
+ Buttons for user interaction without variable assignment.
94
+
95
+ **Note**: `?[text](url)` format is treated as standard Markdown links, not interaction components.
96
+
97
+ ## 🔧 Variable System
98
+
99
+ MarkdownFlow supports two types of variables:
100
+
101
+ - **`{{variable}}`** - Regular variables: Replaced with actual values during processing
102
+ - **`%{{variable}}`** - Preserved variables: Kept in original format for LLM understanding
103
+
104
+ ```python
105
+ # Variable extraction and replacement
106
+ from markdown_flow import extract_variables_from_text, replace_variables_in_text
107
+
108
+ text = "Hello {{name}}, your status is %{{status}}"
109
+ variables = extract_variables_from_text(text)
110
+ # Returns: ['name', 'status']
111
+
112
+ replaced = replace_variables_in_text(text, {'name': 'John', 'status': 'active'})
113
+ # Returns: "Hello John, your status is %{{status}}"
114
+ ```
115
+
116
+ ## 🎮 Processing Modes
117
+
118
+ MarkdownFlow offers three processing modes:
119
+
120
+ ```python
121
+ from markdown_flow import ProcessMode
122
+
123
+ # Get built prompt without LLM call
124
+ prompt_result = await mf.process(0, mode=ProcessMode.PROMPT_ONLY)
125
+
126
+ # Full processing with LLM (non-streaming)
127
+ complete_result = await mf.process(0, mode=ProcessMode.COMPLETE)
128
+
129
+ # Streaming LLM processing
130
+ async for chunk in await mf.process(0, mode=ProcessMode.STREAM):
131
+ print(chunk.content)
132
+ ```
133
+
134
+ ## 🏗️ Core Components
135
+
136
+ ### MarkdownFlow Class
137
+ The main processing class with unified `process()` interface:
138
+
139
+ ```python
140
+ class MarkdownFlow:
141
+ async def process(
142
+ self,
143
+ block_index: int,
144
+ mode: ProcessMode = ProcessMode.COMPLETE,
145
+ variables: Optional[Dict[str, str]] = None,
146
+ user_input: Optional[str] = None,
147
+ ) -> Union[LLMResult, AsyncGenerator[LLMResult, None]]
148
+ ```
149
+
150
+ ### LLM Provider Integration
151
+ Implement the `LLMProvider` interface for custom LLM integration:
152
+
153
+ ```python
154
+ from markdown_flow import LLMProvider, LLMResult
155
+
156
+ class YourLLMProvider(LLMProvider):
157
+ async def generate_response(self, messages: List[Dict], **kwargs) -> LLMResult:
158
+ # Your LLM implementation
159
+ pass
160
+
161
+ async def generate_stream(self, messages: List[Dict], **kwargs):
162
+ # Your streaming implementation
163
+ pass
164
+ ```
165
+
166
+ ## 📖 Advanced Usage
167
+
168
+ ### Document Structure
169
+ ```markdown
170
+ # Document Title
171
+ This is regular content that will be processed.
172
+
173
+ ---
174
+
175
+ ?[%{{user_name}}...What's your name?]
176
+
177
+ ---
178
+
179
+ Hello %{{user_name}}! This block uses your input.
180
+
181
+ ---
182
+
183
+ ===Preserved Content===
184
+ This content is preserved as-is without processing.
185
+ ===
186
+ ```
187
+
188
+ ### Block Processing
189
+ ```python
190
+ # Get all blocks
191
+ blocks = mf.get_all_blocks()
192
+
193
+ for i, block in enumerate(blocks):
194
+ print(f"Block {i}: {block.block_type}")
195
+ if block.block_type == BlockType.INTERACTION:
196
+ # Process interaction
197
+ result = await mf.process(i, mode=ProcessMode.COMPLETE)
198
+ ```
199
+
200
+ ### Interaction Processing
201
+ ```python
202
+ # Process user interaction
203
+ interaction_result = await mf.process(
204
+ block_index=1, # interaction block index
205
+ user_input="user response",
206
+ mode=ProcessMode.COMPLETE
207
+ )
208
+ ```
209
+
210
+ ## 🤝 Contributing
211
+
212
+ We welcome contributions! Please see our [GitHub repository](https://github.com/ai-shifu/markdown-flow) for more information.
213
+
214
+ ## 📄 License
215
+
216
+ This project is licensed under the MIT License - see the LICENSE file for details.
217
+
218
+ ## 🔗 Links
219
+
220
+ - **Homepage**: https://github.com/ai-shifu/markdown-flow
221
+ - **Bug Tracker**: https://github.com/ai-shifu/markdown-flow/issues
222
+ - **Documentation**: Coming soon
223
+
224
+ ## 🏷️ Version
225
+
226
+ Current version: 0.1.0
227
+
228
+ ---
229
+
230
+ **MarkdownFlow** - Making interactive Markdown documents simple and powerful! 🚀
@@ -0,0 +1,84 @@
1
+ """
2
+ Markdown-Flow Core Components
3
+
4
+ A powerful Python package for parsing and processing specially formatted Markdown documents.
5
+
6
+ Core Features:
7
+ - Parse documents into blocks using --- and ?[] separators
8
+ - Three-layer parsing architecture for complex interaction formats
9
+ - Extract variable placeholders ({{variable}} and %{{variable}} formats)
10
+ - Build LLM-ready prompts and message formats
11
+ - Handle user interaction validation and input processing
12
+ - Support multiple processing modes: PROMPT_ONLY, COMPLETE, STREAM
13
+
14
+ Supported Interaction Types:
15
+ - TEXT_ONLY: ?[%{{var}}...question] - Text input only
16
+ - BUTTONS_ONLY: ?[%{{var}} A|B] - Button selection only
17
+ - BUTTONS_WITH_TEXT: ?[%{{var}} A|B|...question] - Buttons + text input
18
+ - NON_ASSIGNMENT_BUTTON: ?[Continue|Cancel] - Display buttons only
19
+
20
+ Basic Usage:
21
+ from markdown_flow import MarkdownFlow, ProcessMode
22
+
23
+ # Create instance with LLM provider
24
+ mf = MarkdownFlow(document, llm_provider=your_llm_provider)
25
+
26
+ # Extract variables
27
+ variables = mf.extract_variables()
28
+
29
+ # Get all blocks
30
+ blocks = mf.get_all_blocks()
31
+
32
+ # Process blocks using unified interface
33
+ result = await mf.process(0, variables={'name': 'John'}, mode=ProcessMode.COMPLETE)
34
+
35
+ # Different processing modes
36
+ prompt_result = await mf.process(0, mode=ProcessMode.PROMPT_ONLY)
37
+ complete_result = await mf.process(0, mode=ProcessMode.COMPLETE)
38
+ stream_result = await mf.process(0, mode=ProcessMode.STREAM)
39
+
40
+ Variable System:
41
+ - {{variable}} - Regular variables, replaced with actual values
42
+ - %{{variable}} - Preserved variables, kept in original format for LLM understanding
43
+
44
+ Import Guide:
45
+ from markdown_flow import MarkdownFlow, ProcessMode, LLMProvider
46
+ from markdown_flow import extract_variables_from_text, InteractionParser
47
+ from markdown_flow import InteractionType, BlockType, InputType
48
+ """
49
+
50
+ # Import core classes and enums
51
+ from .core import MarkdownFlow
52
+ from .enums import BlockType, InputType
53
+ from .llm import LLMProvider, LLMResult, ProcessMode
54
+ from .utils import (
55
+ InteractionParser,
56
+ InteractionType,
57
+ extract_interaction_question,
58
+ extract_variables_from_text,
59
+ generate_smart_validation_template,
60
+ replace_variables_in_text,
61
+ )
62
+
63
+ # Public API
64
+ __all__ = [
65
+ # Core classes
66
+ "MarkdownFlow",
67
+ "InteractionParser",
68
+ # LLM related
69
+ "LLMProvider",
70
+ "LLMResult",
71
+ "ProcessMode",
72
+ # Enumeration types
73
+ "BlockType",
74
+ "InputType",
75
+ "InteractionType",
76
+ # Main utility functions
77
+ "generate_smart_validation_template",
78
+ "extract_interaction_question",
79
+ "extract_variables_from_text",
80
+ "replace_variables_in_text",
81
+ ]
82
+
83
+ # Version information
84
+ __version__ = "0.1.0"