-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_interactive_cli.py
More file actions
141 lines (110 loc) · 4.98 KB
/
Copy pathtest_interactive_cli.py
File metadata and controls
141 lines (110 loc) · 4.98 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
139
140
141
#!/usr/bin/env python3
"""
Test script for the enhanced interactive CLI with side-by-side display
and token weight visualization.
"""
import sys
from pathlib import Path
# Add src to path
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
from rich.console import Console
from src.toaripi_slm.cli.core import BilingualDisplay, TokenWeight
def test_token_weight_visualization():
"""Test the token weight visualization system."""
console = Console()
display = BilingualDisplay(console)
console.print("🧪 [bold blue]Testing Token Weight Visualization[/bold blue]\n")
# Test sample texts
english_text = "The children went fishing by the river"
toaripi_text = "Bada-bada na'a gola hanere malolo peni"
console.print("📝 [yellow]Sample Content:[/yellow]")
console.print(f"English: {english_text}")
console.print(f"Toaripi: {toaripi_text}\n")
# Test 1: Basic bilingual display with weights
console.print("🎯 [green]Test 1: Basic Bilingual Display with Token Weights[/green]")
display.display(english_text, toaripi_text, "story")
# Test 2: Display without weights
console.print("\n🎯 [green]Test 2: Display without Token Weights[/green]")
display.toggle_weights()
display.display(english_text, toaripi_text, "story")
# Test 3: Re-enable weights and test alignment toggle
console.print("\n🎯 [green]Test 3: Toggle Alignment (weights re-enabled)[/green]")
display.toggle_weights() # Re-enable weights
display.toggle_alignment() # Disable alignment
display.display(english_text, toaripi_text, "story")
# Test 4: Test different content types
console.print("\n🎯 [green]Test 4: Different Content Types[/green]")
display.toggle_alignment() # Re-enable alignment
vocab_english = "Fish swimming water children learning"
vocab_toaripi = "Hanere potopoto peni bada-bada nene-ida"
console.print("\n📚 [cyan]Vocabulary Example:[/cyan]")
display.display(vocab_english, vocab_toaripi, "vocabulary")
dialogue_english = "Teacher: What did you learn? Student: I learned about fishing."
dialogue_toaripi = "Amo-harigi: Ami na'a nene? Amo-nene: Mina na'a nene hanere."
console.print("\n💬 [cyan]Dialogue Example:[/cyan]")
display.display(dialogue_english, dialogue_toaripi, "dialogue")
# Test 5: Individual token weight creation
console.print("\n🎯 [green]Test 5: Individual Token Weight Examples[/green]")
tokens = [
TokenWeight("High", 0.9),
TokenWeight("Medium-High", 0.7),
TokenWeight("Medium", 0.5),
TokenWeight("Low", 0.3),
TokenWeight("Very-Low", 0.1)
]
from rich.text import Text
test_text = Text()
for i, tw in enumerate(tokens):
if i > 0:
test_text.append(" ")
test_text.append(tw.token, style=tw.color_style())
test_text.append(f"({tw.weight:.1f})", style="dim white")
console.print("Color Scale Example:")
console.print(test_text)
# Show legend
console.print("\n🎨 [green]Weight Legend:[/green]")
# Access internal legend for test purposes
display._legend()
console.print("\n✅ [bold green]All tests completed![/bold green]")
def test_interactive_commands():
"""Test the available interactive commands."""
console = Console()
console.print("\n📋 [bold blue]Available Interactive Commands[/bold blue]\n")
commands = [
("/help", "Show help message"),
("/type story", "Change to story generation"),
("/weights", "Toggle token weight display"),
("/align", "Toggle token alignment"),
("/legend", "Show color legend"),
("/settings", "Adjust generation settings"),
("/history", "Show conversation history"),
("/save", "Save session to file"),
("/clear", "Clear conversation history"),
("/quit", "Exit interactive mode")
]
from rich.table import Table
cmd_table = Table(title="Interactive Commands", show_header=True, header_style="bold magenta")
cmd_table.add_column("Command", style="cyan")
cmd_table.add_column("Description", style="green")
for cmd, desc in commands:
cmd_table.add_row(cmd, desc)
console.print(cmd_table)
if __name__ == "__main__":
try:
test_token_weight_visualization()
test_interactive_commands()
print("\n" + "="*50)
print("🎉 Enhanced Interactive CLI Test Complete!")
print("="*50)
print("\nTo run the interactive mode:")
print(" toaripi interact")
print("\nNew features available:")
print(" • Side-by-side English ↔ Toaripi display")
print(" • Colored token weight visualization")
print(" • Token alignment between languages")
print(" • Interactive visualization controls")
except Exception as e:
print(f"❌ Test failed: {e}")
import traceback
traceback.print_exc()
sys.exit(1)