mrmd-ai 0.1.0__py3-none-any.whl
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.
- mrmd_ai/__init__.py +3 -0
- mrmd_ai/juice.py +416 -0
- mrmd_ai/metrics/__init__.py +1 -0
- mrmd_ai/modules/__init__.py +74 -0
- mrmd_ai/modules/code.py +141 -0
- mrmd_ai/modules/correct.py +53 -0
- mrmd_ai/modules/document.py +41 -0
- mrmd_ai/modules/finish.py +95 -0
- mrmd_ai/modules/fix.py +52 -0
- mrmd_ai/modules/notebook.py +15 -0
- mrmd_ai/modules/text.py +69 -0
- mrmd_ai/optimizers/__init__.py +1 -0
- mrmd_ai/server.py +429 -0
- mrmd_ai/signatures/__init__.py +27 -0
- mrmd_ai/signatures/code.py +279 -0
- mrmd_ai/signatures/correct.py +72 -0
- mrmd_ai/signatures/document.py +57 -0
- mrmd_ai/signatures/finish.py +134 -0
- mrmd_ai/signatures/fix.py +72 -0
- mrmd_ai/signatures/notebook.py +37 -0
- mrmd_ai/signatures/text.py +134 -0
- mrmd_ai/utils/__init__.py +1 -0
- mrmd_ai-0.1.0.dist-info/METADATA +45 -0
- mrmd_ai-0.1.0.dist-info/RECORD +26 -0
- mrmd_ai-0.1.0.dist-info/WHEEL +4 -0
- mrmd_ai-0.1.0.dist-info/entry_points.txt +2 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"""Signature definitions for code transformation programs."""
|
|
2
|
+
|
|
3
|
+
import dspy
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class DocumentCodeSignature(dspy.Signature):
|
|
8
|
+
"""
|
|
9
|
+
Add documentation to the selected code ONLY.
|
|
10
|
+
|
|
11
|
+
CRITICAL: You must ONLY transform the `code` field. Do NOT include any code from `local_context`.
|
|
12
|
+
The `local_context` is provided ONLY to help you understand the code - never include it in output.
|
|
13
|
+
|
|
14
|
+
Guidelines:
|
|
15
|
+
- For functions: Add a docstring describing purpose, parameters, and return value
|
|
16
|
+
- For classes: Add a class docstring describing purpose and key attributes
|
|
17
|
+
- For code sections: Add a comment block explaining what the code does
|
|
18
|
+
- Follow the language's documentation conventions (e.g., Google style for Python)
|
|
19
|
+
- Keep documentation concise but informative
|
|
20
|
+
- Output must be EXACTLY the `code` input with documentation added
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
code: str = dspy.InputField(
|
|
24
|
+
desc="The EXACT code to document. Output must contain ONLY this code with docs added."
|
|
25
|
+
)
|
|
26
|
+
language: str = dspy.InputField(
|
|
27
|
+
desc="Programming language (e.g., python, javascript, rust)"
|
|
28
|
+
)
|
|
29
|
+
local_context: str = dspy.InputField(
|
|
30
|
+
desc="Surrounding code for context ONLY - do NOT include this in output"
|
|
31
|
+
)
|
|
32
|
+
document_context: Optional[str] = dspy.InputField(
|
|
33
|
+
desc="Full file content for understanding - do NOT include in output",
|
|
34
|
+
default=None,
|
|
35
|
+
)
|
|
36
|
+
documented_code: str = dspy.OutputField(
|
|
37
|
+
desc="ONLY the `code` input with documentation added. Must contain same code structure."
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class CompleteCodeSignature(dspy.Signature):
|
|
42
|
+
"""
|
|
43
|
+
Complete an incomplete function, class, or code block.
|
|
44
|
+
|
|
45
|
+
Guidelines:
|
|
46
|
+
- Analyze what the code is trying to accomplish
|
|
47
|
+
- Complete the implementation logically
|
|
48
|
+
- Follow existing code style and patterns
|
|
49
|
+
- Only output the completion, not the original code
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
code: str = dspy.InputField(
|
|
53
|
+
desc="Incomplete code to complete"
|
|
54
|
+
)
|
|
55
|
+
language: str = dspy.InputField(
|
|
56
|
+
desc="Programming language (e.g., python, javascript, rust)"
|
|
57
|
+
)
|
|
58
|
+
local_context: str = dspy.InputField(
|
|
59
|
+
desc="Surrounding code for context"
|
|
60
|
+
)
|
|
61
|
+
document_context: Optional[str] = dspy.InputField(
|
|
62
|
+
desc="Full file content for understanding the codebase",
|
|
63
|
+
default=None,
|
|
64
|
+
)
|
|
65
|
+
completion: str = dspy.OutputField(
|
|
66
|
+
desc="The code completion (what comes after the input code)"
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class AddTypeHintsSignature(dspy.Signature):
|
|
71
|
+
"""
|
|
72
|
+
Add type annotations to the selected code ONLY.
|
|
73
|
+
|
|
74
|
+
CRITICAL: You must ONLY transform the `code` field. Do NOT include any code from `local_context`.
|
|
75
|
+
The `local_context` is provided ONLY to help you understand types - never include it in output.
|
|
76
|
+
|
|
77
|
+
Guidelines:
|
|
78
|
+
- Add type hints to function parameters and return types
|
|
79
|
+
- Add type hints to variables where beneficial
|
|
80
|
+
- Use appropriate types from typing module (List, Dict, Optional, etc.)
|
|
81
|
+
- Infer types from usage and context
|
|
82
|
+
- Output must be EXACTLY the `code` input with type hints added - same lines, same structure
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
code: str = dspy.InputField(
|
|
86
|
+
desc="The EXACT code to transform. Output must contain ONLY this code with type hints added."
|
|
87
|
+
)
|
|
88
|
+
language: str = dspy.InputField(
|
|
89
|
+
desc="Programming language (e.g., python, typescript)"
|
|
90
|
+
)
|
|
91
|
+
local_context: str = dspy.InputField(
|
|
92
|
+
desc="Surrounding code for context ONLY - do NOT include this in output"
|
|
93
|
+
)
|
|
94
|
+
document_context: Optional[str] = dspy.InputField(
|
|
95
|
+
desc="Full file content for understanding types - do NOT include in output",
|
|
96
|
+
default=None,
|
|
97
|
+
)
|
|
98
|
+
typed_code: str = dspy.OutputField(
|
|
99
|
+
desc="ONLY the `code` input with type annotations added. Must have same structure as input."
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class ImproveNamesSignature(dspy.Signature):
|
|
104
|
+
"""
|
|
105
|
+
Improve variable, function, and class names in the selected code ONLY.
|
|
106
|
+
|
|
107
|
+
CRITICAL: You must ONLY transform the `code` field. Do NOT include any code from `local_context`.
|
|
108
|
+
The `local_context` is provided ONLY to help you understand naming patterns - never include it in output.
|
|
109
|
+
|
|
110
|
+
Guidelines:
|
|
111
|
+
- Make names more descriptive and self-documenting
|
|
112
|
+
- Follow language naming conventions (snake_case for Python, camelCase for JS, etc.)
|
|
113
|
+
- Avoid single-letter names except for obvious cases (i, j for loops)
|
|
114
|
+
- Make the code more readable through better naming
|
|
115
|
+
- Preserve the code's functionality exactly
|
|
116
|
+
- Output must be EXACTLY the `code` input with names improved
|
|
117
|
+
"""
|
|
118
|
+
|
|
119
|
+
code: str = dspy.InputField(
|
|
120
|
+
desc="The EXACT code to transform. Output must contain ONLY this code with better names."
|
|
121
|
+
)
|
|
122
|
+
language: str = dspy.InputField(
|
|
123
|
+
desc="Programming language"
|
|
124
|
+
)
|
|
125
|
+
local_context: str = dspy.InputField(
|
|
126
|
+
desc="Surrounding code for context ONLY - do NOT include this in output"
|
|
127
|
+
)
|
|
128
|
+
document_context: Optional[str] = dspy.InputField(
|
|
129
|
+
desc="Full file content for understanding naming patterns - do NOT include in output",
|
|
130
|
+
default=None,
|
|
131
|
+
)
|
|
132
|
+
improved_code: str = dspy.OutputField(
|
|
133
|
+
desc="ONLY the `code` input with improved names. Must have same structure as input."
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class ExplainCodeSignature(dspy.Signature):
|
|
138
|
+
"""
|
|
139
|
+
Add inline comments to explain the selected code ONLY.
|
|
140
|
+
|
|
141
|
+
CRITICAL: You must ONLY transform the `code` field. Do NOT include any code from `local_context`.
|
|
142
|
+
The `local_context` is provided ONLY to help you understand purpose - never include it in output.
|
|
143
|
+
|
|
144
|
+
Guidelines:
|
|
145
|
+
- Add comments that explain the "why" not just the "what"
|
|
146
|
+
- Focus on complex or non-obvious logic
|
|
147
|
+
- Don't over-comment simple, self-explanatory code
|
|
148
|
+
- Use clear, concise language
|
|
149
|
+
- Place comments on the line before or on the same line as the code
|
|
150
|
+
- Output must be EXACTLY the `code` input with comments added
|
|
151
|
+
"""
|
|
152
|
+
|
|
153
|
+
code: str = dspy.InputField(
|
|
154
|
+
desc="The EXACT code to explain. Output must contain ONLY this code with comments added."
|
|
155
|
+
)
|
|
156
|
+
language: str = dspy.InputField(
|
|
157
|
+
desc="Programming language"
|
|
158
|
+
)
|
|
159
|
+
local_context: str = dspy.InputField(
|
|
160
|
+
desc="Surrounding code for context ONLY - do NOT include this in output"
|
|
161
|
+
)
|
|
162
|
+
document_context: Optional[str] = dspy.InputField(
|
|
163
|
+
desc="Full file content for understanding purpose - do NOT include in output",
|
|
164
|
+
default=None,
|
|
165
|
+
)
|
|
166
|
+
explained_code: str = dspy.OutputField(
|
|
167
|
+
desc="ONLY the `code` input with explanatory comments. Must have same structure as input."
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
class RefactorCodeSignature(dspy.Signature):
|
|
172
|
+
"""
|
|
173
|
+
Refactor and simplify the selected code ONLY while preserving its behavior.
|
|
174
|
+
|
|
175
|
+
CRITICAL: You must ONLY transform the `code` field. Do NOT include any code from `local_context`.
|
|
176
|
+
The `local_context` is provided ONLY to help you understand dependencies - never include it in output.
|
|
177
|
+
|
|
178
|
+
Guidelines:
|
|
179
|
+
- Simplify complex logic
|
|
180
|
+
- Remove redundancy and dead code
|
|
181
|
+
- Improve readability
|
|
182
|
+
- Apply best practices and design patterns where appropriate
|
|
183
|
+
- Preserve the exact functionality
|
|
184
|
+
- Don't change the API/interface unless clearly beneficial
|
|
185
|
+
- Output must be EXACTLY the `code` input refactored
|
|
186
|
+
"""
|
|
187
|
+
|
|
188
|
+
code: str = dspy.InputField(
|
|
189
|
+
desc="The EXACT code to refactor. Output must contain ONLY this code refactored."
|
|
190
|
+
)
|
|
191
|
+
language: str = dspy.InputField(
|
|
192
|
+
desc="Programming language"
|
|
193
|
+
)
|
|
194
|
+
local_context: str = dspy.InputField(
|
|
195
|
+
desc="Surrounding code for context ONLY - do NOT include this in output"
|
|
196
|
+
)
|
|
197
|
+
document_context: Optional[str] = dspy.InputField(
|
|
198
|
+
desc="Full file content for understanding dependencies - do NOT include in output",
|
|
199
|
+
default=None,
|
|
200
|
+
)
|
|
201
|
+
refactored_code: str = dspy.OutputField(
|
|
202
|
+
desc="ONLY the `code` input refactored. Must transform only the input code."
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
class FormatCodeSignature(dspy.Signature):
|
|
207
|
+
"""
|
|
208
|
+
Format and prettify the selected code ONLY.
|
|
209
|
+
|
|
210
|
+
CRITICAL: You must ONLY format the `code` field. Do NOT include any code from `local_context`.
|
|
211
|
+
The `local_context` is provided ONLY to understand style conventions - never include it in output.
|
|
212
|
+
|
|
213
|
+
Guidelines:
|
|
214
|
+
- Apply consistent indentation (spaces or tabs based on context)
|
|
215
|
+
- Add proper line breaks and spacing
|
|
216
|
+
- Align similar constructs (assignments, parameters, etc.)
|
|
217
|
+
- Follow language-specific formatting conventions (PEP8 for Python, etc.)
|
|
218
|
+
- Preserve the exact functionality - only change whitespace and formatting
|
|
219
|
+
- Output must be EXACTLY the `code` input formatted
|
|
220
|
+
"""
|
|
221
|
+
|
|
222
|
+
code: str = dspy.InputField(
|
|
223
|
+
desc="The EXACT code to format. Output must contain ONLY this code formatted."
|
|
224
|
+
)
|
|
225
|
+
language: str = dspy.InputField(
|
|
226
|
+
desc="Programming language (e.g., python, javascript, rust)"
|
|
227
|
+
)
|
|
228
|
+
local_context: str = dspy.InputField(
|
|
229
|
+
desc="Surrounding code for style context ONLY - do NOT include this in output"
|
|
230
|
+
)
|
|
231
|
+
document_context: Optional[str] = dspy.InputField(
|
|
232
|
+
desc="Full file content for style conventions - do NOT include in output",
|
|
233
|
+
default=None,
|
|
234
|
+
)
|
|
235
|
+
formatted_code: str = dspy.OutputField(
|
|
236
|
+
desc="ONLY the `code` input formatted. Must have same logic, just better formatting."
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
class ProgramCodeSignature(dspy.Signature):
|
|
241
|
+
"""
|
|
242
|
+
Transform pseudo-code or natural language instructions into proper, executable code.
|
|
243
|
+
|
|
244
|
+
The input is a mix of English descriptions and code fragments - a shorthand way of
|
|
245
|
+
expressing programming intent. Your job is to interpret this and produce clean,
|
|
246
|
+
working code in the target language.
|
|
247
|
+
|
|
248
|
+
Guidelines:
|
|
249
|
+
- Parse the pseudo-code to understand the programmer's intent
|
|
250
|
+
- Convert English descriptions into actual code constructs
|
|
251
|
+
- Fill in implied details (variable declarations, imports, error handling)
|
|
252
|
+
- Follow the conventions and patterns visible in document_context
|
|
253
|
+
- Match the coding style of surrounding code in local_context
|
|
254
|
+
- Output must be syntactically correct, runnable code
|
|
255
|
+
- Preserve any actual code fragments from the input, just clean them up
|
|
256
|
+
|
|
257
|
+
Examples of pseudo-code patterns to handle:
|
|
258
|
+
- "loop through items and print each" -> for item in items: print(item)
|
|
259
|
+
- "if user exists then return user else throw error" -> proper if/else with exception
|
|
260
|
+
- "fetch url, parse json, extract 'data' field" -> requests + json parsing code
|
|
261
|
+
- "class User with name, email, save method" -> full class definition
|
|
262
|
+
"""
|
|
263
|
+
|
|
264
|
+
pseudo_code: str = dspy.InputField(
|
|
265
|
+
desc="The pseudo-code or natural language mixed with code fragments to transform"
|
|
266
|
+
)
|
|
267
|
+
language: str = dspy.InputField(
|
|
268
|
+
desc="Target programming language (e.g., python, javascript, rust)"
|
|
269
|
+
)
|
|
270
|
+
local_context: str = dspy.InputField(
|
|
271
|
+
desc="Surrounding code for style and context - understand patterns but don't include in output"
|
|
272
|
+
)
|
|
273
|
+
document_context: Optional[str] = dspy.InputField(
|
|
274
|
+
desc="Full document/notebook content - use for imports, defined functions, conventions",
|
|
275
|
+
default=None,
|
|
276
|
+
)
|
|
277
|
+
code: str = dspy.OutputField(
|
|
278
|
+
desc="Clean, executable code that implements the pseudo-code intent"
|
|
279
|
+
)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""Signature definitions for correct-and-finish programs."""
|
|
2
|
+
|
|
3
|
+
import dspy
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class CorrectAndFinishLineSignature(dspy.Signature):
|
|
8
|
+
"""
|
|
9
|
+
You are helping a user in a markdown notebook. Your task is to BOTH correct
|
|
10
|
+
errors AND complete the current line.
|
|
11
|
+
|
|
12
|
+
You will receive:
|
|
13
|
+
- document_context: The full notebook for understanding context
|
|
14
|
+
- local_context: The current section/code block
|
|
15
|
+
- text_to_fix: The current line that may have errors and is incomplete
|
|
16
|
+
- content_type: Whether this is 'text' or code (e.g., 'python', 'javascript')
|
|
17
|
+
|
|
18
|
+
Output the COMPLETE corrected and finished line.
|
|
19
|
+
First fix any errors, then complete the line naturally.
|
|
20
|
+
This replaces the entire text_to_fix, so output the full corrected+completed version.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
document_context: Optional[str] = dspy.InputField(
|
|
24
|
+
desc="The full notebook/document for understanding context",
|
|
25
|
+
default=None,
|
|
26
|
+
)
|
|
27
|
+
local_context: str = dspy.InputField(
|
|
28
|
+
desc="The current paragraph or code block for immediate context"
|
|
29
|
+
)
|
|
30
|
+
text_to_fix: str = dspy.InputField(
|
|
31
|
+
desc="The current line with possible errors, incomplete - will be replaced entirely"
|
|
32
|
+
)
|
|
33
|
+
content_type: str = dspy.InputField(
|
|
34
|
+
desc="Type of content: 'text' for prose, or language name like 'python', 'javascript'"
|
|
35
|
+
)
|
|
36
|
+
corrected_completion: str = dspy.OutputField(
|
|
37
|
+
desc="The FULL line - corrected and completed - this replaces text_to_fix entirely"
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class CorrectAndFinishSectionSignature(dspy.Signature):
|
|
42
|
+
"""
|
|
43
|
+
You are helping a user in a markdown notebook. Your task is to BOTH correct
|
|
44
|
+
errors AND complete the current section (paragraph or code block).
|
|
45
|
+
|
|
46
|
+
You will receive:
|
|
47
|
+
- document_context: The full notebook for understanding context
|
|
48
|
+
- local_context: The surrounding content
|
|
49
|
+
- text_to_fix: The current section that may have errors and is incomplete
|
|
50
|
+
- content_type: Whether this is 'text' or code (e.g., 'python', 'javascript')
|
|
51
|
+
|
|
52
|
+
Output the COMPLETE corrected and finished section.
|
|
53
|
+
First fix any errors, then complete the section naturally.
|
|
54
|
+
This replaces the entire text_to_fix, so output the full corrected+completed version.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
document_context: Optional[str] = dspy.InputField(
|
|
58
|
+
desc="The full notebook/document for understanding context",
|
|
59
|
+
default=None,
|
|
60
|
+
)
|
|
61
|
+
local_context: str = dspy.InputField(
|
|
62
|
+
desc="The surrounding content for context"
|
|
63
|
+
)
|
|
64
|
+
text_to_fix: str = dspy.InputField(
|
|
65
|
+
desc="The current section with possible errors, incomplete - will be replaced entirely"
|
|
66
|
+
)
|
|
67
|
+
content_type: str = dspy.InputField(
|
|
68
|
+
desc="Type of content: 'text' for prose, or language name like 'python', 'javascript'"
|
|
69
|
+
)
|
|
70
|
+
corrected_completion: str = dspy.OutputField(
|
|
71
|
+
desc="The FULL section - corrected and completed - this replaces text_to_fix entirely"
|
|
72
|
+
)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Signature definitions for document-level AI programs."""
|
|
2
|
+
|
|
3
|
+
import dspy
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class DocumentResponseSignature(dspy.Signature):
|
|
8
|
+
"""
|
|
9
|
+
You are responding to a document prompt in a markdown notebook.
|
|
10
|
+
The entire document serves as the prompt/context, and you generate a thoughtful response.
|
|
11
|
+
|
|
12
|
+
Use cases:
|
|
13
|
+
- Answer questions posed in the document
|
|
14
|
+
- Continue a train of thought
|
|
15
|
+
- Provide analysis or feedback on the content
|
|
16
|
+
- Generate content based on instructions in the document
|
|
17
|
+
|
|
18
|
+
Your response will be appended to a "# AI Response" section at the end of the document.
|
|
19
|
+
Format your response in markdown. Be thorough but concise.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
document: str = dspy.InputField(
|
|
23
|
+
desc="The full document/notebook content serving as the prompt"
|
|
24
|
+
)
|
|
25
|
+
response: str = dspy.OutputField(
|
|
26
|
+
desc="Your response in markdown format - thoughtful, well-structured, and relevant to the document"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class DocumentSummarySignature(dspy.Signature):
|
|
31
|
+
"""
|
|
32
|
+
Summarize a document concisely while preserving key information.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
document: str = dspy.InputField(
|
|
36
|
+
desc="The document to summarize"
|
|
37
|
+
)
|
|
38
|
+
summary: str = dspy.OutputField(
|
|
39
|
+
desc="A concise summary capturing the main points and key information"
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class DocumentAnalysisSignature(dspy.Signature):
|
|
44
|
+
"""
|
|
45
|
+
Analyze a document and provide insights, suggestions, or critique.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
document: str = dspy.InputField(
|
|
49
|
+
desc="The document to analyze"
|
|
50
|
+
)
|
|
51
|
+
analysis_type: str = dspy.InputField(
|
|
52
|
+
desc="Type of analysis: 'structure', 'clarity', 'completeness', 'technical', or 'general'",
|
|
53
|
+
default="general"
|
|
54
|
+
)
|
|
55
|
+
analysis: str = dspy.OutputField(
|
|
56
|
+
desc="Detailed analysis with specific observations and actionable suggestions"
|
|
57
|
+
)
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"""Signature definitions for finish/completion programs."""
|
|
2
|
+
|
|
3
|
+
import dspy
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class FinishSentenceSignature(dspy.Signature):
|
|
8
|
+
"""
|
|
9
|
+
You are helping a user write in a markdown notebook. Your task is to complete
|
|
10
|
+
the sentence they are currently typing.
|
|
11
|
+
|
|
12
|
+
You will receive:
|
|
13
|
+
- document_context: The full notebook content for understanding the topic and style
|
|
14
|
+
- local_context: The current paragraph/section being written
|
|
15
|
+
- text_before_cursor: The exact text up to where the cursor is (what needs completion)
|
|
16
|
+
|
|
17
|
+
Output ONLY the text that should be appended after the cursor.
|
|
18
|
+
Do NOT repeat any of the text_before_cursor.
|
|
19
|
+
Complete the sentence naturally, matching the writing style.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
document_context: Optional[str] = dspy.InputField(
|
|
23
|
+
desc="The full notebook/document content for understanding context, style, and topic",
|
|
24
|
+
default=None,
|
|
25
|
+
)
|
|
26
|
+
local_context: str = dspy.InputField(
|
|
27
|
+
desc="The current paragraph or section being written"
|
|
28
|
+
)
|
|
29
|
+
text_before_cursor: str = dspy.InputField(
|
|
30
|
+
desc="The exact text up to the cursor position - this is what you're completing"
|
|
31
|
+
)
|
|
32
|
+
completion: str = dspy.OutputField(
|
|
33
|
+
desc="ONLY the new text to append after the cursor - do not repeat any existing text"
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class FinishParagraphSignature(dspy.Signature):
|
|
38
|
+
"""
|
|
39
|
+
You are helping a user write in a markdown notebook. Your task is to complete
|
|
40
|
+
the paragraph they are currently writing.
|
|
41
|
+
|
|
42
|
+
You will receive:
|
|
43
|
+
- document_context: The full notebook content for understanding the topic and style
|
|
44
|
+
- local_context: The current section/cell being written
|
|
45
|
+
- text_before_cursor: The paragraph text up to the cursor position
|
|
46
|
+
|
|
47
|
+
Output ONLY the text that should be appended after the cursor.
|
|
48
|
+
Do NOT repeat any of the text_before_cursor.
|
|
49
|
+
Complete the paragraph naturally, bringing the thought to conclusion.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
document_context: Optional[str] = dspy.InputField(
|
|
53
|
+
desc="The full notebook/document content for understanding context and topic",
|
|
54
|
+
default=None,
|
|
55
|
+
)
|
|
56
|
+
local_context: str = dspy.InputField(
|
|
57
|
+
desc="The current section or cell being written"
|
|
58
|
+
)
|
|
59
|
+
text_before_cursor: str = dspy.InputField(
|
|
60
|
+
desc="The paragraph text up to the cursor - this is what you're completing"
|
|
61
|
+
)
|
|
62
|
+
completion: str = dspy.OutputField(
|
|
63
|
+
desc="ONLY the new text to append - complete the paragraph without repeating existing text"
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class FinishCodeLineSignature(dspy.Signature):
|
|
68
|
+
"""
|
|
69
|
+
You are helping a user write code in a markdown notebook. Your task is to complete
|
|
70
|
+
the current line of code they are typing.
|
|
71
|
+
|
|
72
|
+
You will receive:
|
|
73
|
+
- document_context: The full notebook content (may include other code blocks, explanations)
|
|
74
|
+
- local_context: The current code block being edited
|
|
75
|
+
- code_before_cursor: The code in this block up to the cursor position
|
|
76
|
+
- language: The programming language
|
|
77
|
+
|
|
78
|
+
Output ONLY the code to append after the cursor to complete the current line.
|
|
79
|
+
Do NOT repeat any code from code_before_cursor.
|
|
80
|
+
Follow the coding style visible in the context.
|
|
81
|
+
Only complete the current line - stop at the end of the line.
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
document_context: Optional[str] = dspy.InputField(
|
|
85
|
+
desc="The full notebook content for understanding the project context",
|
|
86
|
+
default=None,
|
|
87
|
+
)
|
|
88
|
+
local_context: str = dspy.InputField(
|
|
89
|
+
desc="The complete current code block being edited"
|
|
90
|
+
)
|
|
91
|
+
code_before_cursor: str = dspy.InputField(
|
|
92
|
+
desc="The code up to the cursor position - this is what you're completing"
|
|
93
|
+
)
|
|
94
|
+
language: str = dspy.InputField(
|
|
95
|
+
desc="The programming language (python, javascript, etc.)"
|
|
96
|
+
)
|
|
97
|
+
completion: str = dspy.OutputField(
|
|
98
|
+
desc="ONLY the code to append to complete the current line - no repetition, no extra lines"
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class FinishCodeSectionSignature(dspy.Signature):
|
|
103
|
+
"""
|
|
104
|
+
You are helping a user write code in a markdown notebook. Your task is to complete
|
|
105
|
+
the current code section (function, class, or logical block).
|
|
106
|
+
|
|
107
|
+
You will receive:
|
|
108
|
+
- document_context: The full notebook content (other code blocks, documentation)
|
|
109
|
+
- local_context: The current code block being edited
|
|
110
|
+
- code_before_cursor: The code up to the cursor position
|
|
111
|
+
- language: The programming language
|
|
112
|
+
|
|
113
|
+
Output ONLY the code to append after the cursor.
|
|
114
|
+
Do NOT repeat any code from code_before_cursor.
|
|
115
|
+
Complete the logical unit (finish the function, close the class, etc.).
|
|
116
|
+
Follow the coding style and conventions visible in the context.
|
|
117
|
+
"""
|
|
118
|
+
|
|
119
|
+
document_context: Optional[str] = dspy.InputField(
|
|
120
|
+
desc="The full notebook content for understanding the project context",
|
|
121
|
+
default=None,
|
|
122
|
+
)
|
|
123
|
+
local_context: str = dspy.InputField(
|
|
124
|
+
desc="The complete current code block being edited"
|
|
125
|
+
)
|
|
126
|
+
code_before_cursor: str = dspy.InputField(
|
|
127
|
+
desc="The code up to the cursor - this is what you're completing"
|
|
128
|
+
)
|
|
129
|
+
language: str = dspy.InputField(
|
|
130
|
+
desc="The programming language (python, javascript, etc.)"
|
|
131
|
+
)
|
|
132
|
+
completion: str = dspy.OutputField(
|
|
133
|
+
desc="ONLY the code to append to complete the section - no repetition of existing code"
|
|
134
|
+
)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""Signature definitions for fix/correction programs."""
|
|
2
|
+
|
|
3
|
+
import dspy
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class FixGrammarSignature(dspy.Signature):
|
|
8
|
+
"""
|
|
9
|
+
You are helping a user fix text in a markdown notebook. Your task is to correct
|
|
10
|
+
grammar, spelling, and punctuation errors in the selected text.
|
|
11
|
+
|
|
12
|
+
You will receive:
|
|
13
|
+
- document_context: The full notebook content for understanding terminology and style
|
|
14
|
+
- local_context: The current paragraph/section for understanding immediate context
|
|
15
|
+
- text_to_fix: The exact text that needs fixing (user's selection or current line)
|
|
16
|
+
|
|
17
|
+
Output the corrected version of text_to_fix.
|
|
18
|
+
Make minimal changes - only fix actual errors.
|
|
19
|
+
Preserve the original meaning, tone, and formatting.
|
|
20
|
+
|
|
21
|
+
IMPORTANT: Preserve ALL whitespace including leading/trailing newlines and spaces.
|
|
22
|
+
The fixed_text must have the exact same whitespace structure as text_to_fix.
|
|
23
|
+
If text_to_fix starts with newlines, fixed_text must too.
|
|
24
|
+
If text_to_fix ends with newlines, fixed_text must too.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
document_context: Optional[str] = dspy.InputField(
|
|
28
|
+
desc="The full notebook/document for understanding terminology and writing style",
|
|
29
|
+
default=None,
|
|
30
|
+
)
|
|
31
|
+
local_context: str = dspy.InputField(
|
|
32
|
+
desc="The current paragraph or section for immediate context"
|
|
33
|
+
)
|
|
34
|
+
text_to_fix: str = dspy.InputField(
|
|
35
|
+
desc="The exact text to fix - preserve all whitespace including leading/trailing newlines"
|
|
36
|
+
)
|
|
37
|
+
fixed_text: str = dspy.OutputField(
|
|
38
|
+
desc="The corrected text - MUST preserve exact whitespace structure (leading/trailing newlines and spaces)"
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class FixTranscriptionSignature(dspy.Signature):
|
|
43
|
+
"""
|
|
44
|
+
You are helping a user fix speech-to-text transcription in a markdown notebook.
|
|
45
|
+
Your task is to correct errors from voice transcription.
|
|
46
|
+
|
|
47
|
+
You will receive:
|
|
48
|
+
- document_context: The full notebook content for understanding the topic and terminology
|
|
49
|
+
- local_context: The current section for understanding what's being discussed
|
|
50
|
+
- text_to_fix: The transcribed text that likely contains speech-to-text errors
|
|
51
|
+
|
|
52
|
+
Output the corrected transcription.
|
|
53
|
+
Fix misheard words, add proper punctuation, and fix capitalization.
|
|
54
|
+
Preserve the speaker's intended meaning.
|
|
55
|
+
|
|
56
|
+
IMPORTANT: Preserve ALL whitespace including leading/trailing newlines and spaces.
|
|
57
|
+
The fixed_text must have the exact same whitespace structure as text_to_fix.
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
document_context: Optional[str] = dspy.InputField(
|
|
61
|
+
desc="The full notebook/document for understanding topic and terminology",
|
|
62
|
+
default=None,
|
|
63
|
+
)
|
|
64
|
+
local_context: str = dspy.InputField(
|
|
65
|
+
desc="The current section for understanding what's being discussed"
|
|
66
|
+
)
|
|
67
|
+
text_to_fix: str = dspy.InputField(
|
|
68
|
+
desc="The transcribed text to fix - preserve all whitespace including leading/trailing newlines"
|
|
69
|
+
)
|
|
70
|
+
fixed_text: str = dspy.OutputField(
|
|
71
|
+
desc="The corrected transcription - MUST preserve exact whitespace structure"
|
|
72
|
+
)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Signature definitions for notebook-related AI programs."""
|
|
2
|
+
|
|
3
|
+
import dspy
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class NotebookNameSignature(dspy.Signature):
|
|
7
|
+
"""
|
|
8
|
+
Generate a short, descriptive filename for a notebook based on its content.
|
|
9
|
+
|
|
10
|
+
The name should:
|
|
11
|
+
- Be a valid filename (no special characters except hyphens and underscores)
|
|
12
|
+
- Be lowercase with hyphens between words (kebab-case)
|
|
13
|
+
- Be concise (2-5 words, max 50 characters)
|
|
14
|
+
- Capture the essence or main topic of the document
|
|
15
|
+
- NOT include the .md extension (that will be added separately)
|
|
16
|
+
|
|
17
|
+
Examples of good names:
|
|
18
|
+
- "meeting-notes-q4-planning"
|
|
19
|
+
- "react-hooks-tutorial"
|
|
20
|
+
- "api-design-thoughts"
|
|
21
|
+
- "weekly-standup-dec-15"
|
|
22
|
+
- "debugging-memory-leak"
|
|
23
|
+
|
|
24
|
+
If the content is too short or unclear, suggest a generic but contextual name
|
|
25
|
+
like "untitled-notes" or "draft-thoughts".
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
document: str = dspy.InputField(
|
|
29
|
+
desc="The notebook content to analyze for naming"
|
|
30
|
+
)
|
|
31
|
+
current_name: str = dspy.InputField(
|
|
32
|
+
desc="The current filename (may be 'Untitled' or generic)",
|
|
33
|
+
default="Untitled"
|
|
34
|
+
)
|
|
35
|
+
name: str = dspy.OutputField(
|
|
36
|
+
desc="A short, descriptive kebab-case filename (without .md extension)"
|
|
37
|
+
)
|