Retrieve a single prompt with its content
const prompt = await tracia.prompts.get(slug);
slug
string
interface Prompt { id: string; slug: string; name: string; description: string | null; model: string | null; modelConfigurationId: string | null; currentVersion: number; content: PromptMessage[]; variables: string[]; createdAt: string; updatedAt: string; } interface PromptMessage { id: string; role: 'system' | 'user' | 'assistant'; content: string; }
const prompt = await tracia.prompts.get('welcome-email'); console.log(prompt.name); // "Welcome Email" console.log(prompt.currentVersion); // 3
const prompt = await tracia.prompts.get('welcome-email'); prompt.content.forEach(message => { console.log(`[${message.role}]: ${message.content}`); }); // [system]: You are a helpful assistant... // [user]: Write a welcome email for {{name}}...
const prompt = await tracia.prompts.get('welcome-email'); console.log('Required variables:', prompt.variables); // ['name', 'product'] // Validate before running const myVariables = { name: 'Alice' }; const missing = prompt.variables.filter(v => !(v in myVariables)); if (missing.length > 0) { console.error(`Missing variables: ${missing.join(', ')}`); }
import { TraciaError, TraciaErrorCode } from 'tracia'; try { const prompt = await tracia.prompts.get('welcome-email'); } catch (error) { if (error instanceof TraciaError) { if (error.code === TraciaErrorCode.NOT_FOUND) { console.error('Prompt does not exist'); } } }