Report
| 42 | references: List[ReferenceItem] = Field(description="The references of the item") |
| 43 | |
| 44 | class Report(BaseModel): |
| 45 | """Report""" |
| 46 | model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow") |
| 47 | |
| 48 | title: str = Field(description="The title of the report") |
| 49 | items: List[ReportItem] = Field(default=[], description="The items of the report") |
| 50 | model_name: str = Field(default="openrouter/gemini-3-flash-preview", description="The model to use for extraction") |
| 51 | report_file_path: Optional[str] = Field(default=None, description="The file path where the report will be saved") |
| 52 | |
| 53 | def __init__(self, model_name: str = None, report_file_path: Optional[str] = None, **kwargs): |
| 54 | super().__init__(**kwargs) |
| 55 | if model_name is not None: |
| 56 | self.model_name = model_name |
| 57 | if report_file_path is not None: |
| 58 | self.report_file_path = report_file_path |
| 59 | |
| 60 | async def add_item(self, file_path: Optional[str] = None, content: Optional[Union[str, Dict[str, Any]]] = None): |
| 61 | """Add a new item to the report by extracting ReportItem from content. |
| 62 | |
| 63 | Args: |
| 64 | file_path (Optional[str]): The file path of the content (typically a markdown file). If provided, the file content will be read and appended to the prompt. |
| 65 | content (Optional[Union[str, Dict[str, Any]]]): Input content as string or dictionary. If string, it will be processed to extract content, summary, and references. If dictionary, it should contain structured data. |
| 66 | |
| 67 | Returns: |
| 68 | ReportItem: The extracted and added report item |
| 69 | """ |
| 70 | # Read file content if file_path is provided |
| 71 | file_content = "" |
| 72 | if file_path and os.path.exists(file_path): |
| 73 | try: |
| 74 | with open(file_path, 'r', encoding='utf-8') as f: |
| 75 | file_content = f.read() |
| 76 | except Exception as e: |
| 77 | # If file reading fails, continue without file content |
| 78 | file_content = f"[Note: Failed to read file {file_path}: {str(e)}]" |
| 79 | |
| 80 | # Prepare input text for processing |
| 81 | if isinstance(content, dict): |
| 82 | # Convert dict to formatted string |
| 83 | input_text = json.dumps(content, indent=4, ensure_ascii=False) |
| 84 | else: |
| 85 | input_text = str(content) if content else "" |
| 86 | |
| 87 | # Combine content and file content |
| 88 | combined_content = input_text |
| 89 | if file_content: |
| 90 | if combined_content: |
| 91 | combined_content = f"{combined_content}\n\n--- File Content from {file_path} ---\n\n{file_content}" |
| 92 | else: |
| 93 | combined_content = f"--- File Content from {file_path} ---\n\n{file_content}" |
| 94 | |
| 95 | # Build prompt to extract ReportItem |
| 96 | prompt = dedent(f"""Extract and structure the following content into a report item with content, summary, and references. |
| 97 | |
| 98 | Input Content: |
| 99 | ```json |
| 100 | {combined_content} |
| 101 | ``` |
no outgoing calls
no test coverage detected