pdd-cli 0.0.38__py3-none-any.whl → 0.0.40__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.
Potentially problematic release.
This version of pdd-cli might be problematic. Click here for more details.
- pdd/__init__.py +5 -4
- pdd/auto_deps_main.py +14 -7
- pdd/auto_include.py +147 -98
- pdd/auto_update.py +24 -11
- pdd/bug_main.py +5 -2
- pdd/bug_to_unit_test.py +9 -2
- pdd/change.py +32 -22
- pdd/change_main.py +14 -10
- pdd/cli.py +11 -1
- pdd/cmd_test_main.py +7 -3
- pdd/code_generator.py +7 -1
- pdd/code_generator_main.py +9 -3
- pdd/conflicts_in_prompts.py +7 -2
- pdd/conflicts_main.py +6 -2
- pdd/context_generator.py +20 -3
- pdd/context_generator_main.py +2 -0
- pdd/continue_generation.py +8 -2
- pdd/crash_main.py +51 -31
- pdd/detect_change.py +8 -4
- pdd/detect_change_main.py +3 -0
- pdd/fix_code_loop.py +7 -2
- pdd/fix_code_module_errors.py +5 -2
- pdd/fix_error_loop.py +6 -2
- pdd/fix_errors_from_unit_tests.py +11 -6
- pdd/fix_main.py +4 -0
- pdd/fix_verification_errors.py +8 -3
- pdd/fix_verification_errors_loop.py +9 -3
- pdd/fix_verification_main.py +37 -31
- pdd/generate_test.py +10 -4
- pdd/get_extension.py +23 -9
- pdd/git_update.py +5 -3
- pdd/increase_tests.py +5 -2
- pdd/insert_includes.py +8 -2
- pdd/preprocess_main.py +10 -3
- pdd/process_csv_change.py +8 -2
- pdd/split.py +15 -7
- pdd/split_main.py +2 -0
- pdd/summarize_directory.py +4 -0
- pdd/trace.py +9 -5
- pdd/trace_main.py +5 -4
- pdd/unfinished_prompt.py +6 -1
- pdd/update_main.py +6 -3
- pdd/update_prompt.py +8 -4
- pdd/xml_tagger.py +10 -5
- {pdd_cli-0.0.38.dist-info → pdd_cli-0.0.40.dist-info}/METADATA +4 -4
- {pdd_cli-0.0.38.dist-info → pdd_cli-0.0.40.dist-info}/RECORD +50 -50
- {pdd_cli-0.0.38.dist-info → pdd_cli-0.0.40.dist-info}/WHEEL +0 -0
- {pdd_cli-0.0.38.dist-info → pdd_cli-0.0.40.dist-info}/entry_points.txt +0 -0
- {pdd_cli-0.0.38.dist-info → pdd_cli-0.0.40.dist-info}/licenses/LICENSE +0 -0
- {pdd_cli-0.0.38.dist-info → pdd_cli-0.0.40.dist-info}/top_level.txt +0 -0
pdd/change.py
CHANGED
|
@@ -6,7 +6,7 @@ from pydantic import BaseModel, Field
|
|
|
6
6
|
from .preprocess import preprocess
|
|
7
7
|
from .load_prompt_template import load_prompt_template
|
|
8
8
|
from .llm_invoke import llm_invoke
|
|
9
|
-
from . import EXTRACTION_STRENGTH
|
|
9
|
+
from . import EXTRACTION_STRENGTH, DEFAULT_STRENGTH, DEFAULT_TIME
|
|
10
10
|
|
|
11
11
|
console = Console()
|
|
12
12
|
|
|
@@ -17,8 +17,10 @@ def change(
|
|
|
17
17
|
input_prompt: str,
|
|
18
18
|
input_code: str,
|
|
19
19
|
change_prompt: str,
|
|
20
|
-
strength: float,
|
|
21
|
-
temperature: float,
|
|
20
|
+
strength: float = DEFAULT_STRENGTH,
|
|
21
|
+
temperature: float = 0.0,
|
|
22
|
+
time: float = DEFAULT_TIME,
|
|
23
|
+
budget: float = 5.0, # Note: budget is in the spec but not used. Keeping for now.
|
|
22
24
|
verbose: bool = False
|
|
23
25
|
) -> Tuple[str, float, str]:
|
|
24
26
|
"""
|
|
@@ -30,26 +32,28 @@ def change(
|
|
|
30
32
|
change_prompt (str): Instructions for modifying the input prompt
|
|
31
33
|
strength (float): The strength parameter for the LLM model (0-1)
|
|
32
34
|
temperature (float): The temperature parameter for the LLM model
|
|
33
|
-
|
|
35
|
+
time (float): The time budget for LLM calls.
|
|
36
|
+
budget (float): The budget for the operation (currently unused directly by llm_invoke).
|
|
37
|
+
verbose (bool): Whether to print out detailed information.
|
|
34
38
|
|
|
35
39
|
Returns:
|
|
36
40
|
Tuple[str, float, str]: (modified prompt, total cost, model name)
|
|
37
41
|
"""
|
|
38
42
|
try:
|
|
39
43
|
# Step 1: Load prompt templates
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
change_llm_prompt_template = load_prompt_template("change_LLM")
|
|
45
|
+
extract_prompt_template = load_prompt_template("extract_prompt_change_LLM")
|
|
42
46
|
|
|
43
|
-
if not all([
|
|
47
|
+
if not all([change_llm_prompt_template, extract_prompt_template]):
|
|
44
48
|
raise ValueError("Failed to load prompt templates")
|
|
45
49
|
|
|
46
50
|
# Step 2: Preprocess the change_LLM prompt
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
processed_change_llm_template = preprocess(change_llm_prompt_template, recursive=False, double_curly_brackets=False)
|
|
52
|
+
processed_change_prompt_content = preprocess(change_prompt, recursive=False, double_curly_brackets=False)
|
|
49
53
|
|
|
50
54
|
# Input validation
|
|
51
|
-
if not all([input_prompt, input_code,
|
|
52
|
-
raise ValueError("Missing required input parameters")
|
|
55
|
+
if not all([input_prompt, input_code, processed_change_prompt_content]):
|
|
56
|
+
raise ValueError("Missing required input parameters after preprocessing")
|
|
53
57
|
if not (0 <= strength <= 1):
|
|
54
58
|
raise ValueError("Strength must be between 0 and 1")
|
|
55
59
|
|
|
@@ -61,14 +65,15 @@ def change(
|
|
|
61
65
|
console.print(Panel("Running change prompt through LLM...", style="blue"))
|
|
62
66
|
|
|
63
67
|
change_response = llm_invoke(
|
|
64
|
-
prompt=
|
|
68
|
+
prompt=processed_change_llm_template,
|
|
65
69
|
input_json={
|
|
66
70
|
"input_prompt": input_prompt,
|
|
67
71
|
"input_code": input_code,
|
|
68
|
-
"change_prompt":
|
|
72
|
+
"change_prompt": processed_change_prompt_content
|
|
69
73
|
},
|
|
70
74
|
strength=strength,
|
|
71
75
|
temperature=temperature,
|
|
76
|
+
time=time,
|
|
72
77
|
verbose=verbose
|
|
73
78
|
)
|
|
74
79
|
|
|
@@ -85,10 +90,11 @@ def change(
|
|
|
85
90
|
console.print(Panel("Extracting modified prompt...", style="blue"))
|
|
86
91
|
|
|
87
92
|
extract_response = llm_invoke(
|
|
88
|
-
prompt=
|
|
93
|
+
prompt=extract_prompt_template,
|
|
89
94
|
input_json={"llm_output": change_response["result"]},
|
|
90
|
-
strength=EXTRACTION_STRENGTH,
|
|
95
|
+
strength=EXTRACTION_STRENGTH,
|
|
91
96
|
temperature=temperature,
|
|
97
|
+
time=time,
|
|
92
98
|
verbose=verbose,
|
|
93
99
|
output_pydantic=ExtractedPrompt
|
|
94
100
|
)
|
|
@@ -110,23 +116,27 @@ def change(
|
|
|
110
116
|
return modified_prompt, total_cost, final_model_name
|
|
111
117
|
|
|
112
118
|
except Exception as e:
|
|
113
|
-
|
|
119
|
+
# Conditionally print error if verbose
|
|
120
|
+
if verbose:
|
|
121
|
+
console.print(f"[red]Error in change function: {str(e)}[/red]")
|
|
114
122
|
raise
|
|
115
123
|
|
|
116
124
|
def main():
|
|
117
125
|
"""Example usage of the change function"""
|
|
118
126
|
try:
|
|
119
127
|
# Example inputs
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
128
|
+
input_prompt_content = "Write a function that adds two numbers"
|
|
129
|
+
input_code_content = "def add(a, b):\n return a + b"
|
|
130
|
+
change_prompt_content = "Make the function handle negative numbers explicitly"
|
|
123
131
|
|
|
124
132
|
modified_prompt, cost, model = change(
|
|
125
|
-
input_prompt=
|
|
126
|
-
input_code=
|
|
127
|
-
change_prompt=
|
|
133
|
+
input_prompt=input_prompt_content,
|
|
134
|
+
input_code=input_code_content,
|
|
135
|
+
change_prompt=change_prompt_content,
|
|
128
136
|
strength=0.7,
|
|
129
137
|
temperature=0.7,
|
|
138
|
+
time=DEFAULT_TIME,
|
|
139
|
+
budget=10.0,
|
|
130
140
|
verbose=True
|
|
131
141
|
)
|
|
132
142
|
|
pdd/change_main.py
CHANGED
|
@@ -10,7 +10,7 @@ from .construct_paths import construct_paths
|
|
|
10
10
|
from .change import change as change_func
|
|
11
11
|
from .process_csv_change import process_csv_change
|
|
12
12
|
from .get_extension import get_extension
|
|
13
|
-
from . import DEFAULT_STRENGTH #
|
|
13
|
+
from . import DEFAULT_STRENGTH, DEFAULT_TIME # Added DEFAULT_TIME
|
|
14
14
|
|
|
15
15
|
# Import Rich for pretty printing
|
|
16
16
|
from rich import print as rprint
|
|
@@ -66,6 +66,7 @@ def change_main(
|
|
|
66
66
|
quiet: bool = ctx.obj.get("quiet", False)
|
|
67
67
|
strength: float = ctx.obj.get("strength", DEFAULT_STRENGTH)
|
|
68
68
|
temperature: float = ctx.obj.get("temperature", 0.0)
|
|
69
|
+
time_budget: float = ctx.obj.get("time", DEFAULT_TIME) # Added time_budget
|
|
69
70
|
# --- Get language and extension from context ---
|
|
70
71
|
# These are crucial for knowing the target code file types, especially in CSV mode
|
|
71
72
|
target_language: str = ctx.obj.get("language", "") # Get from context
|
|
@@ -215,6 +216,7 @@ def change_main(
|
|
|
215
216
|
csv_file=change_prompt_file,
|
|
216
217
|
strength=strength,
|
|
217
218
|
temperature=temperature,
|
|
219
|
+
time=time_budget, # Pass time_budget
|
|
218
220
|
code_directory=input_code, # Pass the directory path
|
|
219
221
|
language=csv_target_language,
|
|
220
222
|
extension=extension,
|
|
@@ -254,16 +256,18 @@ def change_main(
|
|
|
254
256
|
return msg, 0.0, ""
|
|
255
257
|
|
|
256
258
|
try:
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
259
|
+
# Call the imported change function
|
|
260
|
+
result_message, total_cost, model_name = change_func(
|
|
261
|
+
change_prompt_content,
|
|
262
|
+
input_code_content,
|
|
263
|
+
input_prompt_content,
|
|
264
|
+
strength,
|
|
265
|
+
temperature,
|
|
266
|
+
time_budget, # Pass time_budget
|
|
267
|
+
budget=budget,
|
|
268
|
+
quiet=quiet
|
|
264
269
|
)
|
|
265
|
-
|
|
266
|
-
success = True # Assume success if no exception
|
|
270
|
+
success = True # Assume success if no exception
|
|
267
271
|
logger.info("Single prompt change successful.")
|
|
268
272
|
except Exception as e:
|
|
269
273
|
msg = f"Error during prompt modification: {e}"
|
pdd/cli.py
CHANGED
|
@@ -11,7 +11,7 @@ from rich.theme import Theme
|
|
|
11
11
|
from rich.markup import MarkupError, escape
|
|
12
12
|
|
|
13
13
|
# --- Relative Imports for Internal Modules ---
|
|
14
|
-
from . import DEFAULT_STRENGTH, __version__
|
|
14
|
+
from . import DEFAULT_STRENGTH, __version__, DEFAULT_TIME
|
|
15
15
|
from .auto_deps_main import auto_deps_main
|
|
16
16
|
from .auto_update import auto_update
|
|
17
17
|
from .bug_main import bug_main
|
|
@@ -89,6 +89,13 @@ def handle_error(e: Exception, command_name: str, quiet: bool):
|
|
|
89
89
|
show_default=True,
|
|
90
90
|
help="Set the temperature of the AI model.",
|
|
91
91
|
)
|
|
92
|
+
@click.option(
|
|
93
|
+
"--time",
|
|
94
|
+
type=click.FloatRange(0.0, 1.0),
|
|
95
|
+
default=None,
|
|
96
|
+
show_default=True,
|
|
97
|
+
help="Controls reasoning allocation for LLMs (0.0-1.0). Uses DEFAULT_TIME if None.",
|
|
98
|
+
)
|
|
92
99
|
@click.option(
|
|
93
100
|
"--verbose",
|
|
94
101
|
is_flag=True,
|
|
@@ -131,6 +138,7 @@ def cli(
|
|
|
131
138
|
output_cost: Optional[str],
|
|
132
139
|
review_examples: bool,
|
|
133
140
|
local: bool,
|
|
141
|
+
time: Optional[float], # Type hint is Optional[float]
|
|
134
142
|
):
|
|
135
143
|
"""
|
|
136
144
|
Main entry point for the PDD CLI. Handles global options and initializes context.
|
|
@@ -148,6 +156,8 @@ def cli(
|
|
|
148
156
|
ctx.obj["output_cost"] = output_cost
|
|
149
157
|
ctx.obj["review_examples"] = review_examples
|
|
150
158
|
ctx.obj["local"] = local
|
|
159
|
+
# Use DEFAULT_TIME if time is not provided
|
|
160
|
+
ctx.obj["time"] = time if time is not None else DEFAULT_TIME
|
|
151
161
|
|
|
152
162
|
# Suppress verbose if quiet is enabled
|
|
153
163
|
if quiet:
|
pdd/cmd_test_main.py
CHANGED
|
@@ -49,6 +49,7 @@ def cmd_test_main(
|
|
|
49
49
|
verbose = ctx.obj["verbose"]
|
|
50
50
|
strength = ctx.obj["strength"]
|
|
51
51
|
temperature = ctx.obj["temperature"]
|
|
52
|
+
time = ctx.obj.get("time")
|
|
52
53
|
|
|
53
54
|
if verbose:
|
|
54
55
|
print(f"[bold blue]Prompt file:[/bold blue] {prompt_file}")
|
|
@@ -97,9 +98,11 @@ def cmd_test_main(
|
|
|
97
98
|
unit_test, total_cost, model_name = generate_test(
|
|
98
99
|
input_strings["prompt_file"],
|
|
99
100
|
input_strings["code_file"],
|
|
100
|
-
strength,
|
|
101
|
-
temperature,
|
|
102
|
-
|
|
101
|
+
strength=strength,
|
|
102
|
+
temperature=temperature,
|
|
103
|
+
time=time,
|
|
104
|
+
language=language,
|
|
105
|
+
verbose=verbose
|
|
103
106
|
)
|
|
104
107
|
except Exception as e:
|
|
105
108
|
print(f"[bold red]Error generating tests: {e}[/bold red]")
|
|
@@ -121,6 +124,7 @@ def cmd_test_main(
|
|
|
121
124
|
language=language,
|
|
122
125
|
strength=strength,
|
|
123
126
|
temperature=temperature,
|
|
127
|
+
time=time,
|
|
124
128
|
verbose=verbose,
|
|
125
129
|
)
|
|
126
130
|
except Exception as e:
|
pdd/code_generator.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Tuple
|
|
1
|
+
from typing import Tuple, Optional
|
|
2
2
|
from rich.console import Console
|
|
3
3
|
from . import EXTRACTION_STRENGTH
|
|
4
4
|
from .preprocess import preprocess
|
|
@@ -14,6 +14,7 @@ def code_generator(
|
|
|
14
14
|
language: str,
|
|
15
15
|
strength: float,
|
|
16
16
|
temperature: float = 0.0,
|
|
17
|
+
time: Optional[float] = None,
|
|
17
18
|
verbose: bool = False,
|
|
18
19
|
preprocess_prompt: bool = True,
|
|
19
20
|
) -> Tuple[str, float, str]:
|
|
@@ -25,6 +26,7 @@ def code_generator(
|
|
|
25
26
|
language (str): The target programming language
|
|
26
27
|
strength (float): The strength of the LLM model (0 to 1)
|
|
27
28
|
temperature (float, optional): The temperature for the LLM model. Defaults to 0.0
|
|
29
|
+
time (Optional[float], optional): The time for the LLM model. Defaults to None
|
|
28
30
|
verbose (bool, optional): Whether to print detailed information. Defaults to False
|
|
29
31
|
|
|
30
32
|
Returns:
|
|
@@ -65,6 +67,7 @@ def code_generator(
|
|
|
65
67
|
input_json={},
|
|
66
68
|
strength=strength,
|
|
67
69
|
temperature=temperature,
|
|
70
|
+
time=time,
|
|
68
71
|
verbose=verbose
|
|
69
72
|
)
|
|
70
73
|
initial_output = response['result']
|
|
@@ -79,6 +82,7 @@ def code_generator(
|
|
|
79
82
|
prompt_text=last_chunk,
|
|
80
83
|
strength=0.5,
|
|
81
84
|
temperature=0.0,
|
|
85
|
+
time=time,
|
|
82
86
|
verbose=verbose
|
|
83
87
|
)
|
|
84
88
|
total_cost += check_cost
|
|
@@ -92,6 +96,7 @@ def code_generator(
|
|
|
92
96
|
llm_output=initial_output,
|
|
93
97
|
strength=strength,
|
|
94
98
|
temperature=temperature,
|
|
99
|
+
time=time,
|
|
95
100
|
verbose=verbose
|
|
96
101
|
)
|
|
97
102
|
total_cost += continue_cost
|
|
@@ -107,6 +112,7 @@ def code_generator(
|
|
|
107
112
|
language=language,
|
|
108
113
|
strength=EXTRACTION_STRENGTH,
|
|
109
114
|
temperature=0.0,
|
|
115
|
+
time=time,
|
|
110
116
|
verbose=verbose
|
|
111
117
|
)
|
|
112
118
|
total_cost += postprocess_cost
|
pdd/code_generator_main.py
CHANGED
|
@@ -410,11 +410,17 @@ def code_generator_main(
|
|
|
410
410
|
if current_execution_is_local:
|
|
411
411
|
if verbose: console.print("Executing code generator locally...")
|
|
412
412
|
generated_code_content, total_cost, model_name = local_code_generator_func(
|
|
413
|
-
prompt=prompt_content,
|
|
414
|
-
|
|
413
|
+
prompt=prompt_content,
|
|
414
|
+
language=language,
|
|
415
|
+
strength=strength,
|
|
416
|
+
temperature=temperature,
|
|
417
|
+
time=time_budget,
|
|
418
|
+
verbose=verbose,
|
|
419
|
+
preprocess_prompt=True
|
|
415
420
|
)
|
|
421
|
+
was_incremental_operation = False
|
|
416
422
|
if verbose:
|
|
417
|
-
console.print(Panel(f"
|
|
423
|
+
console.print(Panel(f"Full generation successful. Model: {model_name}, Cost: ${total_cost:.6f}", title="[green]Local Success[/green]", expand=False))
|
|
418
424
|
|
|
419
425
|
if generated_code_content is not None:
|
|
420
426
|
if output_path:
|
pdd/conflicts_in_prompts.py
CHANGED
|
@@ -4,7 +4,7 @@ from rich import print as rprint
|
|
|
4
4
|
from rich.markdown import Markdown
|
|
5
5
|
from .load_prompt_template import load_prompt_template
|
|
6
6
|
from .llm_invoke import llm_invoke
|
|
7
|
-
from . import EXTRACTION_STRENGTH
|
|
7
|
+
from . import EXTRACTION_STRENGTH, DEFAULT_STRENGTH, DEFAULT_TIME
|
|
8
8
|
|
|
9
9
|
class ConflictChange(BaseModel):
|
|
10
10
|
prompt_name: str = Field(description="Name of the prompt that needs to be changed")
|
|
@@ -16,8 +16,9 @@ class ConflictResponse(BaseModel):
|
|
|
16
16
|
def conflicts_in_prompts(
|
|
17
17
|
prompt1: str,
|
|
18
18
|
prompt2: str,
|
|
19
|
-
strength: float =
|
|
19
|
+
strength: float = DEFAULT_STRENGTH,
|
|
20
20
|
temperature: float = 0,
|
|
21
|
+
time: float = DEFAULT_TIME,
|
|
21
22
|
verbose: bool = False
|
|
22
23
|
) -> Tuple[List[dict], float, str]:
|
|
23
24
|
"""
|
|
@@ -28,6 +29,7 @@ def conflicts_in_prompts(
|
|
|
28
29
|
prompt2 (str): Second prompt to compare
|
|
29
30
|
strength (float): Model strength (0-1)
|
|
30
31
|
temperature (float): Model temperature (0-1)
|
|
32
|
+
time (float): Time budget for LLM calls.
|
|
31
33
|
verbose (bool): Whether to print detailed information
|
|
32
34
|
|
|
33
35
|
Returns:
|
|
@@ -66,6 +68,7 @@ def conflicts_in_prompts(
|
|
|
66
68
|
input_json=input_json,
|
|
67
69
|
strength=strength,
|
|
68
70
|
temperature=temperature,
|
|
71
|
+
time=time,
|
|
69
72
|
verbose=verbose
|
|
70
73
|
)
|
|
71
74
|
|
|
@@ -88,6 +91,7 @@ def conflicts_in_prompts(
|
|
|
88
91
|
input_json=extract_input,
|
|
89
92
|
strength=EXTRACTION_STRENGTH,
|
|
90
93
|
temperature=temperature,
|
|
94
|
+
time=time,
|
|
91
95
|
output_pydantic=ConflictResponse,
|
|
92
96
|
verbose=verbose
|
|
93
97
|
)
|
|
@@ -125,6 +129,7 @@ def main():
|
|
|
125
129
|
prompt2=prompt2,
|
|
126
130
|
strength=0.7,
|
|
127
131
|
temperature=0,
|
|
132
|
+
time=DEFAULT_TIME,
|
|
128
133
|
verbose=True
|
|
129
134
|
)
|
|
130
135
|
|
pdd/conflicts_main.py
CHANGED
|
@@ -6,6 +6,7 @@ from rich import print as rprint
|
|
|
6
6
|
|
|
7
7
|
from .construct_paths import construct_paths
|
|
8
8
|
from .conflicts_in_prompts import conflicts_in_prompts
|
|
9
|
+
from . import DEFAULT_TIME, DEFAULT_STRENGTH
|
|
9
10
|
|
|
10
11
|
def conflicts_main(ctx: click.Context, prompt1: str, prompt2: str, output: Optional[str], verbose: bool = False) -> Tuple[List[Dict], float, str]:
|
|
11
12
|
"""
|
|
@@ -40,13 +41,16 @@ def conflicts_main(ctx: click.Context, prompt1: str, prompt2: str, output: Optio
|
|
|
40
41
|
prompt2_content = input_strings["prompt2"]
|
|
41
42
|
|
|
42
43
|
# Analyze conflicts
|
|
43
|
-
strength = ctx.obj.get('strength',
|
|
44
|
+
strength = ctx.obj.get('strength', DEFAULT_STRENGTH)
|
|
44
45
|
temperature = ctx.obj.get('temperature', 0)
|
|
46
|
+
time_budget = ctx.obj.get('time', DEFAULT_TIME)
|
|
45
47
|
conflicts, total_cost, model_name = conflicts_in_prompts(
|
|
46
48
|
prompt1_content,
|
|
47
49
|
prompt2_content,
|
|
48
50
|
strength,
|
|
49
|
-
temperature
|
|
51
|
+
temperature,
|
|
52
|
+
time_budget,
|
|
53
|
+
verbose
|
|
50
54
|
)
|
|
51
55
|
|
|
52
56
|
# Replace prompt1 and prompt2 with actual file paths
|
pdd/context_generator.py
CHANGED
|
@@ -5,9 +5,18 @@ from .llm_invoke import llm_invoke
|
|
|
5
5
|
from .unfinished_prompt import unfinished_prompt
|
|
6
6
|
from .continue_generation import continue_generation
|
|
7
7
|
from .postprocess import postprocess
|
|
8
|
-
from . import EXTRACTION_STRENGTH
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
from . import EXTRACTION_STRENGTH, DEFAULT_TIME
|
|
9
|
+
from typing import Optional
|
|
10
|
+
|
|
11
|
+
def context_generator(
|
|
12
|
+
code_module: str,
|
|
13
|
+
prompt: str,
|
|
14
|
+
language: str = "python",
|
|
15
|
+
strength: float = 0.5,
|
|
16
|
+
temperature: float = 0,
|
|
17
|
+
time: Optional[float] = DEFAULT_TIME,
|
|
18
|
+
verbose: bool = False,
|
|
19
|
+
) -> tuple:
|
|
11
20
|
"""
|
|
12
21
|
Generates a concise example on how to use a given code module properly.
|
|
13
22
|
|
|
@@ -17,6 +26,7 @@ def context_generator(code_module: str, prompt: str, language: str = "python", s
|
|
|
17
26
|
language (str): The language of the code module. Default is "python".
|
|
18
27
|
strength (float): The strength of the LLM model to use. Default is 0.5. Range is between 0 and 1.
|
|
19
28
|
temperature (float): The temperature of the LLM model to use. Default is 0. Range is between 0 and 1.
|
|
29
|
+
time (Optional[float], optional): Time allocation for the LLM. Defaults to DEFAULT_TIME.
|
|
20
30
|
verbose (bool): Whether to print out the details of the function. Default is False.
|
|
21
31
|
|
|
22
32
|
Returns:
|
|
@@ -45,6 +55,9 @@ def context_generator(code_module: str, prompt: str, language: str = "python", s
|
|
|
45
55
|
return None, 0.0, None
|
|
46
56
|
|
|
47
57
|
try:
|
|
58
|
+
if verbose:
|
|
59
|
+
print(f"[bold blue]Generating example for language: {language}[/bold blue]")
|
|
60
|
+
|
|
48
61
|
# Step 1: Load and preprocess the 'example_generator_LLM' prompt template
|
|
49
62
|
prompt_template = load_prompt_template("example_generator_LLM")
|
|
50
63
|
if not prompt_template:
|
|
@@ -70,6 +83,7 @@ def context_generator(code_module: str, prompt: str, language: str = "python", s
|
|
|
70
83
|
},
|
|
71
84
|
strength=strength,
|
|
72
85
|
temperature=temperature,
|
|
86
|
+
time=time,
|
|
73
87
|
verbose=verbose
|
|
74
88
|
)
|
|
75
89
|
|
|
@@ -80,6 +94,7 @@ def context_generator(code_module: str, prompt: str, language: str = "python", s
|
|
|
80
94
|
prompt_text=last_600_chars,
|
|
81
95
|
strength=0.5,
|
|
82
96
|
temperature=temperature,
|
|
97
|
+
time=time,
|
|
83
98
|
verbose=verbose
|
|
84
99
|
)
|
|
85
100
|
except Exception as e:
|
|
@@ -96,6 +111,7 @@ def context_generator(code_module: str, prompt: str, language: str = "python", s
|
|
|
96
111
|
llm_output=llm_response['result'],
|
|
97
112
|
strength=strength,
|
|
98
113
|
temperature=temperature,
|
|
114
|
+
time=time,
|
|
99
115
|
verbose=verbose
|
|
100
116
|
)
|
|
101
117
|
total_cost = llm_response['cost'] + unfinished_cost + continue_cost
|
|
@@ -113,6 +129,7 @@ def context_generator(code_module: str, prompt: str, language: str = "python", s
|
|
|
113
129
|
language=language,
|
|
114
130
|
strength=EXTRACTION_STRENGTH,
|
|
115
131
|
temperature=temperature,
|
|
132
|
+
time=time,
|
|
116
133
|
verbose=verbose
|
|
117
134
|
)
|
|
118
135
|
total_cost += postprocess_cost
|
pdd/context_generator_main.py
CHANGED
|
@@ -40,12 +40,14 @@ def context_generator_main(ctx: click.Context, prompt_file: str, code_file: str,
|
|
|
40
40
|
# Generate example code
|
|
41
41
|
strength = ctx.obj.get('strength', 0.5)
|
|
42
42
|
temperature = ctx.obj.get('temperature', 0)
|
|
43
|
+
time = ctx.obj.get('time')
|
|
43
44
|
example_code, total_cost, model_name = context_generator(
|
|
44
45
|
language=language,
|
|
45
46
|
code_module=code_content,
|
|
46
47
|
prompt=prompt_content,
|
|
47
48
|
strength=strength,
|
|
48
49
|
temperature=temperature,
|
|
50
|
+
time=time,
|
|
49
51
|
verbose=ctx.obj.get('verbose', False)
|
|
50
52
|
)
|
|
51
53
|
|
pdd/continue_generation.py
CHANGED
|
@@ -6,7 +6,7 @@ from .load_prompt_template import load_prompt_template
|
|
|
6
6
|
from .preprocess import preprocess
|
|
7
7
|
from .llm_invoke import llm_invoke
|
|
8
8
|
from .unfinished_prompt import unfinished_prompt
|
|
9
|
-
from . import EXTRACTION_STRENGTH
|
|
9
|
+
from . import EXTRACTION_STRENGTH, DEFAULT_TIME
|
|
10
10
|
|
|
11
11
|
console = Console()
|
|
12
12
|
|
|
@@ -23,6 +23,7 @@ def continue_generation(
|
|
|
23
23
|
llm_output: str,
|
|
24
24
|
strength: float,
|
|
25
25
|
temperature: float,
|
|
26
|
+
time: float = DEFAULT_TIME,
|
|
26
27
|
verbose: bool = False
|
|
27
28
|
) -> Tuple[str, float, str]:
|
|
28
29
|
"""
|
|
@@ -33,6 +34,7 @@ def continue_generation(
|
|
|
33
34
|
llm_output (str): Current output from the LLM to be checked and continued.
|
|
34
35
|
strength (float): Strength parameter for the LLM model (0-1).
|
|
35
36
|
temperature (float): Temperature parameter for the LLM model (0-1).
|
|
37
|
+
time (float): Time budget for LLM calls.
|
|
36
38
|
verbose (bool): Whether to print detailed information.
|
|
37
39
|
|
|
38
40
|
Returns:
|
|
@@ -72,8 +74,9 @@ def continue_generation(
|
|
|
72
74
|
trim_start_response = llm_invoke(
|
|
73
75
|
prompt=processed_prompts['trim_start'],
|
|
74
76
|
input_json={"LLM_OUTPUT": llm_output},
|
|
75
|
-
strength=
|
|
77
|
+
strength=EXTRACTION_STRENGTH,
|
|
76
78
|
temperature=0,
|
|
79
|
+
time=time,
|
|
77
80
|
output_pydantic=TrimResultsStartOutput,
|
|
78
81
|
verbose=verbose
|
|
79
82
|
)
|
|
@@ -95,6 +98,7 @@ def continue_generation(
|
|
|
95
98
|
},
|
|
96
99
|
strength=strength,
|
|
97
100
|
temperature=temperature,
|
|
101
|
+
time=time,
|
|
98
102
|
verbose=verbose
|
|
99
103
|
)
|
|
100
104
|
|
|
@@ -108,6 +112,7 @@ def continue_generation(
|
|
|
108
112
|
prompt_text=last_chunk,
|
|
109
113
|
strength=0.5,
|
|
110
114
|
temperature=0,
|
|
115
|
+
time=time,
|
|
111
116
|
verbose=verbose
|
|
112
117
|
)
|
|
113
118
|
total_cost += check_cost
|
|
@@ -124,6 +129,7 @@ def continue_generation(
|
|
|
124
129
|
},
|
|
125
130
|
strength=EXTRACTION_STRENGTH,
|
|
126
131
|
temperature=0,
|
|
132
|
+
time=time,
|
|
127
133
|
output_pydantic=TrimResultsOutput,
|
|
128
134
|
verbose=verbose
|
|
129
135
|
)
|