ds api请求时加上user_id
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
// DeepSeek API 客户端
|
||||
const DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY || '';
|
||||
|
||||
async function callDeepSeek(messages, temperature = 0.1) {
|
||||
function sanitizeUserId(username) {
|
||||
return username.replace(/[^a-zA-Z0-9\-_]/g, '_').substring(0, 64) || 'anon';
|
||||
}
|
||||
|
||||
async function callDeepSeek(messages, temperature = 0.1, userId = '') {
|
||||
console.log('🤖 调用 DeepSeek...');
|
||||
const res = await fetch('https://api.deepseek.com/chat/completions', {
|
||||
var body = { model: 'deepseek-v4-flash', messages: messages, temperature: temperature, stream: false };
|
||||
if (userId) body.user_id = sanitizeUserId(userId);
|
||||
var res = await fetch('https://api.deepseek.com/chat/completions', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${DEEPSEEK_API_KEY}` },
|
||||
body: JSON.stringify({ model: 'deepseek-v4-flash', messages, temperature, stream: false })
|
||||
headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + DEEPSEEK_API_KEY },
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!data.choices || !data.choices[0]) {
|
||||
|
||||
Reference in New Issue
Block a user