ai-model-web▌
tencentcloudbase/skills · updated Apr 8, 2026
AI text generation and streaming for browser applications via CloudBase SDK.
- ›Supports two providers: Hunyuan (recommended: hunyuan-2.0-instruct-20251111 ) and DeepSeek (recommended: deepseek-v3.2 )
- ›Two core methods: generateText() for non-streaming responses and streamText() for incremental text chunks with async iteration
- ›Requires @cloudbase/js-sdk initialization with anonymous authentication and publishable API key from CloudBase console
- ›Not suitable for Node.js backends, WeChat
When to use this skill
Use this skill for calling AI models in browser/Web applications using @cloudbase/js-sdk.
Use it when you need to:
- Integrate AI text generation in a frontend Web app
- Stream AI responses for better user experience
- Call Hunyuan or DeepSeek models from browser
Do NOT use for:
- Node.js backend or cloud functions → use
ai-model-nodejsskill - WeChat Mini Program → use
ai-model-wechatskill - Image generation → use
ai-model-nodejsskill (Node SDK only) - HTTP API integration → use
http-apiskill
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 |
Installation
npm install @cloudbase/js-sdk
Initialization
import cloudbase from "@cloudbase/js-sdk";
const app = cloudbase.init({
env: "<YOUR_ENV_ID>",
accessKey: "<YOUR_PUBLISHABLE_KEY>" // Get from CloudBase console
});
const auth = app.auth();
await auth.signInAnonymously();
const ai = app.ai();
Important notes:
- Always use synchronous initialization with top-level import
- User must be authenticated before using AI features
- Get
accessKeyfrom CloudBase console
generateText() - Non-streaming
const model = ai.createModel("hunyuan-exp");
const result = await model.generateText({
model: "hunyuan-2.0-instruct-20251111", // Recommended model
messages: [{ role: "user", content: "你好,请你介绍一下李白" }],
});
console.log(result.text); // Generated text string
console.log(result.usage); // { prompt_tokens, completion_tokens, total_tokens }
console.log(result.messages); // Full message history
console.log(result.rawResponses); // Raw model responses
streamText() - Streaming
const model = ai.createModel("hunyuan-exp");
const res = await model.streamText({
model: "hunyuan-2.0-instruct-20251111", // Recommended model
messages: [{ role: "user", content: "你好,请你介绍一下李白" }],
});
// Option 1: Iterate text stream (recommended)
for await (let text of res.textStream) {
console.log(text); // Incremental text chunks
}
// Option 2: Iterate data stream for full response data
for await (let data of res.dataStream) {
console.log(data); // Full response chunk with metadata
}
// Option 3: Get final results
const messages = await res.messages; // Full message history
const usage = await res.usage; // Token usage
Error Handling Pattern
const model = ai.createModel("deepseek");
try {
const result = await model.generateText({
model: "deepseek-v3.2",
messages: [{ role: "user", content: "Generate a concise onboarding checklist" }],
});
console.log(result.text);
} catch (error) {
console.error("Failed to call CloudBase AI from Web", error);
}
Type Definitions
interface BaseChatModelInput {
model: string; // Required: model name
messages: Array<ChatModelMessage>; // Required: message array
temperature?: number; // Optional: sampling temperature
topP?: number; // Optional: nucleus sampling
}
type ChatModelMessage =
| { role: "user"; content: string }
| { role: "system"; content: string }
| { role: "assistant"; content: string };
interface GenerateTextResult {
text: string; // Generated text
messages: Array<ChatModelMessage>; // Full message history
usage: Usage; // Token usage
rawResponses: Array<unknown>; // Raw model responses
error?: unknown; // Error if any
}
interface StreamTextResult {
textStream: AsyncIterable<string>; // Incremental text stream
dataStream: AsyncIterable<DataChunk>; // Full data stream
messages: Promise<ChatModelMessage[]>;// Final message history
usage: Promise<Usage>; // Final token usage
error?: unknown; // Error if any
}
interface Usage {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
}
Best Practices
- Use streaming for long responses - Better user experience
- Handle errors gracefully - Wrap AI calls in try/catch
- Keep accessKey secure - Use publishable key, not secret key
- Initialize early - Initialize SDK in app entry point
- Ensure authentication - User must be signed in before AI calls
Ratings
4.7★★★★★39 reviews- ★★★★★Anaya Singh· Dec 20, 2024
ai-model-web reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Anika Lopez· Nov 11, 2024
Solid pick for teams standardizing on skills: ai-model-web is focused, and the summary matches what you get after install.
- ★★★★★Amelia Mensah· Nov 11, 2024
ai-model-web has been reliable in day-to-day use. Documentation quality is above average for community skills.
- ★★★★★Amelia Chawla· Oct 2, 2024
We added ai-model-web from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
- ★★★★★Amelia Kim· Oct 2, 2024
Useful defaults in ai-model-web — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Sakshi Patil· Sep 13, 2024
ai-model-web fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- ★★★★★Amelia Torres· Sep 9, 2024
Registry listing for ai-model-web matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Arjun Thomas· Sep 9, 2024
Useful defaults in ai-model-web — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Anaya Srinivasan· Aug 28, 2024
Keeps context tight: ai-model-web is the kind of skill you can hand to a new teammate without a long onboarding doc.
- ★★★★★Amelia Malhotra· Aug 28, 2024
ai-model-web has been reliable in day-to-day use. Documentation quality is above average for community skills.
showing 1-10 of 39