-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
172 lines (134 loc) · 5.7 KB
/
Copy pathtest.py
File metadata and controls
172 lines (134 loc) · 5.7 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env python3
"""
Test Script for Multi-turn Dialogue Generation
This script tests the dialogue generator with clean data structure and validates
all functionality including data loading, template processing, and dialogue generation.
Author: Your Name
License: MIT
Version: 1.0.0
"""
import json
import os
from dialogue_generator import DialogueGenerator
from config import API_CONFIG, FILE_PATHS, GENERATION_CONFIG
def test_config_loading():
"""Test configuration loading"""
print("=== Testing Configuration Loading ===")
try:
print(f"API Configuration: {API_CONFIG}")
print(f"File Path Configuration: {FILE_PATHS}")
print(f"Generation Configuration: {GENERATION_CONFIG}")
print("✓ Configuration loading successful")
return True
except Exception as e:
print(f"❌ Configuration loading failed: {e}")
return False
def test_data_structure():
"""Test simplified data structure"""
print("\n=== Testing Simplified Data Structure ===")
try:
data_path = FILE_PATHS["data"]
if not os.path.exists(data_path):
print("❌ Simplified data file does not exist")
return False
with open(data_path, 'r', encoding='utf-8') as f:
data = json.load(f)
# Check structure
if "categories" not in data:
print("❌ Missing 'categories' in data structure")
return False
if "flow_definitions" not in data:
print("❌ Missing 'flow_definitions' in data structure")
return False
categories = data["categories"]
flow_definitions = data["flow_definitions"]
print(f"✓ Found {len(categories)} categories")
print(f"✓ Found {len(flow_definitions)} flow definitions")
# Check each category has required fields
for category_name, category_data in categories.items():
if "scenarios" not in category_data:
print(f"❌ Category '{category_name}' missing 'scenarios'")
return False
if "flow_type" not in category_data:
print(f"❌ Category '{category_name}' missing 'flow_type'")
return False
flow_type = category_data["flow_type"]
if flow_type not in flow_definitions:
print(f"❌ Category '{category_name}' references unknown flow_type '{flow_type}'")
return False
print("✓ All categories have valid structure")
return True
except Exception as e:
print(f"❌ Data structure test failed: {e}")
return False
def test_dialogue_generator():
"""Test simplified dialogue generator"""
print("\n=== Testing Simplified Dialogue Generator ===")
try:
# Initialize generator
generator = DialogueGenerator(
base_url=API_CONFIG["base_url"],
api_key=API_CONFIG["api_key"],
model=API_CONFIG["model"]
)
print("✓ Successfully initialized dialogue generator")
# Test loading data
data = generator.load_data(FILE_PATHS["data"])
categories = data.get("categories", {})
flow_definitions = data.get("flow_definitions", {})
print(f"✓ Successfully loaded data, total {len(categories)} categories")
# Test loading templates
query_template = generator.load_prompt_template(FILE_PATHS["query_prompt"])
response_template = generator.load_prompt_template(FILE_PATHS["response_prompt"])
print("✓ Successfully loaded prompt templates")
# Test single dialogue generation
print("\nStarting single dialogue generation test...")
test_category = "Problem-solving Interaction"
test_scenario = "Technical Support"
test_flow_type = "problem_diagnosis_to_solution"
dialogue = generator.generate_dialogue(
category=test_category,
scenario=test_scenario,
flow_type=test_flow_type,
query_prompt_template=query_template,
response_prompt_template=response_template,
flow_definitions=flow_definitions
)
print("✓ Successfully generated test dialogue")
print(f"Dialogue category: {dialogue['category']}")
print(f"Dialogue turns: {len(dialogue['turns'])}")
print(f"Query count: {len(dialogue['queries'])}")
print(f"Response count: {len(dialogue['responses'])}")
# Save test results
test_output = "test_simple_output.json"
with open(test_output, "w", encoding="utf-8") as f:
json.dump(dialogue, f, ensure_ascii=False, indent=2)
print(f"✓ Test results saved to {test_output}")
return True
except Exception as e:
print(f"❌ Dialogue generator test failed: {e}")
return False
def main():
"""Main test function"""
print("Starting tests for simplified dialogue generation...")
tests = [
test_config_loading,
test_data_structure,
test_dialogue_generator
]
passed = 0
total = len(tests)
for test_func in tests:
try:
if test_func():
passed += 1
except Exception as e:
print(f"Test {test_func.__name__} encountered exception: {e}")
print(f"\n=== Test Results ===")
print(f"Passed: {passed}/{total}")
if passed == total:
print("🎉 All tests passed! Simplified version is working properly.")
else:
print("⚠ Some tests failed. Please check the configuration and data structure.")
if __name__ == "__main__":
main()