@rethink-ai/core
v0.1.7
Published
Official TypeScript SDK for ReThink Core API
Readme
ReThink Core SDK
Official SDK untuk mengakses ReThink Core API dengan mudah dan efisien
Bahasa Indonesia | English Documentation
Dokumentasi Bahasa Indonesia
@rethink-ai/core adalah library client resmi yang dirancang untuk mempermudah integrasi dengan layanan AI dari ReThink Core. Mendukung text generation (streaming & non-streaming) serta image generation
🔑 Mendapatkan API Key
Sebelum memulai, Anda wajib memiliki API Key yang bisa didapatkan dengan cara:
- Kunjungi halaman ReThink Core
- Daftar akun baru atau login
- Masuk ke menu dashboard untuk menyalin API Key Anda
📦 Instalasi
Install package menggunakan npm, yarn, atau pnpm:
npm install @rethink-ai/core🚀 Penggunaan Dasar
1. Inisialisasi Client
Import dan inisialisasi client. API Key bersifat wajib (dengan batasan tertentu untuk mengakses model berdasarkan tier)
import { rethink } from '@rethink-ai/core';
const client = new rethink({
apiKey: 'YOUR_API_KEY_HERE'
});2. Generate Teks (Chat Completion)
Mendapatkan respons teks sederhana dari model AI
async function contohGenerateTeks() {
try {
const response = await client.text.generate({
model: 'rethink-v1', // atau 'mistral', 'gpt-oss-120b', dll.
prompt: 'Jelaskan apa itu nebula'
});
console.log('AI:', response.content);
// Output: Nebula adalah...
} catch (error) {
console.error('Terjadi kesalahan:', error.message);
}
}3. Streaming Teks (Real-time)
Mendapatkan respons secara bertahap (per kata/chunk) seperti efek mengetik. Sangat disarankan untuk pengalaman pengguna yang lebih baik
async function contohStreaming() {
try {
const stream = await client.text.generate({
model: 'rethink-v1',
prompt: 'Buatkan puisi pendek tentang hujan.',
stream: true // Aktifkan mode streaming
});
process.stdout.write('AI: ');
// Loop async iterator
for await (const chunk of stream) {
process.stdout.write(chunk);
}
console.log('\n--- Selesai ---');
} catch (error) {
console.error('Error streaming:', error.message);
}
}4. Generate Gambar
Membuat gambar berdasarkan deskripsi teks (prompt)
async function contohGenerateGambar() {
try {
const response = await client.image.generate({
model: 'flux', // Model gambar
prompt: 'Buatkan gambar galaksi bima sakti',
width: 1024,
height: 768
});
console.log('URL Gambar:', response.url);
} catch (error) {
console.error('Gagal membuat gambar:', error.message);
}
}🛠️ Fitur Utama
- Type-Safe: Dibangun dengan TypeScript, memberikan autocompletion dan validasi tipe yang kuat
- Convenience Methods: API yang intuitif (
text.generate,image.generate) - Streaming Support: Dukungan native untuk Server-Sent Events (SSE) yang mudah digunakan
- Multi-Model: Akses ke berbagai model AI (OpenAI, Mistral, Gemini, Flux, dll) melalui satu interface
English Documentation
@rethink-ai/core is the official client library for integrating with ReThink Core AI services. It supports text generation (streaming & non-streaming) and image generation
🔑 Getting an API Key
Before starting, you must obtain an API Key:
- Visit ReThink Core
- Sign up for a new account or login
- Go to the dashboard to copy your API Key
📦 Installation
npm install @rethink-ai/core🚀 Basic Usage
1. Client Initialization
import { rethink } from '@rethink-ai/core';
const client = new rethink({
apiKey: 'YOUR_API_KEY_HERE'
});2. Text Generation
const response = await client.text.generate({
model: 'rethink-v1',
prompt: 'Explain AI in one sentence.'
});
console.log(response.content);3. Text Streaming
const stream = await client.text.generate({
model: 'rethink-v1',
prompt: 'Write a haiku about code.',
stream: true
});
for await (const chunk of stream) {
process.stdout.write(chunk);
}4. Image Generation
const response = await client.image.generate({
model: 'flux',
prompt: 'Generate an image of milky way',
width: 1024,
height: 768
});
console.log(response.url);