Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.
make cc
thomashebrard1824978b5ac3
diff --git a/tests/test_pipelines/file.py b/tests/test_pipelines/file.pydeleted file mode 100644index 6560aac1b..000000000--- a/tests/test_pipelines/file.py+++ /dev/null@@ -1,75 +0,0 @@-from pathlib import Path-from typing import List--from cocode.pipelex_libraries.pipelines.doc_proofread.doc_proofread_models import CodebaseFileContent, DocumentationFile, FilePath--from pipelex.core.memory.working_memory import WorkingMemory-from pipelex.core.stuffs.stuff_content import ListContent-from pipelex.tools.func_registry import func_registry---def create_documentation_files_from_paths(doc_file_paths: List[str], doc_dir: str = "docs/") -> List[DocumentationFile]:- """Create DocumentationFile objects from file paths.-- Args:- doc_file_paths: List of documentation file paths- doc_dir: Base documentation directory (used for filtering)-- Returns:- List of DocumentationFile objects- """- doc_files: List[DocumentationFile] = []-- for file_path in doc_file_paths:- # Skip if not in doc_dir (when specified)- if doc_dir and doc_dir not in file_path:- continue-- try:- with open(file_path, "r", encoding="utf-8") as file:- content = file.read()-- # Extract title from first heading in markdown- title = ""- for line in content.split("\n"):- if line.startswith("#"):- title = line.lstrip("#").strip()- break- if not title:- title = Path(file_path).stem.replace("_", " ").title()-- doc_files.append(DocumentationFile(file_path=file_path, doc_content=content, title=title))- except Exception as e:- print(f"Warning: Could not read file {file_path}: {e}")- continue-- return doc_files---def read_file_content(working_memory: WorkingMemory) -> ListContent[CodebaseFileContent]:- """Read the content of related codebase files.-- Args:- working_memory: Working memory containing related_file_paths-- Returns:- ListContent of CodebaseFileContent objects- """-- file_paths_list = working_memory.get_stuff_as_list("related_file_paths", item_type=FilePath)-- codebase_files: List[CodebaseFileContent] = []- for file_path in file_paths_list.items:- try:- with open(file_path.path, "r", encoding="utf-8") as file:- content = file.read()- codebase_files.append(CodebaseFileContent(file_path=file_path.path, file_content=content))- except Exception as e:- codebase_files.append(- CodebaseFileContent(file_path=file_path.path, file_content=f"# File not found or unreadable: {file_path.path}\n# Error: {str(e)}")- )-- return ListContent[CodebaseFileContent](items=codebase_files)---func_registry.register_function(read_file_content, name="read_file_content")diff --git a/tests/test_pipelines/test_file_func_registry.py b/tests/test_pipelines/test_file_func_registry.pynew file mode 100644index 000000000..42b043727--- /dev/null+++ b/tests/test_pipelines/test_file_func_registry.py@@ -0,0 +1,49 @@+from typing import List++from pydantic import Field++from pipelex.core.memory.working_memory import WorkingMemory+from pipelex.core.stuffs.stuff_content import ListContent, StructuredContent+from pipelex.tools.func_registry import func_registry+++class FilePath(StructuredContent):+ """A path to a file in the codebase."""++ path: str = Field(description="Path to the file")+++class CodebaseFileContent(StructuredContent):+ """Content of a codebase file."""++ file_path: str = Field(description="Path to the codebase file")+ file_content: str = Field(description="Content of the codebase file")+++def read_file_content(working_memory: WorkingMemory) -> ListContent[CodebaseFileContent]:+ """Read the content of related codebase files.++ Args:+ working_memory: Working memory containing related_file_paths++ Returns:+ ListContent of CodebaseFileContent objects+ """++ file_paths_list = working_memory.get_stuff_as_list("related_file_paths", item_type=FilePath)++ codebase_files: List[CodebaseFileContent] = []+ for file_path in file_paths_list.items:+ try:+ with open(file_path.path, "r", encoding="utf-8") as file:+ content = file.read()+ codebase_files.append(CodebaseFileContent(file_path=file_path.path, file_content=content))+ except Exception as e:+ codebase_files.append(+ CodebaseFileContent(file_path=file_path.path, file_content=f"# File not found or unreadable: {file_path.path}\n# Error: {str(e)}")+ )++ return ListContent[CodebaseFileContent](items=codebase_files)+++func_registry.register_function(read_file_content, name="read_file_content")