Feat: add env-driven LLM configuration and smoke test

这个提交包含在:
cryptocommuniums-afk
2026-03-14 21:54:51 +08:00
父节点 ba35e50528
当前提交 f5ad0449a8
修改 8 个文件,包含 203 行新增9 行删除

查看文件

@@ -210,13 +210,13 @@ const normalizeToolChoice = (
};
const resolveApiUrl = () =>
ENV.forgeApiUrl && ENV.forgeApiUrl.trim().length > 0
? `${ENV.forgeApiUrl.replace(/\/$/, "")}/v1/chat/completions`
ENV.llmApiUrl && ENV.llmApiUrl.trim().length > 0
? ENV.llmApiUrl
: "https://forge.manus.im/v1/chat/completions";
const assertApiKey = () => {
if (!ENV.forgeApiKey) {
throw new Error("OPENAI_API_KEY is not configured");
if (!ENV.llmApiKey) {
throw new Error("LLM_API_KEY is not configured");
}
};
@@ -280,7 +280,7 @@ export async function invokeLLM(params: InvokeParams): Promise<InvokeResult> {
} = params;
const payload: Record<string, unknown> = {
model: "gemini-2.5-flash",
model: ENV.llmModel,
messages: messages.map(normalizeMessage),
};
@@ -296,9 +296,12 @@ export async function invokeLLM(params: InvokeParams): Promise<InvokeResult> {
payload.tool_choice = normalizedToolChoice;
}
payload.max_tokens = 32768
payload.thinking = {
"budget_tokens": 128
payload.max_tokens = ENV.llmMaxTokens;
if (ENV.llmEnableThinking && ENV.llmThinkingBudget > 0) {
payload.thinking = {
budget_tokens: ENV.llmThinkingBudget,
};
}
const normalizedResponseFormat = normalizeResponseFormat({
@@ -316,7 +319,7 @@ export async function invokeLLM(params: InvokeParams): Promise<InvokeResult> {
method: "POST",
headers: {
"content-type": "application/json",
authorization: `Bearer ${ENV.forgeApiKey}`,
authorization: `Bearer ${ENV.llmApiKey}`,
},
body: JSON.stringify(payload),
});