ai-model-wechat

tencentcloudbase/skills · updated Apr 8, 2026

$npx skills add https://github.com/tencentcloudbase/skills --skill ai-model-wechat
0 commentsdiscussion
summary

AI text generation and streaming for WeChat Mini Programs via wx.cloud.extend.AI.

  • Supports two methods: generateText() for non-streaming responses and streamText() for real-time streaming with callback support ( onText , onEvent , onFinish )
  • Built-in models include Hunyuan (recommended: hunyuan-2.0-instruct-20251111 ) and DeepSeek (recommended: deepseek-v3.2 )
  • API differs from JS/Node SDK: generateText() returns raw model response; streamText() requires parameters wrapped in a data o
skill.md

When to use this skill

Use this skill for calling AI models in WeChat Mini Program using wx.cloud.extend.AI.

Use it when you need to:

  • Integrate AI text generation in a Mini Program
  • Stream AI responses with callback support
  • Call Hunyuan models from WeChat environment

Do NOT use for:

  • Browser/Web apps → use ai-model-web skill
  • Node.js backend or cloud functions → use ai-model-nodejs skill
  • Image generation → use ai-model-nodejs skill (not available in Mini Program)
  • HTTP API integration → use http-api skill

Available Providers and Models

CloudBase provides these built-in providers and models:

Provider Models Recommended
hunyuan-exp hunyuan-turbos-latest, hunyuan-t1-latest, hunyuan-2.0-thinking-20251109, hunyuan-2.0-instruct-20251111 hunyuan-2.0-instruct-20251111
deepseek deepseek-r1-0528, deepseek-v3-0324, deepseek-v3.2 deepseek-v3.2

Prerequisites

  • WeChat base library 3.7.1+
  • No extra SDK installation needed

Initialization

// app.js
App({
  onLaunch: function() {
    wx.cloud.init({ env: "<YOUR_ENV_ID>" });
  }
})

generateText() - Non-streaming

⚠️ Different from JS/Node SDK: Return value is raw model response.

const model = wx.cloud.extend.AI.createModel("hunyuan-exp");

const res = await model.generateText({
  model: "hunyuan-2.0-instruct-20251111",  // Recommended model
  messages: [{ role: "user", content: "你好" }],
});

// ⚠️ Return value is RAW model response, NOT wrapped like JS/Node SDK
console.log(res.choices[0].message.content);  // Access via choices array
console.log(res.usage);                        // Token usage

streamText() - Streaming

⚠️ Different from JS/Node SDK: Must wrap parameters in data object, supports callbacks.

const model = wx.cloud.extend.AI.createModel("hunyuan-exp");

// ⚠️ Parameters MUST be wrapped in `data` object
const res = await model.streamText({
  data: {                              // ⚠️ Required wrapper
    model: "hunyuan-2.0-instruct-20251111",  // Recommended model
    messages: [{ role: "user", content: "hi" }]
  },
  onText: (text) => {                  // Optional: incremental text callback
    console.log("New text:", text);
  },
  onEvent: ({ data }) => {             // Optional: raw event callback
    console.log("Event:", data);
  },
  onFinish: (fullText) => {            // Optional: completion callback
    console.log("Done:", fullText);
  }
});

// Async iteration also available
for await (let str of res.textStream) {
  console.log(str);
}

// Check for completion with eventStream
for await (let event of res.eventStream) {
  console.log(event);
  if (event.data === "[DONE]") {       // ⚠️ Check for [DONE] to stop
    break;
  }
}

Error Handling Pattern

const model = wx.cloud.extend.AI.createModel("deepseek");

try {
  const res = await model.generateText({
    model: "deepseek-v3.2",
    messages: [{ role: "user", content: "生成一段欢迎文案" }],
  });

  console.log(res.choices[0].message.content);
} catch (error) {
  console.error("Mini Program AI request failed", error);
}

API Comparison: JS/Node SDK vs WeChat Mini Program

Feature JS/Node SDK WeChat Mini Program
Namespace app.ai() wx.cloud.extend.AI
generateText params Direct object Direct object
generateText return { text, usage, messages } Raw: { choices, usage }
streamText params Direct object ⚠️ Wrapped in data: {...}
streamText return { textStream, dataStream } { textStream, eventStream }
Callbacks Not supported onText, onEvent, onFinish
Image generation Node SDK only Not available

Type Definitions

streamText() Input

interface WxStreamTextInput {
  data: {                              // ⚠️ Required wrapper object
    model: string;
    messages: Array<{
      role: "user" | "system" | "assistant";
      content: string;
    }>;
  };
  onText?: (text: string) => void;     // Incremental text callback
  onEvent?: (prop: { data: string }) => void;  // Raw event callback
  onFinish?: (text: string) => void;   // Completion callback
}

streamText() Return

interface WxStreamTextResult {
  textStream: AsyncIterable<string>;   // Incremental text stream
  eventStream: AsyncIterable<{         // Raw event stream
    event?

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.
general reviews

Ratings

4.467 reviews
  • Daniel Thomas· Dec 28, 2024

    We added ai-model-wechat from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.

  • Isabella Jain· Dec 24, 2024

    I recommend ai-model-wechat for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

  • Neel Perez· Dec 24, 2024

    ai-model-wechat reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Ava Brown· Dec 12, 2024

    Useful defaults in ai-model-wechat — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Tariq Khan· Dec 4, 2024

    ai-model-wechat is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.

  • Amina Rahman· Nov 23, 2024

    Solid pick for teams standardizing on skills: ai-model-wechat is focused, and the summary matches what you get after install.

  • Kabir Garcia· Nov 19, 2024

    ai-model-wechat reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Ava Taylor· Nov 19, 2024

    I recommend ai-model-wechat for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

  • Neel Malhotra· Nov 15, 2024

    We added ai-model-wechat from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.

  • Daniel Sanchez· Nov 3, 2024

    Useful defaults in ai-model-wechat — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

showing 1-10 of 67

1 / 7