(path)
| 659 | results = {} |
| 660 | |
| 661 | def process_file(path): |
| 662 | try: |
| 663 | target_path_real = self.get_real_path(path) |
| 664 | if target_path_real is None: |
| 665 | return path, f'Access denied: Reading file <{path}> outside output directory is not allowed.' |
| 666 | |
| 667 | index_file = os.path.join(self.index_dir, path.strip(os.sep)) |
| 668 | if os.path.exists(index_file): |
| 669 | with open(index_file, 'r', encoding='utf-8') as f: |
| 670 | return path, f.read() |
| 671 | |
| 672 | # Read file content |
| 673 | with open(target_path_real, 'r', encoding='utf-8') as f: |
| 674 | content = f.read() |
| 675 | |
| 676 | # Use LLM to generate abbreviation |
| 677 | messages = [ |
| 678 | Message(role='system', content=self.system), |
| 679 | Message( |
| 680 | role='user', |
| 681 | content='The content to be abbreviated:\n\n' |
| 682 | + content), |
| 683 | ] |
| 684 | response = self.llm.generate(messages=messages, stream=False) |
| 685 | os.makedirs(os.path.dirname(index_file), exist_ok=True) |
| 686 | with open(index_file, 'w', encoding='utf-8') as f: |
| 687 | f.write(response.content) |
| 688 | return path, response.content |
| 689 | except FileNotFoundError: |
| 690 | return path, f'Read file <{path}> failed: FileNotFound' |
| 691 | except Exception as e: |
| 692 | return path, f'Process file <{path}> failed, error: ' + str(e) |
| 693 | |
| 694 | # Use thread pool for parallel LLM API calls |
| 695 | with ThreadPoolExecutor(max_workers=4) as executor: |
nothing calls this directly
no test coverage detected