Basic Usage
Execute a prompt using its key:Using Variables
Pass dynamic variables to your prompts:Using Subject for A/B Testing
Provide subject to enable deterministic A/B testing:The same subject always gets the same version. This ensures users have a consistent experience.
Subject Types
Subject can be either a string or a map:Response Object
TheExecute method returns a PromptResponse struct with the following fields:
Response Fields
Error Handling
Handle common errors when executing prompts:Common Patterns
Pattern 1: Dynamic Email Generation
Pattern 2: Chatbot Responses
Pattern 3: Content Generation
Pattern 4: Fallback Handling
Best Practices
Always use subject for A/B testing
Always use subject for A/B testing
If you want to track metrics or run A/B tests, always provide subject when executing prompts.
Use consistent subject
Use consistent subject
Use the same subject (e.g., user ID) across prompt executions and metric recording for the same subject or session.
Handle errors gracefully
Handle errors gracefully
Always implement error handling with fallback behavior to ensure your application continues working even if the API fails.
Use type-safe variables
Use type-safe variables
While variables accept
map[string]interface{}, consider wrapping in helper functions for type safety.Cache responses when appropriate
Cache responses when appropriate
For expensive or frequently-used prompts, consider caching responses to reduce API calls and latency.
Log request IDs
Log request IDs
Store
RequestID values for debugging and support purposes.Use defer for cleanup
Use defer for cleanup
Use Go’s
defer keyword for any cleanup operations needed after API calls.Next Steps
Recording Metrics
Learn how to track metrics for your prompts
A/B Testing
Set up A/B tests with multiple versions

