小程序
小游戏
企业微信
微信支付
扫描小程序码分享
我大概用了一周大模型做一个小程序,只到今天才注意调用次数达到了18万次,今天就有8千多次。
我自己计算了一下,跑一次测试大概调用LLM 40-50次(包括小程序和云函数的),AUTH这些没计算进去。我今天大概跑了8-10次测试。所以8千多次感觉不太可能。
是否是因为我调用用了非流式文本生成API的方式?
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
4.服务端日志中单次请求触发的实际API调用次数记录
这个怎么查看?
目前用了小程序端的LLM APi和云函数端的LLM API,一部分采用流式,一部分采用非流式。
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
本回答由AI生成,可能已过期、失效或不适用于当前情形,请谨慎参考
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
4.服务端日志中单次请求触发的实际API调用次数记录
这个怎么查看?
目前用了小程序端的LLM APi和云函数端的LLM API,一部分采用流式,一部分采用非流式。
console.log('[CloudLLM] Initializing Auth & Model...');
await auth.signInAnonymously();
console.log('[CloudLLM] Sign in success');
const ai = app.ai();
const model = ai.createModel("deepseek");
_aiModel = model; // Set cache
return model;
} catch (authErr) {
console.warn('[CloudLLM] Auth Warning (proceeding):', authErr.message);
// Retry or proceed
const ai = app.ai();
_aiModel = ai.createModel("deepseek");
return _aiModel;
}
try {
console.log(`[CloudLLM] Calling ${model}...`);
const aiModel = await getAIModel();
// 4. Call Model with 45s Timeout Guard (Prevent 60s Function Kill)
const callPromise = _aiModel.generateText({
model: model,
messages: messages,
temperature: 0.8
});
const timeoutPromise = new Promise((_, reject) =>
setTimeout(() => reject(new Error("LLM API Timeout (45s)")), 45000)
);
const res = await Promise.race([callPromise, timeoutPromise]);
// Debug response structure
if (!res) throw new Error("Empty Response from CloudBase AI");
if (res.text) return res.text;
console.warn("[CloudLLM] Unexpected response structure:", JSON.stringify(res).substring(0, 200));
return JSON.stringify(res);
} catch (err) {
console.error('[CloudLLM] API Error:', err);
// Normalize error for caller
throw new Error(`LLM Call Failed: ${err.message || err.toString()} (Model: ${model})`);
}
这是代码。运行一次应该是调用40-60次。