chore: unify log formatting
This commit is contained in:
+5
-4
@@ -1,11 +1,12 @@
|
||||
import axios from 'axios';
|
||||
import { getLLMConfig } from './config.js';
|
||||
import { line, error } from './log.js';
|
||||
|
||||
export async function chat(systemPrompt, userContent) {
|
||||
const { provider, apiKeys, baseURL, model } = getLLMConfig();
|
||||
if (!provider) throw new Error('未設定任何 LLM API Key');
|
||||
|
||||
console.log(` [LLM] provider=${provider} model=${model}`);
|
||||
line(`[LLM] provider=${provider} model=${model}`);
|
||||
|
||||
const headers = { 'Content-Type': 'application/json' };
|
||||
if (provider === 'claude') headers['anthropic-version'] = '2023-06-01';
|
||||
@@ -21,10 +22,10 @@ export async function chat(systemPrompt, userContent) {
|
||||
);
|
||||
return resp.data.choices[0].message.content;
|
||||
} catch (e) {
|
||||
console.log(` [LLM] key[${i + 1}/${shuffled.length}] 失敗: ${e.message}`);
|
||||
line(`[LLM] key[${i + 1}/${shuffled.length}] 失敗: ${e.message}`);
|
||||
}
|
||||
}
|
||||
console.error(' [LLM] 所有 API Key 均失敗,終止流程');
|
||||
error('[LLM] 所有 API Key 均失敗,終止流程');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -33,7 +34,7 @@ export async function chatJSON(systemPrompt, userContent) {
|
||||
try {
|
||||
return JSON.parse(text.trim().replace(/^```[^\n]*\n?/, '').replace(/```$/, '').trim());
|
||||
} catch (e) {
|
||||
console.log(` [LLM] JSON 解析失敗: ${e.message}`);
|
||||
line(`[LLM] JSON 解析失敗: ${e.message}`);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user