DeepFabric 4.4.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.
- deepfabric/__init__.py +70 -0
- deepfabric/__main__.py +6 -0
- deepfabric/auth.py +382 -0
- deepfabric/builders.py +303 -0
- deepfabric/builders_agent.py +1304 -0
- deepfabric/cli.py +1288 -0
- deepfabric/config.py +899 -0
- deepfabric/config_manager.py +251 -0
- deepfabric/constants.py +94 -0
- deepfabric/dataset_manager.py +534 -0
- deepfabric/error_codes.py +581 -0
- deepfabric/evaluation/__init__.py +47 -0
- deepfabric/evaluation/backends/__init__.py +32 -0
- deepfabric/evaluation/backends/ollama_backend.py +137 -0
- deepfabric/evaluation/backends/tool_call_parsers.py +409 -0
- deepfabric/evaluation/backends/transformers_backend.py +326 -0
- deepfabric/evaluation/evaluator.py +845 -0
- deepfabric/evaluation/evaluators/__init__.py +13 -0
- deepfabric/evaluation/evaluators/base.py +104 -0
- deepfabric/evaluation/evaluators/builtin/__init__.py +5 -0
- deepfabric/evaluation/evaluators/builtin/tool_calling.py +93 -0
- deepfabric/evaluation/evaluators/registry.py +66 -0
- deepfabric/evaluation/inference.py +155 -0
- deepfabric/evaluation/metrics.py +397 -0
- deepfabric/evaluation/parser.py +304 -0
- deepfabric/evaluation/reporters/__init__.py +13 -0
- deepfabric/evaluation/reporters/base.py +56 -0
- deepfabric/evaluation/reporters/cloud_reporter.py +195 -0
- deepfabric/evaluation/reporters/file_reporter.py +61 -0
- deepfabric/evaluation/reporters/multi_reporter.py +56 -0
- deepfabric/exceptions.py +67 -0
- deepfabric/factory.py +26 -0
- deepfabric/generator.py +1084 -0
- deepfabric/graph.py +545 -0
- deepfabric/hf_hub.py +214 -0
- deepfabric/kaggle_hub.py +219 -0
- deepfabric/llm/__init__.py +41 -0
- deepfabric/llm/api_key_verifier.py +534 -0
- deepfabric/llm/client.py +1206 -0
- deepfabric/llm/errors.py +105 -0
- deepfabric/llm/rate_limit_config.py +262 -0
- deepfabric/llm/rate_limit_detector.py +278 -0
- deepfabric/llm/retry_handler.py +270 -0
- deepfabric/metrics.py +212 -0
- deepfabric/progress.py +262 -0
- deepfabric/prompts.py +290 -0
- deepfabric/schemas.py +1000 -0
- deepfabric/spin/__init__.py +6 -0
- deepfabric/spin/client.py +263 -0
- deepfabric/spin/models.py +26 -0
- deepfabric/stream_simulator.py +90 -0
- deepfabric/tools/__init__.py +5 -0
- deepfabric/tools/defaults.py +85 -0
- deepfabric/tools/loader.py +87 -0
- deepfabric/tools/mcp_client.py +677 -0
- deepfabric/topic_manager.py +303 -0
- deepfabric/topic_model.py +20 -0
- deepfabric/training/__init__.py +35 -0
- deepfabric/training/api_key_prompt.py +302 -0
- deepfabric/training/callback.py +363 -0
- deepfabric/training/metrics_sender.py +301 -0
- deepfabric/tree.py +438 -0
- deepfabric/tui.py +1267 -0
- deepfabric/update_checker.py +166 -0
- deepfabric/utils.py +150 -0
- deepfabric/validation.py +143 -0
- deepfabric-4.4.0.dist-info/METADATA +702 -0
- deepfabric-4.4.0.dist-info/RECORD +71 -0
- deepfabric-4.4.0.dist-info/WHEEL +4 -0
- deepfabric-4.4.0.dist-info/entry_points.txt +2 -0
- deepfabric-4.4.0.dist-info/licenses/LICENSE +201 -0
deepfabric/progress.py
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"""Progress reporting system for dataset generation.
|
|
2
|
+
|
|
3
|
+
This module provides a modular event-based progress reporting system that
|
|
4
|
+
allows components to emit progress events (streaming text, step markers, etc.)
|
|
5
|
+
without coupling to specific display implementations.
|
|
6
|
+
|
|
7
|
+
The system uses the Observer pattern to enable multiple observers (TUI, logging,
|
|
8
|
+
metrics, etc.) to react to progress events.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from typing import TYPE_CHECKING, Any, Protocol
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
from .error_codes import ClassifiedError
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class StreamObserver(Protocol):
|
|
18
|
+
"""Protocol for observers that react to progress events.
|
|
19
|
+
|
|
20
|
+
Implementations can choose which events to handle based on their needs.
|
|
21
|
+
This protocol supports both dataset generation and tree/graph building.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def on_stream_chunk(self, source: str, chunk: str, metadata: dict[str, Any]) -> None:
|
|
25
|
+
"""Called when a chunk of streaming text is received from an LLM.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
source: Identifier for the generation source
|
|
29
|
+
- Dataset: "user_question", "agent_reasoning", "tool_sim_weather"
|
|
30
|
+
- Tree/Graph: "topic_generation", "subtopic_expansion"
|
|
31
|
+
chunk: The text chunk received from the LLM
|
|
32
|
+
metadata: Additional context (sample_idx, node_path, depth, etc.)
|
|
33
|
+
"""
|
|
34
|
+
...
|
|
35
|
+
|
|
36
|
+
def on_step_start(self, step_name: str, metadata: dict[str, Any]) -> None:
|
|
37
|
+
"""Called when a generation step begins.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
step_name: Human-readable name of the step
|
|
41
|
+
- Dataset: "Generating user question", "Simulating tool: get_weather"
|
|
42
|
+
- Tree/Graph: "Expanding node: AI/ML", "Generating subtopics (depth 2)"
|
|
43
|
+
metadata: Additional context (sample_idx, turn_idx, depth, node_path, etc.)
|
|
44
|
+
"""
|
|
45
|
+
...
|
|
46
|
+
|
|
47
|
+
def on_step_complete(self, step_name: str, metadata: dict[str, Any]) -> None:
|
|
48
|
+
"""Called when a generation step completes.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
step_name: Human-readable name of the step
|
|
52
|
+
metadata: Additional context including results (tokens_used, duration, success, etc.)
|
|
53
|
+
"""
|
|
54
|
+
...
|
|
55
|
+
|
|
56
|
+
def on_error(self, error: "ClassifiedError", metadata: dict[str, Any]) -> None:
|
|
57
|
+
"""Called when an error occurs during generation.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
error: ClassifiedError with error code and details
|
|
61
|
+
metadata: Additional context (sample_idx, step, etc.)
|
|
62
|
+
"""
|
|
63
|
+
...
|
|
64
|
+
|
|
65
|
+
def on_retry(
|
|
66
|
+
self,
|
|
67
|
+
sample_idx: int,
|
|
68
|
+
attempt: int,
|
|
69
|
+
max_attempts: int,
|
|
70
|
+
error_summary: str,
|
|
71
|
+
metadata: dict[str, Any],
|
|
72
|
+
) -> None:
|
|
73
|
+
"""Called when a sample generation will be retried due to validation failure.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
sample_idx: 1-based sample index
|
|
77
|
+
attempt: Current attempt number (1-based)
|
|
78
|
+
max_attempts: Total number of attempts allowed
|
|
79
|
+
error_summary: Brief description of the validation error
|
|
80
|
+
metadata: Additional context
|
|
81
|
+
"""
|
|
82
|
+
...
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class ProgressReporter:
|
|
86
|
+
"""Central progress reporter that notifies observers of generation events.
|
|
87
|
+
|
|
88
|
+
This class acts as the subject in the Observer pattern, managing a list of
|
|
89
|
+
observers and broadcasting events to them.
|
|
90
|
+
|
|
91
|
+
Example:
|
|
92
|
+
>>> reporter = ProgressReporter()
|
|
93
|
+
>>> reporter.attach(my_tui_observer)
|
|
94
|
+
>>> reporter.emit_step_start("Generating question", sample_idx=1)
|
|
95
|
+
>>> reporter.emit_chunk("user_question", "What is the weather", sample_idx=1)
|
|
96
|
+
>>> reporter.emit_step_complete("Generating question", sample_idx=1)
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
def __init__(self):
|
|
100
|
+
"""Initialize an empty progress reporter."""
|
|
101
|
+
self._observers: list[StreamObserver] = []
|
|
102
|
+
|
|
103
|
+
def attach(self, observer: StreamObserver) -> None:
|
|
104
|
+
"""Attach an observer to receive progress events.
|
|
105
|
+
|
|
106
|
+
Args:
|
|
107
|
+
observer: Observer implementing StreamObserver protocol
|
|
108
|
+
"""
|
|
109
|
+
if observer not in self._observers:
|
|
110
|
+
self._observers.append(observer)
|
|
111
|
+
|
|
112
|
+
def detach(self, observer: StreamObserver) -> None:
|
|
113
|
+
"""Detach an observer from receiving progress events.
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
observer: Observer to remove
|
|
117
|
+
"""
|
|
118
|
+
if observer in self._observers:
|
|
119
|
+
self._observers.remove(observer)
|
|
120
|
+
|
|
121
|
+
def emit_chunk(self, source: str, chunk: str, **metadata) -> None:
|
|
122
|
+
"""Emit a streaming text chunk to all observers.
|
|
123
|
+
|
|
124
|
+
Args:
|
|
125
|
+
source: Identifier for the generation source
|
|
126
|
+
chunk: Text chunk from LLM
|
|
127
|
+
**metadata: Additional context as keyword arguments
|
|
128
|
+
"""
|
|
129
|
+
for observer in self._observers:
|
|
130
|
+
observer.on_stream_chunk(source, chunk, metadata)
|
|
131
|
+
|
|
132
|
+
def emit_step_start(self, step_name: str, **metadata) -> None:
|
|
133
|
+
"""Emit a step start event to all observers.
|
|
134
|
+
|
|
135
|
+
Args:
|
|
136
|
+
step_name: Human-readable step name
|
|
137
|
+
**metadata: Additional context as keyword arguments
|
|
138
|
+
"""
|
|
139
|
+
for observer in self._observers:
|
|
140
|
+
observer.on_step_start(step_name, metadata)
|
|
141
|
+
|
|
142
|
+
def emit_step_complete(self, step_name: str, **metadata) -> None:
|
|
143
|
+
"""Emit a step complete event to all observers.
|
|
144
|
+
|
|
145
|
+
Args:
|
|
146
|
+
step_name: Human-readable step name
|
|
147
|
+
**metadata: Additional context as keyword arguments
|
|
148
|
+
"""
|
|
149
|
+
for observer in self._observers:
|
|
150
|
+
observer.on_step_complete(step_name, metadata)
|
|
151
|
+
|
|
152
|
+
def emit_error(self, error: "ClassifiedError", **metadata) -> None:
|
|
153
|
+
"""Emit an error event to all observers.
|
|
154
|
+
|
|
155
|
+
Args:
|
|
156
|
+
error: ClassifiedError with error code and details
|
|
157
|
+
**metadata: Additional context as keyword arguments
|
|
158
|
+
"""
|
|
159
|
+
for observer in self._observers:
|
|
160
|
+
if hasattr(observer, "on_error"):
|
|
161
|
+
observer.on_error(error, metadata)
|
|
162
|
+
|
|
163
|
+
def emit_retry(
|
|
164
|
+
self,
|
|
165
|
+
sample_idx: int,
|
|
166
|
+
attempt: int,
|
|
167
|
+
max_attempts: int,
|
|
168
|
+
error_summary: str,
|
|
169
|
+
**metadata,
|
|
170
|
+
) -> None:
|
|
171
|
+
"""Emit a retry event to all observers.
|
|
172
|
+
|
|
173
|
+
This is used to track validation failures that will be retried,
|
|
174
|
+
allowing the TUI to display them gracefully without cluttering output.
|
|
175
|
+
|
|
176
|
+
Args:
|
|
177
|
+
sample_idx: 1-based sample index
|
|
178
|
+
attempt: Current attempt number (1-based)
|
|
179
|
+
max_attempts: Total number of attempts allowed
|
|
180
|
+
error_summary: Brief description of the error
|
|
181
|
+
**metadata: Additional context as keyword arguments
|
|
182
|
+
"""
|
|
183
|
+
for observer in self._observers:
|
|
184
|
+
if hasattr(observer, "on_retry"):
|
|
185
|
+
observer.on_retry(sample_idx, attempt, max_attempts, error_summary, metadata)
|
|
186
|
+
|
|
187
|
+
def emit_tool_execution(
|
|
188
|
+
self,
|
|
189
|
+
tool_name: str,
|
|
190
|
+
success: bool,
|
|
191
|
+
**metadata,
|
|
192
|
+
) -> None:
|
|
193
|
+
"""Emit a tool execution event to all observers.
|
|
194
|
+
|
|
195
|
+
Used to track Spin tool executions in the TUI events panel.
|
|
196
|
+
|
|
197
|
+
Args:
|
|
198
|
+
tool_name: Name of the tool being executed
|
|
199
|
+
success: Whether the execution succeeded
|
|
200
|
+
**metadata: Additional context (e.g., error_type, result preview)
|
|
201
|
+
"""
|
|
202
|
+
for observer in self._observers:
|
|
203
|
+
if hasattr(observer, "on_tool_execution"):
|
|
204
|
+
observer.on_tool_execution(tool_name, success, metadata)
|
|
205
|
+
|
|
206
|
+
def emit_node_retry(
|
|
207
|
+
self,
|
|
208
|
+
node_topic: str,
|
|
209
|
+
attempt: int,
|
|
210
|
+
max_attempts: int,
|
|
211
|
+
error_summary: str,
|
|
212
|
+
**metadata,
|
|
213
|
+
) -> None:
|
|
214
|
+
"""Emit a node expansion retry event to all observers.
|
|
215
|
+
|
|
216
|
+
Used to track graph/tree node expansion retries in the TUI events panel.
|
|
217
|
+
|
|
218
|
+
Args:
|
|
219
|
+
node_topic: Topic of the node being expanded
|
|
220
|
+
attempt: Current attempt number (1-based)
|
|
221
|
+
max_attempts: Total number of attempts allowed
|
|
222
|
+
error_summary: Brief description of the error
|
|
223
|
+
**metadata: Additional context as keyword arguments
|
|
224
|
+
"""
|
|
225
|
+
for observer in self._observers:
|
|
226
|
+
if hasattr(observer, "on_node_retry"):
|
|
227
|
+
observer.on_node_retry(node_topic, attempt, max_attempts, error_summary, metadata)
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
# Convenience context manager for tracking steps
|
|
231
|
+
class ProgressStep:
|
|
232
|
+
"""Context manager for automatic step start/complete reporting.
|
|
233
|
+
|
|
234
|
+
Example:
|
|
235
|
+
>>> with ProgressStep(reporter, "Generating question", sample_idx=1):
|
|
236
|
+
... # Do work
|
|
237
|
+
... reporter.emit_chunk("question", "What is...")
|
|
238
|
+
"""
|
|
239
|
+
|
|
240
|
+
def __init__(self, reporter: ProgressReporter | None, step_name: str, **metadata: Any):
|
|
241
|
+
"""Initialize progress step tracker.
|
|
242
|
+
|
|
243
|
+
Args:
|
|
244
|
+
reporter: Progress reporter (None = no-op)
|
|
245
|
+
step_name: Human-readable step name
|
|
246
|
+
**metadata: Additional context
|
|
247
|
+
"""
|
|
248
|
+
self.reporter = reporter
|
|
249
|
+
self.step_name = step_name
|
|
250
|
+
self.metadata = metadata
|
|
251
|
+
|
|
252
|
+
def __enter__(self):
|
|
253
|
+
"""Enter context: emit step start."""
|
|
254
|
+
if self.reporter:
|
|
255
|
+
self.reporter.emit_step_start(self.step_name, **self.metadata)
|
|
256
|
+
return self
|
|
257
|
+
|
|
258
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
259
|
+
"""Exit context: emit step complete."""
|
|
260
|
+
if self.reporter:
|
|
261
|
+
self.reporter.emit_step_complete(self.step_name, **self.metadata)
|
|
262
|
+
return False # Don't suppress exceptions
|
deepfabric/prompts.py
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
class TreePromptBuilder:
|
|
2
|
+
"""Build dynamic prompts for topic tree expansion with domain-specific examples."""
|
|
3
|
+
|
|
4
|
+
# Domain-specific expansion examples
|
|
5
|
+
EXAMPLES = {
|
|
6
|
+
"general": [
|
|
7
|
+
{
|
|
8
|
+
"path": ["Technology", "Artificial Intelligence"],
|
|
9
|
+
"subtopics": [
|
|
10
|
+
"machine learning",
|
|
11
|
+
"neural networks",
|
|
12
|
+
"computer vision",
|
|
13
|
+
"natural language processing",
|
|
14
|
+
"robotics",
|
|
15
|
+
],
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": ["Entertainment", "Movies", "Actors"],
|
|
19
|
+
"subtopics": [
|
|
20
|
+
"Tom Hanks",
|
|
21
|
+
"Meryl Streep",
|
|
22
|
+
"Leonardo DiCaprio",
|
|
23
|
+
"Jennifer Lawrence",
|
|
24
|
+
"Denzel Washington",
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
"conversational": [
|
|
29
|
+
{
|
|
30
|
+
"path": ["Small Talk Topics"],
|
|
31
|
+
"subtopics": [
|
|
32
|
+
"weather",
|
|
33
|
+
"weekend plans",
|
|
34
|
+
"hobbies",
|
|
35
|
+
"family",
|
|
36
|
+
"books",
|
|
37
|
+
"food",
|
|
38
|
+
"music",
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": ["Small Talk Topics", "Family"],
|
|
43
|
+
"subtopics": [
|
|
44
|
+
"parents",
|
|
45
|
+
"grandparents",
|
|
46
|
+
"siblings",
|
|
47
|
+
"family traditions",
|
|
48
|
+
"family vacations",
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"path": ["Small Talk Topics", "Hobbies", "Cooking"],
|
|
53
|
+
"subtopics": [
|
|
54
|
+
"recipes",
|
|
55
|
+
"asian food",
|
|
56
|
+
"favourite dishes",
|
|
57
|
+
"cookbooks",
|
|
58
|
+
"kitchen gadgets",
|
|
59
|
+
"vegan cooking",
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
"technical": [
|
|
64
|
+
{
|
|
65
|
+
"path": ["Programming"],
|
|
66
|
+
"subtopics": [
|
|
67
|
+
"algorithms",
|
|
68
|
+
"data structures",
|
|
69
|
+
"debugging",
|
|
70
|
+
"testing",
|
|
71
|
+
"version control",
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"path": ["Programming", "Python"],
|
|
76
|
+
"subtopics": ["pandas", "flask", "pytest", "asyncio", "django"],
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
"educational": [
|
|
80
|
+
{
|
|
81
|
+
"path": ["Mathematics"],
|
|
82
|
+
"subtopics": ["algebra", "geometry", "calculus", "statistics", "probability"],
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"path": ["Mathematics", "Algebra"],
|
|
86
|
+
"subtopics": [
|
|
87
|
+
"linear equations",
|
|
88
|
+
"quadratic functions",
|
|
89
|
+
"polynomials",
|
|
90
|
+
"matrices",
|
|
91
|
+
"systems",
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@classmethod
|
|
98
|
+
def build_expansion_prompt(
|
|
99
|
+
cls,
|
|
100
|
+
topic_path: list[str],
|
|
101
|
+
num_subtopics: int,
|
|
102
|
+
system_prompt: str = "",
|
|
103
|
+
domain: str = "general",
|
|
104
|
+
) -> str:
|
|
105
|
+
"""Build a topic expansion prompt with relevant examples."""
|
|
106
|
+
|
|
107
|
+
path_str = " -> ".join(f'"{topic}"' for topic in topic_path)
|
|
108
|
+
examples = cls._format_examples(cls.EXAMPLES.get(domain, cls.EXAMPLES["general"]))
|
|
109
|
+
|
|
110
|
+
return f"""Generate {num_subtopics} subtopics for training data organization.
|
|
111
|
+
|
|
112
|
+
Task: Create diverse but related subtopics that expand on the given topic path.
|
|
113
|
+
|
|
114
|
+
Examples:
|
|
115
|
+
{examples}
|
|
116
|
+
|
|
117
|
+
Context: {system_prompt}
|
|
118
|
+
|
|
119
|
+
Topic path: {path_str}
|
|
120
|
+
Generate {num_subtopics} subtopics as a Python list. Return only the list, nothing else."""
|
|
121
|
+
|
|
122
|
+
@classmethod
|
|
123
|
+
def _format_examples(cls, examples: list) -> str:
|
|
124
|
+
"""Format examples for inclusion in prompt."""
|
|
125
|
+
formatted = []
|
|
126
|
+
for ex in examples[:3]: # Limit to 3 examples
|
|
127
|
+
path_str = " -> ".join(f'"{topic}"' for topic in ex["path"])
|
|
128
|
+
subtopics_str = str(ex["subtopics"])
|
|
129
|
+
formatted.append(f"Path: {path_str}\nSubtopics: {subtopics_str}")
|
|
130
|
+
return "\n\n".join(formatted)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
# Structured Agent Tool-Calling Prompt Builder
|
|
134
|
+
class AgentPromptBuilder:
|
|
135
|
+
"""Build structured prompts for agent tool-calling training."""
|
|
136
|
+
|
|
137
|
+
@staticmethod
|
|
138
|
+
def build_tool_context_prompt(tool_registry, max_tools_per_query: int = 3) -> str:
|
|
139
|
+
"""Build a minimal context prompt that relies on structured generation.
|
|
140
|
+
|
|
141
|
+
Returns a template with {{{{instructions}}}} and {{{{subtopics}}}} placeholders
|
|
142
|
+
that will be filled in by build_prompt() with actual topic paths from the tree.
|
|
143
|
+
"""
|
|
144
|
+
tool_signatures = []
|
|
145
|
+
for tool in tool_registry.tools:
|
|
146
|
+
tool_signatures.append(f"- {tool.to_signature()}")
|
|
147
|
+
|
|
148
|
+
return f"""Generate a realistic agent training example with tool usage reasoning.
|
|
149
|
+
|
|
150
|
+
Available tools:
|
|
151
|
+
{chr(10).join(tool_signatures)}
|
|
152
|
+
|
|
153
|
+
You may use 1 to {max_tools_per_query} tools to complete the task.
|
|
154
|
+
|
|
155
|
+
Focus on WHY each tool is selected and HOW parameters are constructed.
|
|
156
|
+
|
|
157
|
+
ARGUMENT REQUIREMENTS:
|
|
158
|
+
- All argument values must be concrete and realistic (e.g., owner="acme-corp", repo="web-app", issue_number=42)
|
|
159
|
+
- Never use template placeholders like {{{{owner}}}} or {{{{repo}}}}
|
|
160
|
+
- Never use null values - omit optional parameters entirely if not needed
|
|
161
|
+
- String fields must contain actual content, not empty strings
|
|
162
|
+
|
|
163
|
+
{{{{{{{{instructions}}}}}}}}
|
|
164
|
+
{{{{{{{{subtopics}}}}}}}}
|
|
165
|
+
|
|
166
|
+
Generate a complete agent reasoning example using structured output with tool_executions list."""
|
|
167
|
+
|
|
168
|
+
@staticmethod
|
|
169
|
+
def build_multi_turn_context_prompt(tool_registry, max_tools_per_query: int = 3) -> str:
|
|
170
|
+
"""Build context for multi-turn conversations.
|
|
171
|
+
|
|
172
|
+
Returns a template with {{{{instructions}}}} and {{{{subtopics}}}} placeholders
|
|
173
|
+
that will be filled in by build_prompt() with actual topic paths from the tree.
|
|
174
|
+
"""
|
|
175
|
+
tool_signatures = []
|
|
176
|
+
for tool in tool_registry.tools:
|
|
177
|
+
tool_signatures.append(f"- {tool.to_signature()}")
|
|
178
|
+
|
|
179
|
+
return f"""Generate a multi-turn agent conversation with evolving tool usage.
|
|
180
|
+
|
|
181
|
+
Available tools:
|
|
182
|
+
{chr(10).join(tool_signatures)}
|
|
183
|
+
|
|
184
|
+
You may use 1 to {max_tools_per_query} tools per query. Show tool dependencies and reasoning across conversation turns.
|
|
185
|
+
|
|
186
|
+
ARGUMENT REQUIREMENTS:
|
|
187
|
+
- All argument values must be concrete and realistic (e.g., owner="acme-corp", repo="web-app", issue_number=42)
|
|
188
|
+
- Never use template placeholders like {{{{owner}}}} or {{{{repo}}}}
|
|
189
|
+
- Never use null values - omit optional parameters entirely if not needed
|
|
190
|
+
- String fields must contain actual content, not empty strings
|
|
191
|
+
|
|
192
|
+
{{{{{{{{instructions}}}}}}}}
|
|
193
|
+
{{{{{{{{subtopics}}}}}}}}
|
|
194
|
+
|
|
195
|
+
Generate a complete multi-turn conversation using structured output with tool_executions list."""
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
# Simplified prompts that delegate to structured generation
|
|
199
|
+
AGENT_COT_TOOLS_PROMPT = """Generate an agent tool-calling training example using the available tool definitions.
|
|
200
|
+
|
|
201
|
+
You may use multiple tools (up to the specified limit) to complete the task.
|
|
202
|
+
|
|
203
|
+
Focus on the reasoning process: WHY each tool is selected, HOW parameters are constructed, and WHAT results are expected.
|
|
204
|
+
|
|
205
|
+
Create realistic scenarios that teach proper tool reasoning patterns and multi-tool orchestration.
|
|
206
|
+
|
|
207
|
+
{{{{instructions}}}}
|
|
208
|
+
{{{{examples}}}}
|
|
209
|
+
{{{{subtopics}}}}"""
|
|
210
|
+
|
|
211
|
+
AGENT_COT_HYBRID_PROMPT = """Generate agent tool-calling examples with rich CoT reasoning traces and tool execution.
|
|
212
|
+
|
|
213
|
+
You may use multiple tools (up to the specified limit) to complete the task.
|
|
214
|
+
|
|
215
|
+
Combine natural language reasoning with structured step-by-step traces that include:
|
|
216
|
+
- Chain of thought analysis
|
|
217
|
+
- Structured reasoning steps with thoughts and actions
|
|
218
|
+
- Clear tool selection and parameter reasoning
|
|
219
|
+
- Multiple tool executions with results
|
|
220
|
+
|
|
221
|
+
Focus on teaching both the reasoning process AND multi-tool usage patterns.
|
|
222
|
+
|
|
223
|
+
{{{{instructions}}}}
|
|
224
|
+
{{{{examples}}}}
|
|
225
|
+
{{{{subtopics}}}}"""
|
|
226
|
+
|
|
227
|
+
AGENT_COT_MULTI_TURN_PROMPT = """Generate a multi-turn agent conversation with tool usage across turns.
|
|
228
|
+
|
|
229
|
+
Show how reasoning evolves: tool dependencies, progressive refinement, and result synthesis.
|
|
230
|
+
|
|
231
|
+
Create realistic tool chaining patterns and decision-making processes.
|
|
232
|
+
|
|
233
|
+
{{{{instructions}}}}
|
|
234
|
+
{{{{examples}}}}
|
|
235
|
+
{{{{subtopics}}}}"""
|
|
236
|
+
|
|
237
|
+
CONVERSATION_GENERATION_PROMPT = """Generate a training conversation for a language model with this system prompt:
|
|
238
|
+
|
|
239
|
+
<system_prompt>
|
|
240
|
+
{{{{system_prompt}}}}
|
|
241
|
+
</system_prompt>
|
|
242
|
+
|
|
243
|
+
Create a realistic single q&a that demonstrates the system's capabilities. The conversation should:
|
|
244
|
+
- Start with a user question/request
|
|
245
|
+
- Have the assistant respond helpfully according to the system prompt
|
|
246
|
+
- Be natural and educational
|
|
247
|
+
|
|
248
|
+
{{{{instructions}}}}
|
|
249
|
+
{{{{examples}}}}
|
|
250
|
+
{{{{subtopics}}}}
|
|
251
|
+
|
|
252
|
+
Generate one training sample as question and answer."""
|
|
253
|
+
|
|
254
|
+
GRAPH_EXPANSION_PROMPT = """
|
|
255
|
+
You are an expert in knowledge graph generation. Your task is to expand a topic into a set of subtopics. For each subtopic, you should also identify if it connects to any other existing topics in the graph.
|
|
256
|
+
|
|
257
|
+
Here is the current state of the graph:
|
|
258
|
+
{{current_graph_summary}}
|
|
259
|
+
|
|
260
|
+
You are expanding the topic: "{{current_topic}}"
|
|
261
|
+
|
|
262
|
+
Generate a list of {{num_subtopics}} subtopics. For each subtopic, provide:
|
|
263
|
+
1. A "topic" string - the name of the new subtopic
|
|
264
|
+
2. A "connections" list of IDs of existing topics it should connect to for creating cross-links (use empty list if no connections)
|
|
265
|
+
"""
|
|
266
|
+
|
|
267
|
+
# Chain of Thought prompts for reasoning-based dataset generation
|
|
268
|
+
FREETEXT_COT_PROMPT = """Generate a reasoning problem that requires analytical thinking to solve.
|
|
269
|
+
|
|
270
|
+
Create problems involving mathematics, logic, science, or analytical reasoning that can be solved through clear thinking steps.
|
|
271
|
+
|
|
272
|
+
{{{{instructions}}}}
|
|
273
|
+
{{{{examples}}}}
|
|
274
|
+
{{{{subtopics}}}}"""
|
|
275
|
+
|
|
276
|
+
STRUCTURED_COT_PROMPT = """Generate a training conversation that demonstrates systematic problem-solving.
|
|
277
|
+
|
|
278
|
+
Create realistic dialogues where complex problems are solved through methodical reasoning.
|
|
279
|
+
|
|
280
|
+
{{{{instructions}}}}
|
|
281
|
+
{{{{examples}}}}
|
|
282
|
+
{{{{subtopics}}}}"""
|
|
283
|
+
|
|
284
|
+
HYBRID_COT_PROMPT = """Generate problems that require analytical and systematic thinking.
|
|
285
|
+
|
|
286
|
+
Create challenging reasoning problems suitable for training systematic problem-solving skills.
|
|
287
|
+
|
|
288
|
+
{{{{instructions}}}}
|
|
289
|
+
{{{{examples}}}}
|
|
290
|
+
{{{{subtopics}}}}"""
|