pdd-cli 0.0.42__py3-none-any.whl → 0.0.90__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.
- pdd/__init__.py +4 -4
- pdd/agentic_common.py +863 -0
- pdd/agentic_crash.py +534 -0
- pdd/agentic_fix.py +1179 -0
- pdd/agentic_langtest.py +162 -0
- pdd/agentic_update.py +370 -0
- pdd/agentic_verify.py +183 -0
- pdd/auto_deps_main.py +15 -5
- pdd/auto_include.py +63 -5
- pdd/bug_main.py +3 -2
- pdd/bug_to_unit_test.py +2 -0
- pdd/change_main.py +11 -4
- pdd/cli.py +22 -1181
- pdd/cmd_test_main.py +80 -19
- pdd/code_generator.py +58 -18
- pdd/code_generator_main.py +672 -25
- pdd/commands/__init__.py +42 -0
- pdd/commands/analysis.py +248 -0
- pdd/commands/fix.py +140 -0
- pdd/commands/generate.py +257 -0
- pdd/commands/maintenance.py +174 -0
- pdd/commands/misc.py +79 -0
- pdd/commands/modify.py +230 -0
- pdd/commands/report.py +144 -0
- pdd/commands/templates.py +215 -0
- pdd/commands/utility.py +110 -0
- pdd/config_resolution.py +58 -0
- pdd/conflicts_main.py +8 -3
- pdd/construct_paths.py +281 -81
- pdd/context_generator.py +10 -2
- pdd/context_generator_main.py +113 -11
- pdd/continue_generation.py +47 -7
- pdd/core/__init__.py +0 -0
- pdd/core/cli.py +503 -0
- pdd/core/dump.py +554 -0
- pdd/core/errors.py +63 -0
- pdd/core/utils.py +90 -0
- pdd/crash_main.py +44 -11
- pdd/data/language_format.csv +71 -62
- pdd/data/llm_model.csv +20 -18
- pdd/detect_change_main.py +5 -4
- pdd/fix_code_loop.py +331 -77
- pdd/fix_error_loop.py +209 -60
- pdd/fix_errors_from_unit_tests.py +4 -3
- pdd/fix_main.py +75 -18
- pdd/fix_verification_errors.py +12 -100
- pdd/fix_verification_errors_loop.py +319 -272
- pdd/fix_verification_main.py +57 -17
- pdd/generate_output_paths.py +93 -10
- pdd/generate_test.py +16 -5
- pdd/get_jwt_token.py +48 -9
- pdd/get_run_command.py +73 -0
- pdd/get_test_command.py +68 -0
- pdd/git_update.py +70 -19
- pdd/increase_tests.py +7 -0
- pdd/incremental_code_generator.py +2 -2
- pdd/insert_includes.py +11 -3
- pdd/llm_invoke.py +1278 -110
- pdd/load_prompt_template.py +36 -10
- pdd/pdd_completion.fish +25 -2
- pdd/pdd_completion.sh +30 -4
- pdd/pdd_completion.zsh +79 -4
- pdd/postprocess.py +10 -3
- pdd/preprocess.py +228 -15
- pdd/preprocess_main.py +8 -5
- pdd/prompts/agentic_crash_explore_LLM.prompt +49 -0
- pdd/prompts/agentic_fix_explore_LLM.prompt +45 -0
- pdd/prompts/agentic_fix_harvest_only_LLM.prompt +48 -0
- pdd/prompts/agentic_fix_primary_LLM.prompt +85 -0
- pdd/prompts/agentic_update_LLM.prompt +1071 -0
- pdd/prompts/agentic_verify_explore_LLM.prompt +45 -0
- pdd/prompts/auto_include_LLM.prompt +98 -101
- pdd/prompts/change_LLM.prompt +1 -3
- pdd/prompts/detect_change_LLM.prompt +562 -3
- pdd/prompts/example_generator_LLM.prompt +22 -1
- pdd/prompts/extract_code_LLM.prompt +5 -1
- pdd/prompts/extract_program_code_fix_LLM.prompt +14 -2
- pdd/prompts/extract_prompt_update_LLM.prompt +7 -8
- pdd/prompts/extract_promptline_LLM.prompt +17 -11
- pdd/prompts/find_verification_errors_LLM.prompt +6 -0
- pdd/prompts/fix_code_module_errors_LLM.prompt +16 -4
- pdd/prompts/fix_errors_from_unit_tests_LLM.prompt +6 -41
- pdd/prompts/fix_verification_errors_LLM.prompt +22 -0
- pdd/prompts/generate_test_LLM.prompt +21 -6
- pdd/prompts/increase_tests_LLM.prompt +1 -2
- pdd/prompts/insert_includes_LLM.prompt +1181 -6
- pdd/prompts/split_LLM.prompt +1 -62
- pdd/prompts/trace_LLM.prompt +25 -22
- pdd/prompts/unfinished_prompt_LLM.prompt +85 -1
- pdd/prompts/update_prompt_LLM.prompt +22 -1
- pdd/prompts/xml_convertor_LLM.prompt +3246 -7
- pdd/pytest_output.py +188 -21
- pdd/python_env_detector.py +151 -0
- pdd/render_mermaid.py +236 -0
- pdd/setup_tool.py +648 -0
- pdd/simple_math.py +2 -0
- pdd/split_main.py +3 -2
- pdd/summarize_directory.py +56 -7
- pdd/sync_determine_operation.py +918 -186
- pdd/sync_main.py +82 -32
- pdd/sync_orchestration.py +1456 -453
- pdd/sync_tui.py +848 -0
- pdd/template_registry.py +264 -0
- pdd/templates/architecture/architecture_json.prompt +242 -0
- pdd/templates/generic/generate_prompt.prompt +174 -0
- pdd/trace.py +168 -12
- pdd/trace_main.py +4 -3
- pdd/track_cost.py +151 -61
- pdd/unfinished_prompt.py +49 -3
- pdd/update_main.py +549 -67
- pdd/update_model_costs.py +2 -2
- pdd/update_prompt.py +19 -4
- {pdd_cli-0.0.42.dist-info → pdd_cli-0.0.90.dist-info}/METADATA +20 -7
- pdd_cli-0.0.90.dist-info/RECORD +153 -0
- {pdd_cli-0.0.42.dist-info → pdd_cli-0.0.90.dist-info}/licenses/LICENSE +1 -1
- pdd_cli-0.0.42.dist-info/RECORD +0 -115
- {pdd_cli-0.0.42.dist-info → pdd_cli-0.0.90.dist-info}/WHEEL +0 -0
- {pdd_cli-0.0.42.dist-info → pdd_cli-0.0.90.dist-info}/entry_points.txt +0 -0
- {pdd_cli-0.0.42.dist-info → pdd_cli-0.0.90.dist-info}/top_level.txt +0 -0
|
@@ -16,16 +16,575 @@
|
|
|
16
16
|
<example>
|
|
17
17
|
<input_example>
|
|
18
18
|
<prompt_list_example>
|
|
19
|
-
|
|
19
|
+
[{"PROMPT_NAME": "change_python.prompt", "PROMPT_DESCRIPTION": "% You are an expert Python Software Engineer. Your goal is to write a Python function, \"change\", that will modify an input_prompt into a modified_prompt per the change_prompt. All output to the console will be pretty printed using the Python Rich library. Ensure that the module imports are done using relative imports.\n\n% Here are the inputs and outputs of the function:\n Inputs:\n - 'input_prompt' - A string that contains the prompt that will be modified by the change_prompt.\n - 'input_code' - A string that contains the code that was generated from the input_prompt.\n - 'change_prompt' - A string that contains the instructions of how to modify the input_prompt.\n - 'strength': A float value representing the strength parameter for the LLM model, used to influence the model's behavior.\n - 'temperature': A float value representing the temperature parameter for the LLM model, used to control the randomness of the model's output.\n Outputs:\n - 'modified_prompt' - A string that contains the modified prompt that was changed based on the change_prompt.\n - 'total_cost': A float value representing the total cost of running the function.\n - 'model_name': A string representing the name of the selected LLM model.\n\n% Here is an example how to preprocess the prompt from a file: ```<./context/preprocess_example.py>```\n\n% Example usage of the Langchain LCEL program: ```<./context/langchain_lcel_example.py>```\n\n% Example of selecting a Langchain LLM and counting tokens using llm_selector: ```<./context/llm_selector_example.py>```\n\n% Steps to be followed by the function:\n 1. Load the '$PDD_PATH/prompts/xml/change_LLM.prompt' and '$PDD_PATH/prompts/extract_prompt_change_LLM.prompt' files.\n 2. Preprocess the change_LLM prompt using the preprocess function from the preprocess module and set double_curly_brackets to false.\n 3. Create a Langchain LCEL template from the processed change_LLM prompt to return a string output. \n 4. Use the llm_selector function for the LLM model and token counting.\n 5. Run the input_prompt through the model using Langchain LCEL:\n - a. Pass the following string parameters to the prompt during invocation: \n * 'input_prompt'\n * 'input_code'\n * 'change_prompt' (preprocess this with double_curly_brackets set to false)\n - b. Calculate the input and output token count using token_counter from llm_selector and pretty print the output of 4a, including the token count and estimated cost. The cost from llm_selector is in dollars per million tokens.\n 6. Create a Langchain LCEL template with strength .9 from the extract_prompt_change_LLM prompt that outputs JSON:\n - a. Pass the following string parameters to the prompt during invocation: 'llm_output' (this string is from Step 4).\n - b. Calculate input and output token count using token_counter from llm_selector and pretty print the running message with the token count and cost.\n - c. Use 'get' function to extract 'modified_prompt' key values using from the dictionary output.\n 7. Pretty print the extracted modified_prompt using Rich Markdown function. Include token counts and costs.\n 8. Return the 'modified_prompt' string, the total_cost of both invokes and model_name use for the change_LLM prompt.\n\n% Ensure the function handles edge cases, such as missing inputs or model errors, and provide clear error messages."}, {"PROMPT_NAME": "preprocess_python.prompt", "PROMPT_DESCRIPTION": "% You are an expert Python engineer. Your goal is to write a Python function, 'preprocess_prompt', that will preprocess the prompt from a prompt string for a LLM. This will use regular expressions to preprocess specific XML-like tags, if any, in the prompt. All output to the console will be pretty print using the Python rich library.\n\n% Here are the inputs and outputs of the function:\n Input: \n 'prompt' - A string that is the prompt to preprocess\n 'recursive' - A boolean that is True if the program needs to recursively process the includes in the prompt and False if it does not need to recursively process the prompt. Default is True.\n 'double_curly_brackets' - A boolean that is True if the curly brackets need to be doubled and False if they do not need to be doubled. Default is True.\n 'exclude_keys' - An optional list of strings that are excluded from the curly bracket doubling.\n Output: returns a string that is the preprocessed prompt, with any leading or trailing whitespace removed.\n\n% Here are the XML-like tags to preprocess, other tags will remain unmodified:\n 'include' - This tag will include the content of the file indicated in the include tag. The 'include tag' will be directly replaced with the content of the file in the prompt, without wrapping it in a new tag.\n 'pdd' - This tag indicates a comment and anything in this XML will be deleted from the string including the 'pdd' tags themselves.\n 'shell' - This tag indicates that there are shell commands to run. Capture all output of the shell commands and include it in the prompt but remove the shell tags.\n\n% Includes can be nested, that is there can be includes inside of the files of the includes and 'preprocess' should be called recursively on these include files if recursive is True. There are two ways of having includes in the prompt:\n 1. Will check to see if the file has any angle brackets in triple backticks. If so, it will read the included file indicated in the angle brackets and replace the angle brackets with the content of the included file. This will be done recursively until there are no more angle brackets in triple backticks. The program will then remove the angle brackets but leave the contents in the triple backticks.\n 2. The XML 'include' mentioned above.\n\n% If double_curly_brackets is True, the program will check to see if the file has any single curly brackets and if it does and the string in the curly brackets are not in the exclude_keys list, it will check to see if the curly brackets are already doubled before doubling the curly brackets.\n\n% The program should resolve file paths using the PDD_PATH environment variable. Implement a function 'get_file_path' that takes a file name and returns the full path using this environment variable.\n\n% Keep the user informed of the progress of the program by pretty printing messages."}, {"PROMPT_NAME": "unfinished_prompt_python.prompt", "PROMPT_DESCRIPTION": "% You are an expert Python engineer. Your goal is to write a python function called 'unfinished_prompt' that will determine if a given prompt is complete or needs to continue.\n\n% Here are the inputs and outputs of the function:\n Inputs:\n 'prompt_text' - A string containing the prompt text to analyze.\n 'strength' - A float that is the strength of the LLM model to use for the analysis. Default is 0.5.\n 'temperature' - A float that is the temperature of the LLM model to use for the analysis. Default is 0.\n Outputs:\n 'reasoning' - A string containing the structured reasoning for the completeness assessment.\n 'is_finished' - A boolean indicating whether the prompt is complete (True) or incomplete (False).\n 'total_cost' - A float that is the total cost of the analysis function. This is an optional output.\n 'model_name' - A string that is the name of the LLM model used for the analysis. This is an optional output.\n\n% Here is an example of a Langchain LCEL program: ```<./context/langchain_lcel_example.py>```\n\n% Here is an example how to select the Langchain llm and count tokens: ```<./context/llm_selector_example.py>```\n\n% Note: Use relative import for 'llm_selector' to ensure compatibility within the package structure (i.e. 'from .llm_selector') instead of 'from pdd.llm_selector'.\n\n% This function will do the following:\n Step 1. Use $PDD_PATH environment variable to get the path to the project. Load the '$PDD_PATH/prompts/unfinished_prompt_LLM.prompt' file.\n Step 2. Create a Langchain LCEL template from unfinished_prompt_LLM prompt so that it returns a JSON output.\n Step 3. Use the llm_selector function for the LLM model.\n Step 4. Run the prompt text through the model using Langchain LCEL.\n 4a. Pass the following string parameters to the prompt during invoke:\n - 'PROMPT_TEXT'\n 4b. Pretty print a message letting the user know it is running and how many tokens (using token_counter function from llm_selector) are in the prompt and the cost. The cost from llm_selector is in dollars per million tokens.\n 4c. The dictionary output of the LCEL will have the keys 'reasoning' and 'is_finished'. Be sure to access these keys using the get method with default error messages.\n 4d. Pretty print the reasoning and completion status using the rich library. Also, print the number of tokens in the result, the output token cost and the total_cost.\n Step 5. Return the 'reasoning' string and 'is_finished' boolean from the JSON output using 'get', and the 'total_cost' float, and 'model_name' string.\n\n% Ensure that the function handles potential errors gracefully, such as missing input parameters or issues with the LLM model responses.\n\n"}, {"PROMPT_NAME": "xml_tagger_python.prompt", "PROMPT_DESCRIPTION": "% You are an expert Python engineer. Your goal is to write a Python function, \"xml_tagger\", that will enhance a given LLM prompt by adding XML tags to improve its structure and readability.\n\n% You are an expert Python engineer.
|
|
20
|
+
|
|
21
|
+
% Code Style Requirements
|
|
22
|
+
- File must start with `from __future__ import annotations`.
|
|
23
|
+
- All functions must be fully type-hinted.
|
|
24
|
+
- Use `rich.console.Console` for all printing.
|
|
25
|
+
|
|
26
|
+
% Package Structure
|
|
27
|
+
- The function should be part of a Python package, using relative imports (single dot) for internal modules (e.g. 'from .module_name import module_name').
|
|
28
|
+
- The ./pdd/__init__.py file will have the EXTRACTION_STRENGTH, DEFAULT_STRENGTH, DEFAULT_TIME and other global constants. Example: ```from . import DEFAULT_STRENGTH```
|
|
29
|
+
|
|
30
|
+
% Error Handling
|
|
31
|
+
- Ensure the function handles edge cases, such as missing inputs or model errors, and provide clear error messages.\n\n% Here are the inputs and outputs of the function:\n Input: \n 'raw_prompt' - A string containing the prompt that needs XML tagging to improve its organization and clarity.\n 'strength' - A float value representing the strength parameter for the LLM model.\n 'temperature' - A float value representing the temperature parameter for the LLM model.\n Output: \n 'xml_tagged' - A string containing the prompt with properly added XML tags.\n 'total_cost' - A float representing the total cost of running the LCELs.\n 'model_name' - A string representing the name of the selected LLM model.\n\n% Here is an example of a LangChain Expression Language (LCEL) program: <lcel_example>import os
|
|
32
|
+
from langchain_core.prompts import PromptTemplate
|
|
33
|
+
from langchain_community.cache import SQLiteCache
|
|
34
|
+
from langchain_community.llms.mlx_pipeline import MLXPipeline
|
|
35
|
+
from langchain.globals import set_llm_cache
|
|
36
|
+
from langchain_core.output_parsers import JsonOutputParser, PydanticOutputParser # Parsers are only avaiable in langchain_core.output_parsers not langchain.output_parsers
|
|
37
|
+
from langchain_core.output_parsers import StrOutputParser
|
|
38
|
+
from langchain_core.prompts import ChatPromptTemplate
|
|
39
|
+
from langchain_core.runnables import RunnablePassthrough, ConfigurableField
|
|
40
|
+
|
|
41
|
+
from langchain_openai import AzureChatOpenAI
|
|
42
|
+
from langchain_fireworks import Fireworks
|
|
43
|
+
from langchain_anthropic import ChatAnthropic
|
|
44
|
+
from langchain_openai import ChatOpenAI # Chatbot and conversational tasks
|
|
45
|
+
from langchain_openai import OpenAI # General language tasks
|
|
46
|
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
|
47
|
+
from langchain_google_vertexai import ChatVertexAI
|
|
48
|
+
from langchain_groq import ChatGroq
|
|
49
|
+
from langchain_together import Together
|
|
50
|
+
|
|
51
|
+
from langchain.callbacks.base import BaseCallbackHandler
|
|
52
|
+
from langchain.schema import LLMResult
|
|
53
|
+
|
|
54
|
+
import json
|
|
55
|
+
|
|
56
|
+
from langchain_community.chat_models.mlx import ChatMLX
|
|
57
|
+
from langchain_core.messages import HumanMessage
|
|
58
|
+
|
|
59
|
+
from langchain_ollama.llms import OllamaLLM
|
|
60
|
+
from langchain_aws import ChatBedrockConverse
|
|
61
|
+
|
|
62
|
+
# Define a base output parser (e.g., PydanticOutputParser)
|
|
63
|
+
from pydantic import BaseModel, Field
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class CompletionStatusHandler(BaseCallbackHandler):
|
|
68
|
+
def __init__(self):
|
|
69
|
+
self.is_complete = False
|
|
70
|
+
self.finish_reason = None
|
|
71
|
+
self.input_tokens = None
|
|
72
|
+
self.output_tokens = None
|
|
73
|
+
|
|
74
|
+
def on_llm_end(self, response: LLMResult, **kwargs) -> None:
|
|
75
|
+
self.is_complete = True
|
|
76
|
+
if response.generations and response.generations[0]:
|
|
77
|
+
generation = response.generations[0][0]
|
|
78
|
+
self.finish_reason = generation.generation_info.get('finish_reason').lower()
|
|
79
|
+
|
|
80
|
+
# Extract token usage
|
|
81
|
+
if hasattr(generation.message, 'usage_metadata'):
|
|
82
|
+
usage_metadata = generation.message.usage_metadata
|
|
83
|
+
self.input_tokens = usage_metadata.get('input_tokens')
|
|
84
|
+
self.output_tokens = usage_metadata.get('output_tokens')
|
|
85
|
+
# print("response:",response)
|
|
86
|
+
print("Extracted information:")
|
|
87
|
+
print(f"Finish reason: {self.finish_reason}")
|
|
88
|
+
print(f"Input tokens: {self.input_tokens}")
|
|
89
|
+
print(f"Output tokens: {self.output_tokens}")
|
|
90
|
+
|
|
91
|
+
# Set up the LLM with the custom handler
|
|
92
|
+
handler = CompletionStatusHandler()
|
|
93
|
+
# Always setup cache to save money and increase speeds
|
|
94
|
+
set_llm_cache(SQLiteCache(database_path=".langchain.db"))
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
# Create the LCEL template. Make note of the variable {topic} which will be filled in later.
|
|
98
|
+
prompt_template = PromptTemplate.from_template("Tell me a joke about {topic}")
|
|
99
|
+
|
|
100
|
+
llm = ChatGoogleGenerativeAI(model="gemini-2.5-pro-exp-03-25", temperature=0, callbacks=[handler])
|
|
101
|
+
# Combine with a model and parser to output a string
|
|
102
|
+
chain = prompt_template |llm| StrOutputParser()
|
|
103
|
+
|
|
104
|
+
# Run the template. Notice that the input is a dictionary with a single key "topic" which feeds it into the above prompt template. This is needed because the prompt template has a variable {topic} which needs to be filled in when invoked.
|
|
105
|
+
result = chain.invoke({"topic": "cats"})
|
|
106
|
+
print("********Google:", result)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
llm = ChatVertexAI(model="gemini-2.5-pro-exp-03-25", temperature=0, callbacks=[handler])
|
|
110
|
+
# Combine with a model and parser to output a string
|
|
111
|
+
chain = prompt_template |llm| StrOutputParser()
|
|
112
|
+
|
|
113
|
+
# Run the template. Notice that the input is a dictionary with a single key "topic" which feeds it into the above prompt template. This is needed because the prompt template has a variable {topic} which needs to be filled in when invoked.
|
|
114
|
+
result = chain.invoke({"topic": "cats"})
|
|
115
|
+
print("********GoogleVertex:", result)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
# Define your desired data structure.
|
|
119
|
+
class Joke(BaseModel):
|
|
120
|
+
setup: str = Field(description="question to set up a joke")
|
|
121
|
+
punchline: str = Field(description="answer to resolve the joke")
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
# Set up a parser
|
|
125
|
+
parser = JsonOutputParser(pydantic_object=Joke)
|
|
126
|
+
|
|
127
|
+
# Create a prompt template
|
|
128
|
+
prompt = PromptTemplate(
|
|
129
|
+
template="Answer the user query.\n{format_instructions}\n{query}\n",
|
|
130
|
+
input_variables=["query"],
|
|
131
|
+
partial_variables={"format_instructions": parser.get_format_instructions()},
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
llm_no_struct = ChatOpenAI(model="gpt-4o-mini", temperature=0,
|
|
135
|
+
callbacks=[handler])
|
|
136
|
+
llm = llm_no_struct.with_structured_output(Joke) # with structured output forces the output to be a specific object, in this case Joke. Only OpenAI models have structured output
|
|
137
|
+
# Chain the components.
|
|
138
|
+
# The class `LLMChain` was deprecated in LangChain 0.1.17 and will be removed in 1.0. Use RunnableSequence, e.g., `prompt | llm` instead.
|
|
139
|
+
chain = prompt | llm
|
|
140
|
+
|
|
141
|
+
# Invoke the chain with a query.
|
|
142
|
+
# IMPORTANT: chain.run is now obsolete. Use chain.invoke instead.
|
|
143
|
+
result = chain.invoke({"query": "Tell me a joke about openai."})
|
|
144
|
+
print("4o mini JSON: ",result)
|
|
145
|
+
print(result.setup) # How to access the structured output
|
|
146
|
+
|
|
147
|
+
llm = ChatOpenAI(model="o1", temperature=1,
|
|
148
|
+
callbacks=[handler],model_kwargs = {"max_completion_tokens" : 1000})
|
|
149
|
+
# Chain the components.
|
|
150
|
+
# The class `LLMChain` was deprecated in LangChain 0.1.17 and will be removed in 1.0. Use RunnableSequence, e.g., `prompt | llm` instead.
|
|
151
|
+
chain = prompt | llm | parser
|
|
152
|
+
|
|
153
|
+
# Invoke the chain with a query.
|
|
154
|
+
# IMPORTANT: chain.run is now obsolete. Use chain.invoke instead.
|
|
155
|
+
result = chain.invoke({"query": "Tell me a joke about openai."})
|
|
156
|
+
print("o1 JSON: ",result)
|
|
157
|
+
|
|
158
|
+
# Get DEEPSEEK_API_KEY environmental variable
|
|
159
|
+
|
|
160
|
+
deepseek_api_key = os.getenv('DEEPSEEK_API_KEY')
|
|
161
|
+
|
|
162
|
+
# Ensure the API key is retrieved successfully
|
|
163
|
+
if deepseek_api_key is None:
|
|
164
|
+
raise ValueError("DEEPSEEK_API_KEY environment variable is not set")
|
|
165
|
+
|
|
166
|
+
llm = ChatOpenAI(
|
|
167
|
+
model='deepseek-chat',
|
|
168
|
+
openai_api_key=deepseek_api_key,
|
|
169
|
+
openai_api_base='https://api.deepseek.com',
|
|
170
|
+
temperature=0, callbacks=[handler]
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
# Chain the components
|
|
174
|
+
chain = prompt | llm | parser
|
|
175
|
+
|
|
176
|
+
# Invoke the chain with a query
|
|
177
|
+
result = chain.invoke({"query": "Write joke about deepseek."})
|
|
178
|
+
print("deepseek",result)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
# Set up a parser
|
|
182
|
+
parser = PydanticOutputParser(pydantic_object=Joke)
|
|
183
|
+
# Chain the components
|
|
184
|
+
chain = prompt | llm | parser
|
|
185
|
+
|
|
186
|
+
# Invoke the chain with a query
|
|
187
|
+
result = chain.invoke({"query": "Write joke about deepseek and pydantic."})
|
|
188
|
+
print("deepseek pydantic",result)
|
|
189
|
+
|
|
190
|
+
# Set up the Azure ChatOpenAI LLM instance
|
|
191
|
+
llm_no_struct = AzureChatOpenAI(
|
|
192
|
+
model="o4-mini",
|
|
193
|
+
temperature=1,
|
|
194
|
+
callbacks=[handler]
|
|
195
|
+
)
|
|
196
|
+
llm = llm_no_struct.with_structured_output(Joke) # with structured output forces the output to be a specific JSON format
|
|
197
|
+
# Chain the components: prompt | llm | parser
|
|
198
|
+
chain = prompt | llm # returns a Joke object
|
|
199
|
+
|
|
200
|
+
# Invoke the chain with a query
|
|
201
|
+
result = chain.invoke({"query": "What is Azure?"}) # Pass a dictionary if `invoke` expects it
|
|
202
|
+
print("Azure Result:", result)
|
|
203
|
+
|
|
204
|
+
# Set up a parser
|
|
205
|
+
parser = JsonOutputParser(pydantic_object=Joke)
|
|
206
|
+
|
|
207
|
+
llm = Fireworks(
|
|
208
|
+
model="accounts/fireworks/models/llama4-maverick-instruct-basic",
|
|
209
|
+
temperature=0, callbacks=[handler])
|
|
210
|
+
# Chain the components
|
|
211
|
+
chain = prompt | llm | parser
|
|
212
|
+
|
|
213
|
+
# Invoke the chain with a query
|
|
214
|
+
# no money in account
|
|
215
|
+
# result = chain.invoke({"query": "Tell me a joke about the president"})
|
|
216
|
+
# print("fireworks",result)
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
prompt = ChatPromptTemplate.from_template(
|
|
223
|
+
"Tell me a short joke about {topic}"
|
|
224
|
+
)
|
|
225
|
+
chat_openai = ChatOpenAI(model="gpt-3.5-turbo", callbacks=[handler])
|
|
226
|
+
openai = OpenAI(model="gpt-3.5-turbo-instruct", callbacks=[handler])
|
|
227
|
+
anthropic = ChatAnthropic(model="claude-2", callbacks=[handler])
|
|
228
|
+
model = (
|
|
229
|
+
chat_openai
|
|
230
|
+
.with_fallbacks([anthropic])
|
|
231
|
+
.configurable_alternatives(
|
|
232
|
+
ConfigurableField(id="model"),
|
|
233
|
+
default_key="chat_openai",
|
|
234
|
+
openai=openai,
|
|
235
|
+
anthropic=anthropic,
|
|
236
|
+
)
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
chain = (
|
|
240
|
+
{"topic": RunnablePassthrough()}
|
|
241
|
+
| prompt
|
|
242
|
+
| model
|
|
243
|
+
| StrOutputParser()
|
|
244
|
+
)
|
|
245
|
+
result = chain.invoke({"topic": "Tell me a joke about the president"})
|
|
246
|
+
print("config alt:",result)
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
llm = ChatAnthropic(
|
|
251
|
+
model="claude-3-7-sonnet-latest",
|
|
252
|
+
max_tokens=5000, # Total tokens for the response
|
|
253
|
+
thinking={"type": "enabled", "budget_tokens": 2000}, # Tokens for internal reasoning
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
response = llm.invoke("What is the cube root of 50.653?")
|
|
257
|
+
print(json.dumps(response.content, indent=2))
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
llm = ChatGroq(temperature=0, model_name="qwen-qwq-32b", callbacks=[handler])
|
|
261
|
+
system = "You are a helpful assistant."
|
|
262
|
+
human = "{text}"
|
|
263
|
+
prompt = ChatPromptTemplate.from_messages([("system", system), ("human", human)])
|
|
264
|
+
|
|
265
|
+
chain = prompt | llm | StrOutputParser()
|
|
266
|
+
print(chain.invoke({"text": "Explain the importance of low latency LLMs."}))
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
llm = Together(
|
|
270
|
+
model="meta-llama/Llama-3-70b-chat-hf",
|
|
271
|
+
max_tokens=500, callbacks=[handler]
|
|
272
|
+
)
|
|
273
|
+
chain = prompt | llm | StrOutputParser()
|
|
274
|
+
print(chain.invoke({"text": "Explain the importance of together.ai."}))
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
# Define a prompt template with placeholders for variables
|
|
278
|
+
prompt_template = PromptTemplate.from_template("Tell me a {adjective} joke about {content}.")
|
|
279
|
+
|
|
280
|
+
# Format the prompt with the variables
|
|
281
|
+
formatted_prompt = prompt_template.format(adjective="funny", content="data scientists")
|
|
282
|
+
|
|
283
|
+
# Print the formatted prompt
|
|
284
|
+
print(formatted_prompt)
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
# Set up the LLM with the custom handler
|
|
288
|
+
handler = CompletionStatusHandler()
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0.9, callbacks=[handler])
|
|
292
|
+
|
|
293
|
+
prompt = PromptTemplate.from_template("What is a good name for a company that makes {product}?")
|
|
294
|
+
|
|
295
|
+
chain = prompt | llm
|
|
296
|
+
|
|
297
|
+
# Invoke the chain
|
|
298
|
+
response = chain.invoke({"product":"colorful socks"})
|
|
299
|
+
|
|
300
|
+
# Check completion status
|
|
301
|
+
print(f"Is complete: {handler.is_complete}")
|
|
302
|
+
print(f"Finish reason: {handler.finish_reason}")
|
|
303
|
+
print(f"Response: {response}")
|
|
304
|
+
print(f"Input tokens: {handler.input_tokens}")
|
|
305
|
+
print(f"Output tokens: {handler.output_tokens}")
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
template = """Question: {question}"""
|
|
310
|
+
|
|
311
|
+
prompt = ChatPromptTemplate.from_template(template)
|
|
312
|
+
|
|
313
|
+
model = OllamaLLM(model="qwen2.5-coder:32b")
|
|
314
|
+
|
|
315
|
+
chain = prompt | model
|
|
316
|
+
|
|
317
|
+
output = chain.invoke({"question": "Write a python function that calculates Pi"})
|
|
318
|
+
print(output)
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
llm = MLXPipeline.from_model_id(
|
|
323
|
+
"mlx-community/quantized-gemma-2b-it",
|
|
324
|
+
pipeline_kwargs={"max_tokens": 10, "temp": 0.1},
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
chat_model = ChatMLX(llm=llm)
|
|
329
|
+
messages = [HumanMessage(content="What happens when an unstoppable force meets an immovable object?")]
|
|
330
|
+
response = chat_model.invoke(messages)
|
|
331
|
+
print(response.content)
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
llm = ChatBedrockConverse(
|
|
336
|
+
model_id="anthropic.claude-3-5-sonnet-20240620-v1:0",
|
|
337
|
+
# Additional parameters like temperature, max_tokens can be set here
|
|
338
|
+
)
|
|
339
|
+
|
|
340
|
+
messages = [HumanMessage(content="What happens when an unstoppable force meets an immovable sonnet?")]
|
|
341
|
+
response = llm.invoke(messages)
|
|
342
|
+
print(response.content)</lcel_example>\n\n% Here are examples of how to use internal modules:\n<internal_example_modules>\n % Example of selecting a Langchain LLM and counting tokens using llm_selector: <llm_selector_example>from pdd.llm_selector import llm_selector
|
|
343
|
+
|
|
344
|
+
def main() -> None:
|
|
345
|
+
"""
|
|
346
|
+
Main function to demonstrate the usage of the llm_selector function.
|
|
347
|
+
"""
|
|
348
|
+
# Define the strength and temperature parameters
|
|
349
|
+
strength: float = 0.5 # Example strength value for the LLM model
|
|
350
|
+
temperature: float = 1.0 # Example temperature value for the LLM model
|
|
351
|
+
|
|
352
|
+
try:
|
|
353
|
+
while strength <= 1.1:
|
|
354
|
+
# Call the llm_selector function with the specified strength and temperature
|
|
355
|
+
llm, token_counter, input_cost, output_cost, model_name = llm_selector(strength, temperature)
|
|
356
|
+
print(f"Strength: {strength}")
|
|
357
|
+
|
|
358
|
+
# Print the details of the selected LLM model
|
|
359
|
+
print(f"Selected LLM Model: {model_name}")
|
|
360
|
+
print(f"Input Cost per Million Tokens: {input_cost}")
|
|
361
|
+
print(f"Output Cost per Million Tokens: {output_cost}")
|
|
362
|
+
|
|
363
|
+
# Example usage of the token counter function
|
|
364
|
+
sample_text: str = "This is a sample text to count tokens."
|
|
365
|
+
token_count: int = token_counter(sample_text)
|
|
366
|
+
print(f"Token Count for Sample Text: {token_count}")
|
|
367
|
+
print(f"model_name: {model_name}")
|
|
368
|
+
strength += 0.05
|
|
369
|
+
except FileNotFoundError as e:
|
|
370
|
+
print(f"Error: {e}")
|
|
371
|
+
except ValueError as e:
|
|
372
|
+
print(f"Error: {e}")
|
|
373
|
+
|
|
374
|
+
if __name__ == "__main__":
|
|
375
|
+
main()</llm_selector_example>\n</internal_example_modules>\n\n% This program will use Langchain to do the following:\n Step 1. Use $PDD_PATH environment variable to get the path to the project. Load the '$PDD_PATH/prompts/xml_convertor_LLM.prompt' and '$PDD_PATH/prompts/extract_xml_LLM.prompt' files.\n Step 2. Create a Langchain LCEL template from xml_convertor prompt so that it returns a string output.\n Step 3. Use the llm_selector function for the LLM model and token counting.\n Step 4. Run the code through the model using Langchain LCEL. \n 4a. Pass the following string parameters to the prompt during invoke:\n - 'raw_prompt'\n 4b. Pretty print a message letting the user know it is running and how many tokens (using token_counter from llm_selector) are in the prompt and the cost. The cost from llm_selector is in dollars per million tokens. \n 4c. The string output of the LCEL will be 'xml_generated_analysis' that contains the tagged prompt.\n Step 5. The code result of the model will contain a mix of text and XML separated by triple backticks. Create a Langchain LCEL template but with a llm_selector with strength .8 from the extract_xml prompt that has a JSON output.\n 5a. Pass the following string parameters to the prompt during invoke:\n - 'xml_generated_analysis'\n 5b. Pretty print a message letting the user know it is running and how many tokens (using token_counter from llm_selector) are in the prompt and the cost. The cost from llm_selector is in dollars per million tokens.\n 5c. The JSON output of the LCEL will have the key 'xml_tagged' that contains the extracted tagged prompt.\n Step 6. Pretty print the extracted tagged prompt using the rich Markdown function. Also, print the number of tokens in the result and the cost.\n Step 7. Calculate the total cost by summing the costs from both LCEL runs.\n Step 8. Return the 'xml_tagged' string using 'get', the 'total_cost' and 'model_name'."}]
|
|
20
376
|
</prompt_list_example>
|
|
21
377
|
|
|
22
378
|
<change_description_example>
|
|
23
|
-
|
|
379
|
+
% Use context/python_preamble.prompt to make prompts more compact. Some prompts might already have this.
|
|
380
|
+
|
|
381
|
+
% Here is what is inside context/python_preamble.prompt:<preamble>% You are an expert Python engineer.
|
|
382
|
+
|
|
383
|
+
% Code Style Requirements
|
|
384
|
+
- File must start with `from __future__ import annotations`.
|
|
385
|
+
- All functions must be fully type-hinted.
|
|
386
|
+
- Use `rich.console.Console` for all printing.
|
|
387
|
+
|
|
388
|
+
% Package Structure
|
|
389
|
+
- The function should be part of a Python package, using relative imports (single dot) for internal modules (e.g. 'from .module_name import module_name').
|
|
390
|
+
- The ./pdd/__init__.py file will have the EXTRACTION_STRENGTH, DEFAULT_STRENGTH, DEFAULT_TIME and other global constants. Example: ```from . import DEFAULT_STRENGTH```
|
|
391
|
+
|
|
392
|
+
% Error Handling
|
|
393
|
+
- Ensure the function handles edge cases, such as missing inputs or model errors, and provide clear error messages.</preamble>
|
|
394
|
+
|
|
395
|
+
% Here is an example of this being done: <example>% You are an expert Python engineer. Your goal is to write a python function, "code_generator", that will compile a prompt into a code file.
|
|
396
|
+
|
|
397
|
+
You are an expert Python engineer working on the PDD Cloud project.
|
|
398
|
+
|
|
399
|
+
-------------------------------------------------------------------------------
|
|
400
|
+
Python Coding Standards (PDD Cloud)
|
|
401
|
+
-------------------------------------------------------------------------------
|
|
402
|
+
|
|
403
|
+
## Style
|
|
404
|
+
- Python 3.12, PEP 8 compliant
|
|
405
|
+
- Type hints required (from typing import Optional, List, Dict, Any, Tuple)
|
|
406
|
+
- Imports: standard lib -> third-party -> local (alphabetical within groups)
|
|
407
|
+
|
|
408
|
+
## Critical First Import
|
|
409
|
+
import function_import_setup # MUST be first import
|
|
410
|
+
|
|
411
|
+
This enables subprocess module resolution for Firebase Functions Framework.
|
|
412
|
+
All endpoint files must have this as their very first import statement.
|
|
413
|
+
|
|
414
|
+
## Standard Library Imports
|
|
415
|
+
import os
|
|
416
|
+
import logging
|
|
417
|
+
|
|
418
|
+
## Error Handling Pattern
|
|
419
|
+
Map exceptions to HTTP status codes:
|
|
420
|
+
- AuthenticationError -> 401 Unauthorized
|
|
421
|
+
- AuthorizationError -> 403 Forbidden
|
|
422
|
+
- ValidationError -> 400 Bad Request
|
|
423
|
+
- ResourceNotFoundError -> 404 Not Found
|
|
424
|
+
- DatabaseError / Exception -> 500 Internal Server Error
|
|
425
|
+
|
|
426
|
+
All error responses: {"error": "descriptive message"}
|
|
427
|
+
|
|
428
|
+
## Logging
|
|
429
|
+
logger = logging.getLogger(__name__)
|
|
430
|
+
|
|
431
|
+
## Response Format
|
|
432
|
+
Return tuple: (response_dict, status_code)
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
% Here are the inputs and outputs of the function:
|
|
436
|
+
Inputs:
|
|
437
|
+
'prompt' - A string containing the raw prompt to be processed.
|
|
438
|
+
'language' - A string that is the language type (e.g. python, bash) of file that will be outputed by the LLM.
|
|
439
|
+
'strength' - A float between 0 and 1 that is the strength of the LLM model to use.
|
|
440
|
+
'temperature' - A float that is the temperature of the LLM model to use. Default is 0.
|
|
441
|
+
'time' - A float in [0,1] or None that controls the thinking effort for the LLM model, passed to llm_invoke. Default is DEFAULT_TIME. If None, treat as DEFAULT_TIME before invoking llm_invoke.
|
|
442
|
+
'verbose' - A boolean that indicates whether to print out the details of the function. Default is False.
|
|
443
|
+
'preprocess_prompt' - A boolean that indicates whether to preprocess the prompt. Default is True.
|
|
444
|
+
Outputs:
|
|
445
|
+
'runnable_code' - A string that is runnable code
|
|
446
|
+
'total_cost' - A float that is the total cost of all LLM calls within this function (initial generation, unfinished check, continuation if used, and postprocess)
|
|
447
|
+
'model_name' - A string that is the name of the selected LLM model used for the main generation (or continuation). Postprocess may use a different model internally and does not change this value.
|
|
448
|
+
|
|
449
|
+
% Here is how to use the internal modules:
|
|
450
|
+
<internal_modules>
|
|
451
|
+
For running prompts with llm_invoke:
|
|
452
|
+
<llm_invoke_example>
|
|
453
|
+
[File not found: ../context/llm_invoke_example.py]
|
|
454
|
+
</llm_invoke_example>
|
|
455
|
+
|
|
456
|
+
For preprocessing prompts:
|
|
457
|
+
<preprocess_example>
|
|
458
|
+
[File not found: ../context/preprocess_example.py]
|
|
459
|
+
</preprocess_example>
|
|
460
|
+
|
|
461
|
+
For handling unfinished prompts:
|
|
462
|
+
<unfinished_prompt_example>
|
|
463
|
+
[File not found: ../context/unfinished_prompt_example.py]
|
|
464
|
+
</unfinished_prompt_example>
|
|
465
|
+
|
|
466
|
+
For continuing generation:
|
|
467
|
+
<continue_generation_example>
|
|
468
|
+
[File not found: ../context/continue_generation_example.py]
|
|
469
|
+
</continue_generation_example>
|
|
470
|
+
|
|
471
|
+
For postprocessing results:
|
|
472
|
+
<postprocess_example>
|
|
473
|
+
[File not found: ../context/postprocess_example.py]
|
|
474
|
+
</postprocess_example>
|
|
475
|
+
</internal_modules>
|
|
476
|
+
|
|
477
|
+
% This program will do the following:
|
|
478
|
+
Step 1. Conditionally preprocess the raw prompt using the preprocess function from the preprocess module based on the value of 'preprocess_prompt'. If 'preprocess_prompt' is True, preprocess the prompt; otherwise, use the raw prompt directly. When preprocessing, it is acceptable to enable options such as double_curly_brackets=True and recursive=False to preserve placeholders and avoid over-expansion.
|
|
479
|
+
|
|
480
|
+
Step 2. Generate the initial response as follows:
|
|
481
|
+
- If the prompt contains embedded data URLs (e.g., 'data:image/...;base64,...'), split the prompt into alternating text and image parts (preserving order) and call llm_invoke with messages=[{role: 'user', content: [{type: 'image_url', image_url: {url: ...}}, {type: 'text', text: ...}, ...]}] and the provided strength, temperature, time, and verbose.
|
|
482
|
+
- Otherwise, call llm_invoke with the (preprocessed or raw) prompt, input_json={}, and the provided strength, temperature, time, and verbose.
|
|
483
|
+
|
|
484
|
+
Step 3. Detect if the generation is incomplete using the unfinished_prompt function (use strength=0.5, temperature=0.0) by passing in the last 600 characters of the output of Step 2. Pass through language, time, and verbose.
|
|
485
|
+
- a. If incomplete, call the continue_generation function to complete the generation and set final_output to that result.
|
|
486
|
+
- b. Else, set final_output to the initial model output.
|
|
487
|
+
|
|
488
|
+
Step 4. Postprocess the final_output using the postprocess function from the postprocess module with the EXTRACTION_STRENGTH constant. Use temperature=0.0 and pass through language, time, and verbose.
|
|
489
|
+
|
|
490
|
+
Step 5. Return the runnable_code, total_cost and model_name.
|
|
491
|
+
|
|
492
|
+
% Validation and defaults:
|
|
493
|
+
- Validate non-empty 'prompt' and 'language'.
|
|
494
|
+
- Enforce 0 ≤ strength ≤ 1 and 0 ≤ temperature ≤ 2.
|
|
495
|
+
- Enforce 0 ≤ time ≤ 1 when provided; if time is None, substitute DEFAULT_TIME before llm_invoke.
|
|
496
|
+
</example>
|
|
24
497
|
</change_description_example>
|
|
25
498
|
</input_example>
|
|
26
499
|
|
|
27
500
|
<output_example>
|
|
28
|
-
|
|
501
|
+
1. **Impact of the Change and Potential Issues:**
|
|
502
|
+
|
|
503
|
+
The change description suggests using the contents of `context/python_preamble.prompt` to make prompts more compact. This preamble includes instructions for using relative imports, pretty printing with the Python Rich library, and handling edge cases. The main impact is to ensure consistency across prompts by centralizing common instructions, which can reduce redundancy and improve maintainability. Potential issues include ensuring that the preamble does not conflict with existing instructions in the prompts and that it is inserted in a way that maintains the logical flow of the prompt.
|
|
504
|
+
|
|
505
|
+
2. **Possible Implementation Plans:**
|
|
506
|
+
|
|
507
|
+
- **Plan A: Direct Inclusion of Preamble**
|
|
508
|
+
- **Pros:** Simplifies prompts by removing redundant instructions and directly including the preamble.
|
|
509
|
+
- **Cons:** May require significant restructuring of prompts to ensure logical flow and avoid redundancy.
|
|
510
|
+
|
|
511
|
+
- **Plan B: Conditional Inclusion Based on Existing Content**
|
|
512
|
+
- **Pros:** Only includes the preamble if similar instructions are not already present, minimizing disruption.
|
|
513
|
+
- **Cons:** Requires careful analysis of each prompt to determine if the preamble is needed, which can be time-consuming.
|
|
514
|
+
|
|
515
|
+
- **Plan C: Hybrid Approach**
|
|
516
|
+
- **Pros:** Combines the benefits of both plans by including the preamble where it adds value and retaining existing instructions where they are more specific or detailed.
|
|
517
|
+
- **Cons:** Complexity in deciding which parts of the preamble to include or exclude for each prompt.
|
|
518
|
+
|
|
519
|
+
3. **Analysis and Selection of the Best Plan:**
|
|
520
|
+
|
|
521
|
+
Plan C is the best approach as it allows for flexibility and ensures that the preamble is only included where it enhances the prompt. This minimizes redundancy and maintains the integrity of prompts that already have specific instructions. It also allows for a more tailored approach, ensuring that the preamble complements rather than conflicts with existing content.
|
|
522
|
+
|
|
523
|
+
4. **Prompt Analysis Based on Selected Plan:**
|
|
524
|
+
|
|
525
|
+
- **change_python.prompt:** This prompt already contains detailed instructions similar to those in the preamble. However, it can benefit from the preamble for consistency in handling edge cases and pretty printing.
|
|
526
|
+
- **preprocess_python.prompt:** This prompt can include the preamble to ensure consistent handling of edge cases and pretty printing.
|
|
527
|
+
- **unfinished_prompt_python.prompt:** This prompt can include the preamble to ensure consistent handling of edge cases and pretty printing.
|
|
528
|
+
- **xml_tagger_python.prompt:** This prompt already includes the preamble, so no changes are needed.
|
|
529
|
+
|
|
530
|
+
5. **Prompts That Need to Be Changed:**
|
|
531
|
+
|
|
532
|
+
- **change_python.prompt**
|
|
533
|
+
- **Instructions:**
|
|
534
|
+
- Insert the contents of the file `./context/python_preamble.prompt` immediately after the role and goal statement using 'include' XML tags.
|
|
535
|
+
- Remove any redundant instructions that are covered by the preamble, such as those related to pretty printing and handling edge cases.
|
|
536
|
+
- Ensure that the logical flow of the prompt is maintained and that any unique instructions specific to this prompt are retained.
|
|
537
|
+
- Here is what is inside context/python_preamble.prompt:<preamble>% You are an expert Python engineer.
|
|
538
|
+
|
|
539
|
+
% Code Style Requirements
|
|
540
|
+
- File must start with `from __future__ import annotations`.
|
|
541
|
+
- All functions must be fully type-hinted.
|
|
542
|
+
- Use `rich.console.Console` for all printing.
|
|
543
|
+
|
|
544
|
+
% Package Structure
|
|
545
|
+
- The function should be part of a Python package, using relative imports (single dot) for internal modules (e.g. 'from .module_name import module_name').
|
|
546
|
+
- The ./pdd/__init__.py file will have the EXTRACTION_STRENGTH, DEFAULT_STRENGTH, DEFAULT_TIME and other global constants. Example: ```from . import DEFAULT_STRENGTH```
|
|
547
|
+
|
|
548
|
+
% Error Handling
|
|
549
|
+
- Ensure the function handles edge cases, such as missing inputs or model errors, and provide clear error messages.</preamble>
|
|
550
|
+
|
|
551
|
+
- **preprocess_python.prompt**
|
|
552
|
+
- **Instructions:**
|
|
553
|
+
- Insert the contents of the file `./context/python_preamble.prompt` immediately after the role and goal statement using 'include' XML tags.
|
|
554
|
+
- Remove any redundant instructions that are covered by the preamble, such as those related to pretty printing and handling edge cases.
|
|
555
|
+
- Ensure that the logical flow of the prompt is maintained and that any unique instructions specific to this prompt are retained.
|
|
556
|
+
- Here is what is inside context/python_preamble.prompt:<preamble>% You are an expert Python engineer.
|
|
557
|
+
|
|
558
|
+
% Code Style Requirements
|
|
559
|
+
- File must start with `from __future__ import annotations`.
|
|
560
|
+
- All functions must be fully type-hinted.
|
|
561
|
+
- Use `rich.console.Console` for all printing.
|
|
562
|
+
|
|
563
|
+
% Package Structure
|
|
564
|
+
- The function should be part of a Python package, using relative imports (single dot) for internal modules (e.g. 'from .module_name import module_name').
|
|
565
|
+
- The ./pdd/__init__.py file will have the EXTRACTION_STRENGTH, DEFAULT_STRENGTH, DEFAULT_TIME and other global constants. Example: ```from . import DEFAULT_STRENGTH```
|
|
566
|
+
|
|
567
|
+
% Error Handling
|
|
568
|
+
- Ensure the function handles edge cases, such as missing inputs or model errors, and provide clear error messages.</preamble>
|
|
569
|
+
|
|
570
|
+
- **unfinished_prompt_python.prompt**
|
|
571
|
+
- **Instructions:**
|
|
572
|
+
- Insert the contents of the file `./context/python_preamble.prompt` immediately after the role and goal statement using 'include' XML tags.
|
|
573
|
+
- Remove any redundant instructions that are covered by the preamble, such as those related to pretty printing and handling edge cases.
|
|
574
|
+
- Ensure that the logical flow of the prompt is maintained and that any unique instructions specific to this prompt are retained.
|
|
575
|
+
- Here is what is inside context/python_preamble.prompt:<preamble>% You are an expert Python engineer.
|
|
576
|
+
|
|
577
|
+
% Code Style Requirements
|
|
578
|
+
- File must start with `from __future__ import annotations`.
|
|
579
|
+
- All functions must be fully type-hinted.
|
|
580
|
+
- Use `rich.console.Console` for all printing.
|
|
581
|
+
|
|
582
|
+
% Package Structure
|
|
583
|
+
- The function should be part of a Python package, using relative imports (single dot) for internal modules (e.g. 'from .module_name import module_name').
|
|
584
|
+
- The ./pdd/__init__.py file will have the EXTRACTION_STRENGTH, DEFAULT_STRENGTH, DEFAULT_TIME and other global constants. Example: ```from . import DEFAULT_STRENGTH```
|
|
585
|
+
|
|
586
|
+
% Error Handling
|
|
587
|
+
- Ensure the function handles edge cases, such as missing inputs or model errors, and provide clear error messages.</preamble>
|
|
29
588
|
</output_example>
|
|
30
589
|
</example>
|
|
31
590
|
|
|
@@ -4,7 +4,28 @@
|
|
|
4
4
|
|
|
5
5
|
% The language of the example should be in: <language_for_example>{language}</language_for_example>
|
|
6
6
|
|
|
7
|
+
% File path information:
|
|
8
|
+
- The code module file is located at: <code_module_file_path>{source_file_path}</code_module_file_path>
|
|
9
|
+
- The example file will be saved at: <example_file_path>{example_file_path}</example_file_path>
|
|
10
|
+
- The module name (without extension) is: <module_name>{module_name}</module_name>
|
|
11
|
+
|
|
12
|
+
% IMPORT INSTRUCTIONS: Use the appropriate import mechanism for the target language
|
|
13
|
+
- CRITICAL: Use the exact module_name provided in the file path information above - DO NOT use generic names like "greetings" or "module"
|
|
14
|
+
- Avoid package-style imports unless the file is actually in a package structure
|
|
15
|
+
- Import the specific functions/classes that are defined in the code module
|
|
16
|
+
- CRITICAL: Do not assume module names - use the exact module_name provided
|
|
17
|
+
- CRITICAL: Import the appropriate functions/classes from the module (e.g., if module_name is "simple_math", import "add", "subtract", etc.)
|
|
18
|
+
- CRITICAL: Never include hardcoded absolute paths like "/Users/username/project/examples/" in comments or code
|
|
19
|
+
- Use only relative path descriptions in comments (e.g., "relative to project root" or "relative to this script")
|
|
20
|
+
- Make the example portable across different development environments
|
|
21
|
+
- Use dynamic path resolution with os.path.dirname(__file__) and relative path construction
|
|
22
|
+
- In comments, describe file structure using relative terms, not absolute paths
|
|
23
|
+
- CRITICAL: The 'extracted_code' field must preserve all newlines using proper JSON escaping (\\n). The output must be valid JSON where multi-line code is represented with \\n escape sequences for each line break.
|
|
24
|
+
|
|
7
25
|
% Make sure the following happens:
|
|
8
26
|
- Document in detail what the input and output parameters in the doc strings
|
|
9
|
-
- Someone needs to be able to fully understand how to use the module from the example.
|
|
27
|
+
- Someone needs to be able to fully understand how to use the module from the example.
|
|
28
|
+
- Use correct import statements based on the actual file structure
|
|
29
|
+
- The example should be a complete, runnable script that imports from the actual module
|
|
30
|
+
- Include proper file path handling and module discovery if needed
|
|
10
31
|
<include>./context/example.prompt</include>
|
|
@@ -19,4 +19,8 @@
|
|
|
19
19
|
% Output a JSON object with the following keys:
|
|
20
20
|
- 'focus': String containing the focus of the generation.
|
|
21
21
|
- 'explanation': String explanation of why this block_type was the focus of the generation and explain any errors detected in the code, if a code type of block.
|
|
22
|
-
- 'extracted_code': String containing the entire generated and corrected block_type of focus.
|
|
22
|
+
- 'extracted_code': String containing the entire generated and corrected block_type of focus.
|
|
23
|
+
|
|
24
|
+
% CRITICAL: The 'extracted_code' field MUST preserve all newlines and indentation from the original code. In JSON, newlines must be represented as the escape sequence \n (backslash-n). Each line break in the code must appear as \n in the JSON string value. Do NOT concatenate lines together or remove line breaks. The extracted code must be properly formatted and runnable.
|
|
25
|
+
|
|
26
|
+
% IMPORTANT: Output ONLY the JSON object. Do not add any trailing whitespace or newlines after the closing brace.
|