const API_URL = 'https://sdk.senso.ai/api/v1';
const API_KEY = 'YOUR_API_KEY';
async function generateProductContent() {
try {
// First, ensure we have a prompt and template
const promptResponse = await fetch(`${API_URL}/prompts`, {
method: 'POST',
headers: {
'X-API-Key': API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'Product Overview Generator',
text: 'Based on the {{content_type}} information, generate a comprehensive overview including features, benefits, pricing, and target audience. Make it suitable for {{audience}}.'
})
});
const prompt = await promptResponse.json();
const templateResponse = await fetch(`${API_URL}/templates`, {
method: 'POST',
headers: {
'X-API-Key': API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'Product Overview JSON',
text: `{
"product_name": "{{product_name}}",
"overview": {
"summary": "{{summary}}",
"key_features": {{features}},
"benefits": {{benefits}},
"pricing": "{{pricing}}",
"target_audience": "{{target_audience}}"
},
"generated_at": "{{timestamp}}"
}`,
output_type: 'json'
})
});
const template = await templateResponse.json();
// Generate content using the prompt and template
const generateResponse = await fetch(`${API_URL}/generate/prompt`, {
method: 'POST',
headers: {
'X-API-Key': API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
prompt_id: prompt.prompt_id,
template_id: template.template_id,
content_type: 'product documentation and specifications',
category_id: 'your-category-id', // Optional: filter by category
max_results: 10, // Use up to 10 source chunks
save: true // Save the generated content
})
});
const generatedContent = await generateResponse.json();
console.log('Generated content:', generatedContent.generated_text);
console.log('Content saved with ID:', generatedContent.content_id);
console.log('Sources used:', generatedContent.sources.length);
} catch (error) {
console.error('Error generating content:', error);
}
}
generateProductContent();