Skip to main content

Calling AI Large Models in Mini Programs

In WeChat Mini Programs, calling AI Large Models can be achieved through the built-in Cloud Development AI+ capability in the basic library. Below is a detailed step-by-step guide:

1. Preparations

  1. Enable the CloudBase Environment:

    • Log in to the Tencent Cloud Console, enable the CloudBase environment, and obtain the envId.
  2. Initialize the Cloud Environment:

    • Initialize the cloud environment in the app.js file of the Mini Program.
      wx.cloud.init({
      env: "your-env-id", // Replace with your CloudBase environment ID
      });

2. Calling AI Large Models

  1. Use wx.cloud.extend.AI to invoke AI capabilities:

    • In pages or components that require calling AI large models, use the APIs provided by wx.cloud.extend.AI to make the call.

    • For example, invoke the hunyuan model for text generation:

      const hy = wx.cloud.extend.AI.createModel("hunyuan"); // Create a model
      const res = await hy.streamText({
      data: {
      model: "hunyuan-lite",
      messages: [
      {
      role: "user",
      content: "hi",
      },
      ],
      },
      });

      for await (let str of res.textStream) {
      console.log(str); // Print the generated text
      }
      for await (let event of res.eventStream) {
      console.log(event); // Print the complete data returned each time
      }

Similar Issues

  1. What are the prerequisites for invoking AI large models in Mini Programs?
  2. How to activate WeChat Cloud Development AI+ capabilities?
  3. What are the steps for invoking AI large models in Mini Programs?
  4. What APIs does wx.cloud.extend.AI provide?
  5. How to use the hunyuan model in Mini Programs?
  6. How to initialize the cloud environment when invoking AI large models?
  7. What are the code examples for invoking AI large models?
  8. What should be noted when invoking AI large models?
  9. How to handle the return results of invoking AI large models?
  10. What is the performance of invoking AI large models?

Hope the above information helps you better understand how to invoke AI large models in WeChat Mini Programs. If you have further questions, feel free to ask!