基础组件完善

This commit is contained in:
2025-04-09 01:34:14 +08:00
parent e421bcd44b
commit ebdf97aebf
11 changed files with 2673 additions and 1692 deletions
+108
View File
@@ -0,0 +1,108 @@
// 使用原生Node.js http模块发送请求
import http from 'http';
import { Buffer } from 'buffer';
// 测试POST请求 - 尝试创建一个测试评查点
function testPostRequest() {
console.log('测试POST请求...');
// 创建测试数据
const testData = {
code: 'TEST_CODE_' + Date.now(),
name: '测试评查点',
risk: 'low',
is_enabled: false,
description: '这是一个测试评查点',
references_laws: {
name: '测试法规',
articles: ['第一条'],
content: '测试内容'
},
extraction_config: {
llm: {
fields: ['测试字段1', '测试字段2'],
prompt_setting: {
type: 'system',
template: '测试提示词'
}
},
vlm: {
fields: [
{ name: '图片字段1', type: 'default' }
],
prompt_setting: {
type: 'system',
template: '测试图片提示词'
}
},
regex: {
fields: [
{ field: '正则字段1', pattern: '\\d+' }
]
}
},
evaluation_config: {
logicType: 'and',
customLogic: '',
rules: []
},
pass_message: '通过消息',
fail_message: '失败消息',
suggestion_message: '建议消息',
suggestion_message_type: 'warning',
post_action: 'none',
action_config: ''
};
// 将数据转换为JSON字符串
const postData = JSON.stringify(testData);
// 设置请求选项
const options = {
hostname: '127.0.0.1',
port: 9000,
path: '/admin/evaluation_points',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': '1234567890',
'Content-Length': Buffer.byteLength(postData)
}
};
// 创建请求
const req = http.request(options, (res) => {
console.log(`状态码: ${res.statusCode}`);
console.log('响应头:', res.headers);
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
console.log('响应数据:');
try {
const parsedData = JSON.parse(data);
console.log(JSON.stringify(parsedData, null, 2));
} catch (e) {
console.log('无法解析响应为JSON:', data);
}
});
});
req.on('error', (error) => {
console.error('请求错误:', error.message);
});
// 发送数据
req.write(postData);
// 完成请求
req.end();
}
// 执行测试
testPostRequest();