(
included_files: list, project_root: str = "", disable_tokens=False
)
| 158 | |
| 159 | |
| 160 | def get_included_files( |
| 161 | included_files: list, project_root: str = "", disable_tokens=False |
| 162 | ) -> str: |
| 163 | if included_files: |
| 164 | included_files_content = [] |
| 165 | file_names_rel = [] |
| 166 | for file_path in included_files: |
| 167 | try: |
| 168 | with open(file_path, "r") as file: |
| 169 | included_files_content.append(file.read()) |
| 170 | file_path_rel = ( |
| 171 | os.path.relpath(file_path, project_root) |
| 172 | if project_root |
| 173 | else file_path |
| 174 | ) |
| 175 | file_names_rel.append(file_path_rel) |
| 176 | except IOError as e: |
| 177 | print(f"Error reading file {file_path}: {str(e)}") |
| 178 | out_str = "" |
| 179 | if included_files_content: |
| 180 | for i, content in enumerate(included_files_content): |
| 181 | out_str += f"file_path: `{file_names_rel[i]}`\ncontent:\n```\n{content}\n```\n\n\n" |
| 182 | |
| 183 | out_str = out_str.strip() |
| 184 | if not disable_tokens and get_settings().get( |
| 185 | "include_files.limit_tokens", False |
| 186 | ): |
| 187 | encoder = TokenEncoder.get_token_encoder() |
| 188 | num_input_tokens = len(encoder.encode(out_str)) |
| 189 | if num_input_tokens > get_settings().get("include_files.max_tokens"): |
| 190 | print( |
| 191 | f"Clipping included files content from {num_input_tokens} to {get_settings().get('include_files.max_tokens')} tokens" |
| 192 | ) |
| 193 | out_str = clip_tokens( |
| 194 | out_str, |
| 195 | get_settings().get("include_files.max_tokens"), |
| 196 | num_input_tokens=num_input_tokens, |
| 197 | ) |
| 198 | return out_str |
| 199 | return "" |
| 200 | |
| 201 | |
| 202 | def parse_args_full_repo(settings: Dynaconf) -> argparse.Namespace: |
nothing calls this directly
no test coverage detected