| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- // Mock @langchain/openai 让 fetch hang(永不响应)测真实路径 invokeWithRetry
- process.on('SIGTERM', () => process.exit(0));
- const Module = require('module');
- const origResolve = Module._resolve_filename = Module._resolveFilename;
- let hookInstalled = false;
- function installFetchHang(MockClass) {
- const origInvoke = MockClass.prototype.invoke;
- let invokeCount = 0;
- let nodeIndex = 0;
- MockClass.prototype.invoke = async function patchedInvoke(messages) {
- invokeCount++;
- console.log(`[hang-mock] invoke #${invokeCount} on instance with model=${this.model} apiKey-end=${(this.apiKey || '').slice(-12)}`);
- // 模拟 HTTP 永不响应 — 返回一个永远不 resolve 的 Promise
- // 但调用 await Promise.race / onTimeout 让超时能 abort
- return new Promise((_, reject) => {
- // 100ms 后抛"timeout"模拟 disconnect-after-start
- setTimeout(() => {
- const err = new Error('Request timed out after 30000ms (fake hang)');
- err.name = 'AbortError';
- reject(err);
- }, 30000);
- });
- };
- return MockClass;
- }
- const origLoad = Module._load;
- Module._load = function (req, parent, ...rest) {
- const exported = origLoad.call(this, req, parent, ...rest);
- if (req === '@langchain/openai' && !hookInstalled) {
- hookInstalled = true;
- if (exported.ChatOpenAI) {
- return { ...exported, ChatOpenAI: installFetchHang(exported.ChatOpenAI) };
- }
- }
- return exported;
- };
- // 真实入口
- const llm = require('/data/ai/audio/server/dist/services/llm');
- (async () => {
- const start = Date.now();
- console.log('[t=0] calling callLLMWithMessages (qwen3.5-flash) — should fallback through providers');
- try {
- const r = await llm.callLLMWithMessages(
- [
- { role: 'user', content: '一句话总结' }
- ],
- 'qwen3.5-flash',
- 100
- );
- console.log(`[t=${(Date.now() - start) / 1000}s] OK: ${r.slice(0, 100)}`);
- } catch (e) {
- console.log(`[t=${(Date.now() - start) / 1000}s] ERR name=${e?.name}: ${e?.message?.slice(0, 200)}`);
- if (e.attempts) {
- console.log('attempts:', JSON.stringify(e.attempts, null, 2));
- }
- }
- process.exit(0);
- })();
|