You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
3.3 KiB
102 lines
3.3 KiB
#!/usr/bin/env python3
|
|
"""
|
|
简化的DeepSeek v3.1代码规约化测试运行脚本
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import asyncio
|
|
from pathlib import Path
|
|
|
|
# 添加项目根目录到路径
|
|
project_root = Path(__file__).parent.parent.parent
|
|
sys.path.insert(0, str(project_root))
|
|
|
|
from src.spec.llm_generator import LLMGenerator, GenerationRequest
|
|
|
|
|
|
def create_simple_function_info():
|
|
"""创建简单的示例函数信息"""
|
|
return {
|
|
'name': 'add_numbers',
|
|
'return_type': 'int',
|
|
'parameters': [
|
|
{'name': 'a', 'type': 'int'},
|
|
{'name': 'b', 'type': 'int'}
|
|
],
|
|
'source_code': 'int add_numbers(int a, int b) { return a + b; }',
|
|
'complexity': 'basic'
|
|
}
|
|
|
|
|
|
async def quick_test():
|
|
"""快速测试"""
|
|
print("🚀 DeepSeek v3.1 代码规约化快速测试")
|
|
print("=" * 50)
|
|
|
|
# 检查API密钥
|
|
api_key = os.getenv('SILICONFLOW_API_KEY')
|
|
if not api_key:
|
|
print("❌ 错误: 未设置 SILICONFLOW_API_KEY 环境变量")
|
|
print("请先设置: export SILICONFLOW_API_KEY=your_api_key")
|
|
return
|
|
|
|
try:
|
|
# 创建生成器
|
|
async with LLMGenerator() as generator:
|
|
print(f"📡 连接模型: {generator.model}")
|
|
|
|
# 健康检查
|
|
print("🔍 检查API状态...")
|
|
health = await generator.health_check()
|
|
if health['status'] == 'healthy':
|
|
print(f"✅ API健康 (响应时间: {health['api_response_time']:.2f}s)")
|
|
else:
|
|
print(f"❌ API不健康: {health.get('error', '未知错误')}")
|
|
return
|
|
|
|
# 创建测试请求
|
|
function_info = create_simple_function_info()
|
|
request = GenerationRequest(
|
|
function_name=function_info['name'],
|
|
function_info=function_info,
|
|
verification_goals=['functional_correctness'],
|
|
hints=['简单的加法函数']
|
|
)
|
|
|
|
print(f"\n📝 函数: {function_info['name']}")
|
|
print(f"🎯 目标: 生成形式化验证规约")
|
|
|
|
# 生成规约
|
|
print("\n⏳ 正在生成规约...")
|
|
result = await generator.generate_specification(request)
|
|
|
|
print(f"\n✅ 生成成功!")
|
|
print(f"📊 质量评分: {result.quality_score:.2f}")
|
|
print(f"⏱️ 生成时间: {result.generation_time:.2f}s")
|
|
print(f"🔤 使用Token: {result.tokens_used}")
|
|
|
|
print(f"\n📋 生成的CBMC规约:")
|
|
print("-" * 40)
|
|
print(result.specification)
|
|
print("-" * 40)
|
|
|
|
# 显示验证结果
|
|
if result.validation_result:
|
|
print(f"\n🔍 验证结果:")
|
|
print(f" 有效: {'✅' if result.validation_result.is_valid else '❌'}")
|
|
if result.validation_result.errors:
|
|
print(f" 错误: {len(result.validation_result.errors)}")
|
|
if result.validation_result.warnings:
|
|
print(f" 警告: {len(result.validation_result.warnings)}")
|
|
|
|
print(f"\n🎉 测试完成!")
|
|
|
|
except Exception as e:
|
|
print(f"❌ 测试失败: {str(e)}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(quick_test()) |