ai-model-nodejs
Use this skill when developing Node.js backend services or CloudBase cloud functions (Express/Koa/NestJS, serverless, backend APIs) that need AI capabilities. Features text generation (generateText), streaming (streamText), AND image generation (generateImage) via
Installation
Pick a client and clone the repository into its skills directory.
Installation
About this skill
Use this skill when developing Node.js backend services or CloudBase cloud functions (Express/Koa/NestJS, serverless, backend APIs) that need AI capabilities. Features text generation (generateText), streaming (streamText), AND image generation (generateImage) via @cloudbase/node-sdk ≥3.16.0. Built-in models include Hunyuan (hunyuan-2.0-instruct-20251111 recommended), DeepSeek (deepseek-v3.2 recommended), and hunyuan-image for images. This is the ONLY SDK that supports image generation. NOT for browser/Web apps (use ai-model-web) or WeChat Mini Program (use ai-model-wechat).
How to use
Zainstaluj pakiet @cloudbase/node-sdk poleceniem npm install @cloudbase/node-sdk. Upewnij się, że masz wersję 3.16.0 lub wyższą — sprawdź ją komendą npm list @cloudbase/node-sdk.
Zainicjuj CloudBase w funkcji Node.js lub funkcji chmury, importując bibliotekę i przekazując identyfikator środowiska: const tcb = require('@cloudbase/node-sdk'); const app = tcb.init({ env: 'TWÓJ_ID_ŚRODOWISKA' }).
Utwórz instancję AI wewnątrz funkcji głównej: const ai = app.ai(). Ta instancja daje dostęp do wszystkich dostępnych modeli.
Wybierz model do swojego zadania — do generowania tekstu użyj hunyuan-2.0-instruct-20251111 lub deepseek-v3.2, do tworzenia obrazów użyj hunyuan-image. Wywołaj odpowiednią metodę: generateText() dla tekstu, streamText() do przesyłania odpowiedzi w czasie rzeczywistym, lub generateImage() dla grafik.
Obsłuż odpowiedź modelu i zwróć wynik z funkcji. Pamiętaj, że to narzędzie jest przeznaczone wyłącznie dla backendów Node.js i funkcji CloudBase — nie używaj go w aplikacjach przeglądarki ani WeChat Mini Program.