Skip to content

Commit a6052b0

Browse files
committed
fix: improve repo processor error handling and output - Fix error with string summary handling - Add type checking for file content - Improve output formatting with emojis and stats
1 parent 5d2d6f3 commit a6052b0

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

agentic_rag/repo_processor.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ def __init__(self):
2222

2323
def _extract_metadata(self, summary: Dict[str, Any], tree: Dict[str, Any]) -> Dict[str, Any]:
2424
"""Extract metadata from repository summary and tree"""
25+
# Handle case where summary might be a string
26+
if isinstance(summary, str):
27+
return {
28+
"repo_name": "Unknown",
29+
"description": "",
30+
"language": "",
31+
"topics": [],
32+
"stars": 0,
33+
"forks": 0,
34+
"last_updated": "",
35+
"file_count": len(tree) if tree else 0
36+
}
37+
2538
return {
2639
"repo_name": summary.get("name", ""),
2740
"description": summary.get("description", ""),
@@ -48,18 +61,34 @@ def process_repo(self, repo_path: str | Path) -> Tuple[List[Dict[str, Any]], str
4861
# Ingest repository
4962
summary, tree, content = ingest(str(repo_path))
5063

51-
# Print repository information
52-
print("\nRepository Summary:")
53-
print(json.dumps(summary, indent=2))
54-
print("\nFile Tree:")
55-
print(json.dumps(tree, indent=2))
64+
# Print formatted repository information
65+
if isinstance(summary, dict):
66+
repo_name = summary.get("name", "Unknown")
67+
file_count = len(tree) if tree else 0
68+
token_count = sum(len(str(c).split()) for c in content.values()) * 1.3 # Rough estimate
69+
70+
print("\nRepository Information:")
71+
print("-" * 50)
72+
print(f"📦 Repository: {repo_name}")
73+
print(f"📄 Files analyzed: {file_count}")
74+
print(f"🔤 Estimated tokens: {int(token_count):,}")
75+
else:
76+
print("\nRepository Information:")
77+
print("-" * 50)
78+
print(f"📦 Repository: {repo_path}")
79+
print(f"📄 Files analyzed: {len(tree) if tree else 0}")
80+
print(f"🔤 Estimated tokens: {int(sum(len(str(c).split()) for c in content.values()) * 1.3):,}")
5681

5782
# Extract metadata
5883
metadata = self._extract_metadata(summary, tree)
5984

6085
# Process content into chunks
6186
processed_chunks = []
6287
for file_path, file_content in content.items():
88+
# Skip if content is not a string
89+
if not isinstance(file_content, str):
90+
continue
91+
6392
chunk = {
6493
"text": file_content,
6594
"metadata": {

0 commit comments

Comments
 (0)