-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_llm_visualization.py
More file actions
138 lines (95 loc) Β· 4.06 KB
/
Copy pathtest_llm_visualization.py
File metadata and controls
138 lines (95 loc) Β· 4.06 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"""Test script to demonstrate LLM interaction visualization during report generation.
This script shows how the new visualization system captures and displays
all LLM interactions that occur during the report generation phase.
"""
from __future__ import annotations
import asyncio
from dotenv import load_dotenv
from gpt_researcher.agent import GPTResearcher
from gpt_researcher.skills.llm_visualizer import enable_llm_visualization
# Load environment variables
load_dotenv()
async def test_visualization() -> str:
"""Test the LLM interaction visualization"""
print("π§ͺ Testing LLM Interaction Visualization")
print("=" * 50)
# Enable visualization
enable_llm_visualization()
# Create a simple research query
query = "What are the key benefits of artificial intelligence in healthcare?"
# Initialize researcher
researcher = GPTResearcher(
query=query,
report_type="research_report",
verbose=True,
)
print(f"\n㪠Research Query: {query}")
print("\nβοΈ Starting research phase...")
# Conduct research (this won't be visualized, only report generation)
research_context: list[str] = await researcher.conduct_research()
print(f"\nπ Research completed. Found {len(research_context)} sources.")
print("\nπ Starting report generation (THIS WILL BE VISUALIZED)...")
print("=" * 80)
# Generate report (this WILL be visualized)
report: str = await researcher.write_report()
print("\n" + "=" * 80)
print("β
Test completed!")
print(f"π Generated report: {len(report)} characters")
print(f"π Report preview:\n{report[:300]}...")
return report
async def test_introduction_and_conclusion() -> tuple[str, str]:
"""Test individual report components"""
print("\nπ§ͺ Testing Individual Report Components")
print("=" * 50)
# Enable visualization
enable_llm_visualization()
query = "How does machine learning impact modern education?"
researcher = GPTResearcher(
query=query,
report_type="research_report",
verbose=True,
)
# Conduct minimal research
await researcher.conduct_research()
print("\nπ Testing Introduction Generation...")
print("-" * 40)
# Test introduction (will be visualized)
introduction: str = await researcher.write_introduction()
print(f"\nπ Introduction: {introduction[:200]}...")
print("\nπ Testing Conclusion Generation...")
print("-" * 40)
# Test conclusion (will be visualized)
conclusion: str = await researcher.write_report_conclusion("Sample report content for conclusion testing.")
print(f"\nπ Conclusion: {conclusion[:200]}...")
return introduction, conclusion
async def main():
"""Main test function"""
print("π¬ LLM INTERACTION VISUALIZATION DEMO")
print("=" * 80)
print("This demo shows how GPT Researcher visualizes all LLM interactions")
print("during report generation in a 2D mapping format.")
print("=" * 80)
try:
# Test 1: Full report generation
print("\nπ― TEST 1: Full Report Generation with Visualization")
await test_visualization()
print("\n" + "=" * 80)
# Test 2: Individual components
print("\nπ― TEST 2: Individual Components (Introduction & Conclusion)")
intro, conclusion = await test_introduction_and_conclusion()
print("\n" + "=" * 80)
print("π ALL TESTS COMPLETED SUCCESSFULLY!")
print("=" * 80)
print("\nKey Features Demonstrated:")
print("β
Real-time LLM interaction tracking")
print("β
Detailed prompt and response visualization")
print("β
2D flow diagram generation")
print("β
Performance metrics (timing, token counts)")
print("β
Error handling and failed interaction tracking")
print("β
Mermaid diagram export for visual flow")
except Exception as e:
print(f"\nβ Error during testing: {e.__class__.__name__}: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
asyncio.run(main())