v3.0.1, 改成tools调用方式
This commit is contained in:
+5
-3
@@ -19,10 +19,11 @@ function getErrorMsg(status, data) {
|
||||
}
|
||||
}
|
||||
|
||||
async function callDeepSeek(messages, userId, temperature = 0.1, jsonMode = true) {
|
||||
async function callDeepSeek(messages, userId, temperature = 0.1, jsonMode = true, tools) {
|
||||
console.log('调用 DeepSeek...');
|
||||
var body = { model: 'deepseek-v4-flash', messages: messages, temperature: temperature, stream: false, thinking: { type: 'disabled' } };
|
||||
if (jsonMode) body.response_format = { type: 'json_object' };
|
||||
if (tools && tools.length) body.tools = tools;
|
||||
if (jsonMode && !(tools && tools.length)) body.response_format = { type: 'json_object' };
|
||||
if (userId) body.user_id = sanitizeUserId(userId);
|
||||
var res = await fetch('https://api.deepseek.com/chat/completions', {
|
||||
method: 'POST',
|
||||
@@ -50,7 +51,8 @@ async function callDeepSeek(messages, userId, temperature = 0.1, jsonMode = true
|
||||
// 输入消息大小日志
|
||||
//var inputChars = JSON.stringify(messages).length;
|
||||
//console.log('输入大小: ' + inputChars + ' 字符, ' + messages.length + ' 条消息');
|
||||
return data.choices[0].message.content;
|
||||
// 返回整个 message 对象,可能包含 content 或 tool_calls(供上层决定走工具还是 JSON)
|
||||
return data.choices[0].message;
|
||||
}
|
||||
|
||||
module.exports = { callDeepSeek };
|
||||
|
||||
Reference in New Issue
Block a user