second commit
This commit is contained in:
53
test-deepseek-api.js
Normal file
53
test-deepseek-api.js
Normal file
@@ -0,0 +1,53 @@
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
// DeepSeek API 配置
|
||||
const DEEPSEEK_API_URL = 'https://api.deepseek.com/v1/chat/completions';
|
||||
const DEEPSEEK_API_KEY = 'sk-fdf7cc1c73504e628ec0119b7e11b8cc';
|
||||
|
||||
async function testDeepSeekAPI() {
|
||||
console.log('🧪 测试 DeepSeek API 连接...\n');
|
||||
|
||||
try {
|
||||
const response = await fetch(DEEPSEEK_API_URL, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${DEEPSEEK_API_KEY}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: 'deepseek-chat',
|
||||
messages: [
|
||||
{
|
||||
role: 'user',
|
||||
content: '你好,请简单介绍一下你自己。'
|
||||
}
|
||||
],
|
||||
temperature: 0.7,
|
||||
max_tokens: 200,
|
||||
stream: false
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.text();
|
||||
console.error('❌ API 调用失败:');
|
||||
console.error(`状态码: ${response.status}`);
|
||||
console.error(`错误信息: ${error}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
console.log('✅ API 连接成功!');
|
||||
console.log('📝 响应内容:');
|
||||
console.log(data.choices[0]?.message?.content || '无响应内容');
|
||||
console.log('\n🔧 响应详情:');
|
||||
console.log(JSON.stringify(data, null, 2));
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 测试失败:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 运行测试
|
||||
testDeepSeekAPI();
|
||||
Reference in New Issue
Block a user