MCPcopy
hub / github.com/HKUDS/DeepCode / find_relationships

Method find_relationships

tools/code_indexer.py:865–949  ·  view source on GitHub ↗

Find relationships between a repo file and target structure

(
        self, file_summary: FileSummary
    )

Source from the content-addressed store, hash-verified

863 )
864
865 async def find_relationships(
866 self, file_summary: FileSummary
867 ) -> List[FileRelationship]:
868 """Find relationships between a repo file and target structure"""
869
870 # Build relationship type description from config
871 relationship_type_desc = []
872 for rel_type, weight in self.relationship_types.items():
873 relationship_type_desc.append(f"- {rel_type} (priority: {weight})")
874
875 relationship_prompt = f"""
876 Analyze the relationship between this existing code file and the target project structure.
877
878 Existing File Analysis:
879 - Path: {file_summary.file_path}
880 - Type: {file_summary.file_type}
881 - Functions: {', '.join(file_summary.main_functions)}
882 - Concepts: {', '.join(file_summary.key_concepts)}
883 - Summary: {file_summary.summary}
884
885 Target Project Structure:
886 {self.target_structure}
887
888 Available relationship types (with priority weights):
889 {chr(10).join(relationship_type_desc)}
890
891 Identify potential relationships and provide analysis in this JSON format:
892 {{
893 "relationships": [
894 {{
895 "target_file_path": "path/in/target/structure",
896 "relationship_type": "direct_match|partial_match|reference|utility",
897 "confidence_score": 0.0-1.0,
898 "helpful_aspects": ["specific", "aspects", "that", "could", "help"],
899 "potential_contributions": ["how", "this", "could", "contribute"],
900 "usage_suggestions": "detailed suggestion on how to use this file"
901 }}
902 ]
903 }}
904
905 Consider the priority weights when determining relationship types. Higher weight types should be preferred when multiple types apply.
906 Only include relationships with confidence > {self.min_confidence_score}. Focus on concrete, actionable connections.
907 """
908
909 try:
910 llm_response = await self._call_llm(relationship_prompt, max_tokens=1500)
911
912 match = re.search(r"\{.*\}", llm_response, re.DOTALL)
913 relationship_data = json.loads(match.group(0))
914
915 relationships = []
916 for rel_data in relationship_data.get("relationships", []):
917 confidence_score = float(rel_data.get("confidence_score", 0.0))
918 relationship_type = rel_data.get("relationship_type", "reference")
919
920 # Validate relationship type is in config
921 if relationship_type not in self.relationship_types:
922 if self.verbose_output:

Calls 3

_call_llmMethod · 0.95
FileRelationshipClass · 0.85
getMethod · 0.80

Tested by

no test coverage detected