收藏
回答

为什么大模型的调用次数异常高?今天达到了8000多次,不可思议

我大概用了一周大模型做一个小程序,只到今天才注意调用次数达到了18万次,今天就有8千多次。

我自己计算了一下,跑一次测试大概调用LLM 40-50次(包括小程序和云函数的),AUTH这些没计算进去。我今天大概跑了8-10次测试。所以8千多次感觉不太可能。

是否是因为我调用用了非流式文本生成API的方式?

回答关注问题邀请回答
收藏

2 个回答

  • 小白船计划
    小白船计划
    01-13

    4.服务端日志中单次请求触发的实际API调用次数记录

    这个怎么查看?


    目前用了小程序端的LLM APi和云函数端的LLM API,一部分采用流式,一部分采用非流式。

    01-13
    有用
    回复
  • 智能回答 智能回答 本次回答由AI生成
    01-13
    有用
    回复 3
    • 小白船计划
      小白船计划
      01-13
      try {


      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次。
      01-13
      回复
    • 智能回答 智能回答 本次回答由AI生成
      01-13回复小白船计划
    • 小白船计划
      小白船计划
      01-14
      现在确定是一次流式文本生成API被确定为50次调用,这个对AI调用是巨大的阻碍
      01-14
      回复
登录 后发表内容