coding package¶
Submodules¶
coding.code_cache module¶
coding.code_executor module¶
- class coding.code_executor.CodeExecutor[source]¶
Bases:
object
- execute_and_save(code: str, output_path: str, certain_file_types: list[str] | None = None, timeout: int = 10) tuple[bool, str] [source]¶
Executes the provided code and saves the output artifacts to the specified directory.
- Parameters:
code (str) – The Python code to execute.
output_path (str) – The directory where the output artifacts should be saved.
certain_file_types (list, optional) – A list of file extensions to save. If None, all files are saved.
timeout (int, optional) – The maximum execution time in seconds. Defaults to 10 seconds.
- Returns:
A tuple containing a boolean indicating success and a message string.
- Return type:
tuple
- execute_code(code: str, timeout: int = 10, test_run: bool = False) tuple[bool, dict] [source]¶
Executes the provided Python code in a temporary directory and returns the results.
- Parameters:
code (str) – The Python code to execute.
timeout (int, optional) – The maximum time (in seconds) to allow for the execution. Defaults to 10.
- Returns:
A tuple where the first element is a boolean indicating success (True) or failure (False), and the second element is a dictionary containing the results. If successful, the dictionary will contain the standard output and any generated files. If unsuccessful, it will contain an error message.
- Return type:
tuple[bool, dict]
- validate_code_with_flake8(code: str) tuple[bool, str | None] [source]¶
Check the syntax of the generated code using flake8.
- Parameters:
code (str) – The generated code to be checked.
- Returns:
- A tuple containing:
bool: True if the code is syntactically correct, False otherwise.
str | None: Error message if there is a syntax error, None otherwise.
- Return type:
tuple[bool, str | None]
coding.code_generator module¶
- class coding.code_generator.CodeGenerator(api_key, api_base_url, model_name, org_id, prompt_templates, **model_kwargs)[source]¶
Bases:
LanguageModel
- fix_code(code: str, design_goal: DesignGoal, feedbacks: List[str] | None) str [source]¶
Fixes the code using error feedback, leveraging dochelper to query documentation insights if necessary.
- generate_code(design_goal: DesignGoal, plan: dict = None) str [source]¶
Generates a build123d script based on the design goal and plan, focusing purely on geometric information.
- generate_or_fix_code(design_goal: DesignGoal, plan: dict = None, existing_code: str = None, feedbacks: List[str] = None) str [source]¶
Generate new code or fix existing code based on the provided design goal, plan, and feedback.
- Parameters:
design_goal (DesignGoal) – The design goal containing text and decomposition details.
plan (dict, optional) – A dictionary containing the coding plan, typically including a ‘plan’ key.
existing_code (str, optional) – The existing code that needs to be fixed or improved.
feedbacks (List[str], optional) – A list of feedback messages or errors from previous iterations.
- Returns:
The generated or fixed code as a string. Returns None if no code could be generated or fixed.
- Return type:
str
- patch_code_to_export(code, format: Literal['stl', 'step'] = 'stl', target_output_dir=None) tuple[str, str] [source]¶
This method appends code to center the 3D model at the origin and export it in the desired format (STL or STEP). The exported file is saved in the specified directory or the current working directory if none is provided.
- Parameters:
code (str) – The original code to be extended with export functionality.
format (Literal["stl", "step"], optional) – The desired export format. Defaults to “stl”.
target_output_dir (str, optional) – The directory where the exported 3D file will be saved.
None (If)
directory. (the file will be saved in the current working)
- Returns:
- A tuple containing:
patched_code: The extended code with the added export functionality.
target_output_dir: The directory where the exported 3D file will be saved.
- Return type:
tuple[str, str]
coding.coder module¶
- class coding.coder.Coder(api_key, api_base_url, model_name, org_id, prompt_templates, code_master_config: dict = None, max_coding_iterations: int = 10, **model_kwargs)[source]¶
Bases:
object