-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_mlx_integration.py
More file actions
executable file
·118 lines (97 loc) · 3.44 KB
/
Copy pathtest_mlx_integration.py
File metadata and controls
executable file
·118 lines (97 loc) · 3.44 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
#!/usr/bin/env python3
"""
测试 MLX 集成
"""
import requests
import json
import time
BASE_URL = "http://localhost:5001"
def test_mlx_check():
"""测试 MLX 状态检测"""
print("🔍 测试 MLX 状态检测...")
try:
response = requests.get(f"{BASE_URL}/api/check-parallax")
data = response.json()
print(f" 状态: {'✅ 可用' if data['available'] else '❌ 不可用'}")
if data['available']:
print(f" 模式: {data['mode']}")
print(f" 设备: {data['device']}")
else:
print(f" 原因: {data.get('error', '未知')}")
return data['available']
except Exception as e:
print(f" ❌ 测试失败: {e}")
return False
def test_mlx_evolution():
"""测试 MLX 模式进化"""
print("\n🤖 测试 MLX 模式进化...")
print(" ⚠️ 这将需要 1-2 分钟,请耐心等待...")
code = """def sort_array(arr):
n = len(arr)
for i in range(n):
for j in range(n - i - 1):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
return arr"""
try:
start_time = time.time()
response = requests.post(
f"{BASE_URL}/api/start-evolution",
json={
"code": code,
"generations": 3,
"mode": "parallax" # 使用 MLX 模式
},
timeout=300 # 5 分钟超时
)
elapsed = time.time() - start_time
data = response.json()
if response.status_code == 200:
print(f" ✅ MLX 模式成功(耗时 {elapsed:.1f}秒)")
print(f" 实际使用模式: {data['mode']}")
print(f" 进化代数: {len(data['result']['history'])}")
print(f" 最终性能: {data['result']['final_time']:.6f}秒")
# 显示改进
history = data['result']['history']
if len(history) > 1:
initial_time = history[0]['time']
final_time = history[-1]['time']
improvement = ((initial_time - final_time) / initial_time) * 100
print(f" 总提升: {improvement:.1f}%")
return True
else:
print(f" ❌ 失败: {data.get('error')}")
return False
except Exception as e:
print(f" ❌ 测试失败: {e}")
return False
def main():
print("=" * 60)
print("🧬 代码进化实验室 - MLX 集成测试")
print("=" * 60)
# 测试 MLX 检测
mlx_available = test_mlx_check()
if not mlx_available:
print("\n❌ MLX 不可用,无法继续测试")
return 1
# 测试 MLX 进化
mlx_success = test_mlx_evolution()
# 总结
print("\n" + "=" * 60)
print("📊 测试总结")
print("=" * 60)
print(f"MLX 检测: {'✅' if mlx_available else '❌'}")
print(f"MLX 进化: {'✅' if mlx_success else '❌'}")
if mlx_success:
print("\n🎉 MLX 集成完全可用!")
print("=" * 60)
print("✨ 项目已经使用真实的本地 AI!")
print("📍 访问 http://localhost:5001 开始使用")
print("🤖 选择 'MLX 本地 AI' 模式体验真实代码进化")
return 0
else:
print("\n⚠️ 存在问题,请检查日志")
return 1
if __name__ == "__main__":
import sys
sys.exit(main())