-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_analyzer_debug.py
More file actions
101 lines (80 loc) · 2.78 KB
/
test_analyzer_debug.py
File metadata and controls
101 lines (80 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
"""
Debug test para Context Analyzer
"""
import asyncio
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent / "src"))
from snippets.agents.context_analyzer import ContextAnalyzer
from snippets.agents.llm_client import get_llm_client, LLMConfig
from snippets.agents.base_agent import Snippet
async def debug_analyzer():
"""Debug del Context Analyzer paso a paso"""
print("🔍 DEBUG: Context Analyzer")
print("=" * 50)
# Configuración mínima
config = LLMConfig(
model="llama-3.1-8b-instant",
max_tokens=200,
temperature=0.1
)
# Test simple con pocos snippets
snippets = [
Snippet(content='x = 5', index=0),
Snippet(content='y = x + 10', index=1)
]
target_snippet = snippets[1] # y = x + 10
print(f"Target: {target_snippet.content}")
print(f"Context: {len(snippets)} snippets")
print()
# Crear analyzer
analyzer = ContextAnalyzer()
# Hacer request directo al LLM para ver la respuesta
print("🧪 Testing direct LLM call...")
# Preparar contexto manualmente
context_formatted = """## Snippet 0 (-1)
```python
x = 5
```
## Snippet 1 >>> TARGET <<<
```python
y = x + 10
```"""
# Usar template
prompt = analyzer.prompt_template.format(
target_snippet=target_snippet.content,
context_snippets=context_formatted
)
print("📝 Prompt preview:")
print("-" * 30)
print(prompt[:400] + "..." if len(prompt) > 400 else prompt)
print("-" * 30)
try:
# Hacer request directo
llm_response = await analyzer.llm_client.generate(
prompt=prompt,
system_message="You are an expert Python code analyzer. Return valid JSON only."
)
print("\n📄 Raw LLM Response:")
print("-" * 30)
print(llm_response.content)
print("-" * 30)
# Intentar parsear
dependency_map = analyzer._parse_llm_response(llm_response.content)
print(f"\n📊 Parsed result:")
print(f" Confidence: {dependency_map.confidence}")
print(f" Error: {dependency_map.error}")
print(f" Variables: {dependency_map.variables}")
except Exception as e:
print(f"❌ LLM request failed: {e}")
# Probar fallback
print("\n🔄 Testing AST fallback...")
try:
fallback_result = analyzer._analyze_with_ast_fallback(target_snippet)
print(f" AST Variables: {fallback_result.variables}")
print(f" AST Confidence: {fallback_result.confidence}")
except Exception as ast_e:
print(f"❌ AST fallback also failed: {ast_e}")
if __name__ == "__main__":
asyncio.run(debug_analyzer())