Files
BaiLongma/orchestrator-v2/debate/llm.js
chengjiaxi 664ffb3834 小白龙 Bailongma - 初始提交
自主操作员与思考搭档系统。
包含 orchestrator-v2 多Agent编排层、后台意识引擎、记忆系统、ACUI 组件。
2026-05-22 19:22:06 +08:00

32 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// ============================================================
// LLM 调用工具 — 独立于 agent-worker直接 fetch API
// ============================================================
const BASE_URL = (process.env.LLM_BASE_URL || process.env.OPENAI_BASE_URL || "https://api.openai.com/v1").replace(/\/+$/, "");
const MODEL = process.env.LLM_MODEL || process.env.OPENAI_MODEL || "gpt-4o";
const API_KEY = process.env.LLM_API_KEY || process.env.OPENAI_API_KEY || "";
async function callLLM({ messages, model, maxTokens, temperature }) {
const url = BASE_URL + "/chat/completions";
const body = {
model: model || MODEL,
messages: messages,
max_tokens: maxTokens || 2048,
temperature: temperature ?? 0.7
};
const resp = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + API_KEY
},
body: JSON.stringify(body)
});
if (!resp.ok) {
const errText = await resp.text().catch(() => "");
throw new Error("LLM " + resp.status + ": " + errText.slice(0, 200));
}
return await resp.json();
}
module.exports = { callLLM };