rynn-k / gists
writecream.js javascript
const axios = require('axios');

class WriteCream {
    chat = async function ({ question, logic } = {}) {
        try {
            if (!question) throw new Error('Question is required.');
            
            const { data } = await axios.get('https://8pe3nv3qha.execute-api.us-east-1.amazonaws.com/default/llm_chat', {
                params: {
                    query: JSON.stringify([...(logic ? [{
                        role: 'system',
                        content: logic
                    }] : []), {
                        role: 'user',
                        content: question
                    }]),
                    link: 'writecream.com'
                }
            });
            
            return data.response_content;
        } catch (error) {
            throw new Error(error.message);
        }
    }
    
    image = async function ({ prompt, ratio = '1:1' } = {}) {
        try {
            const ratios = ['1:1', '16:9', '2:3', '3:2', '4:5', '5:4', '9:16', '21:9', '9:21'];
            if (!prompt) throw new Error('Prompt is required.');
            if (!ratios.includes(ratio)) throw new Error(`Available ratios: ${ratios.join(', ')}.`);
            
            const { data } = await axios.get('https://1yjs1yldj7.execute-api.us-east-1.amazonaws.com/default/ai_image', {
                params: {
                    prompt: prompt,
                    aspect_ratio: ratio,
                    link: 'writecream.com'
                }
            });
            
            return data.image_link;
        } catch (error) {
            throw new Error(error.message);
        }
    }
}

// Usage:
const w = new WriteCream();
w.image({
    prompt: 'girl wearing glasses',
    ratio: '16:9'
}).then(console.log);
1762 bytes ยท Updated Mar 9, 2026