### Install and Configure Chimit Prompt Package via Composer Source: https://context7.com/chimit/prompt/llms.txt Bash commands for installing the Chimit Prompt package via Composer, verifying the installation, and setting up the directory structure for managing prompt templates. Creates necessary directories for organizing prompts by feature (seo, content, support) and demonstrates creating a sample Markdown prompt file with Blade templating syntax including conditional directives. ```bash # Install the package composer require chimit/prompt # Verify installation composer show chimit/prompt # Expected output: # name : chimit/prompt # descrip. : Manage AI prompts in Blade style. # keywords : laravel, prompts, blade, ai # versions : * v1.0.0 # type : library # license : MIT # Create prompts directory structure mkdir -p resources/prompts mkdir -p resources/prompts/seo mkdir -p resources/prompts/content mkdir -p resources/prompts/support # Create a sample prompt file cat > resources/prompts/welcome.md << 'EOF' Hello {{ $name }}! Welcome to our AI-powered application. How can I assist you today? @if(isset($isPremium) && $isPremium) As a premium member, you have access to advanced features. @endif EOF # Test the prompt in tinker php artisan tinker # >>> Chimit\Prompt::get('welcome', ['name' => 'Alice', 'isPremium' => true]) ``` -------------------------------- ### Install Chimit Prompt Package (Bash) Source: https://github.com/chimit/prompt/blob/main/README.md Installs the Chimit Prompt package using Composer. This is the initial step to integrate the package into your Laravel project. No specific inputs or outputs are required beyond the package installation. ```bash composer require chimit/prompt ``` -------------------------------- ### Generate Product Description with OpenAI GPT API Source: https://context7.com/chimit/prompt/llms.txt Complete PHP example demonstrating how to render dynamic prompts using the Chimit Prompt package and send them to OpenAI's GPT-4 model. The AiContentGenerator class accepts product data, renders a templated prompt with product details and target market information, and returns AI-generated marketing copy. Requires OpenAI PHP client library and access to GPT-4 API. ```php openai = $openai; } public function generateProductDescription(object $product): string { // Render prompt using Prompt package $prompt = Prompt::get('marketing/product-description', [ 'product' => $product, 'brand' => $product->brand, 'category' => $product->category, 'features' => $product->features, 'targetMarket' => 'tech-savvy millennials' ]); // Send to OpenAI $response = $this->openai->chat()->create([ 'model' => 'gpt-4', 'messages' => [ [ 'role' => 'system', 'content' => 'You are a creative marketing copywriter.' ], [ 'role' => 'user', 'content' => $prompt ] ], 'temperature' => 0.7, 'max_tokens' => 500 ]); return $response->choices[0]->message->content; } } // Usage $product = Product::find(1); $generator = new AiContentGenerator($openaiClient); $description = $generator->generateProductDescription($product); echo $description; // Output: AI-generated marketing copy based on your prompt template ``` -------------------------------- ### Example AI Prompt with Blade Syntax (Markdown) Source: https://github.com/chimit/prompt/blob/main/README.md An example of an AI prompt file written in Markdown, incorporating Blade syntax for dynamic content insertion. It uses variables like $product->name, $product->description, and PHP expressions like number_format and implode. It also demonstrates conditional rendering with @if and unsafe HTML rendering with {!! !!}. ```markdown You are an SEO expert specializing in e-commerce. Generate a compelling meta description for this product. **Product:** {{ $product->name }} **Price:** ${{ number_format($product->price, 2) }} **Product Description:** --- {!! $product->description !!} --- @if($product->discount_percentage > 0) **Special Offer:** {{ $product->discount_percentage }}% OFF - Limited Time! @endif Requirements: - Maximum 160 characters - Include the product name and key benefits - Create urgency if there's a discount - Target keywords: {{ implode(', ', $keywords) }} ``` -------------------------------- ### Retrieve and Render AI Prompt with Blade Templating in PHP Source: https://context7.com/chimit/prompt/llms.txt Uses the Prompt::get() method to retrieve and render a Markdown prompt file with dynamic data using Blade templating. Accepts prompt name in dot or slash notation and optional data array. Throws FileNotFoundException if the prompt file doesn't exist. The example demonstrates rendering an SEO product meta description with product data and keywords. ```php 'Wireless Noise-Cancelling Headphones', 'price' => 299.99, 'description' => '

Premium wireless headphones with active noise cancellation, 30-hour battery life, and superior sound quality.

', 'discount_percentage' => 15 ]; // Keywords for SEO targeting $keywords = ['wireless headphones', 'bluetooth', 'noise cancelling']; try { // Render the prompt with dynamic data $prompt = Prompt::get('seo/product-meta', [ 'product' => $product, 'keywords' => $keywords ]); echo $prompt; } catch (FileNotFoundException $e) { // Handle missing prompt file echo "Error: " . $e->getMessage(); } ``` -------------------------------- ### Create Markdown Prompt File with Blade Templating Syntax Source: https://context7.com/chimit/prompt/llms.txt Demonstrates creating a Markdown prompt file in the resources/prompts/ directory with full Blade syntax support. The file uses Blade directives like {{ }} for variables, {!! !! } for unescaped HTML, and @if conditionals to create dynamic SEO product meta descriptions. Organizes prompts in subdirectories for better structure. ```markdown You are an SEO expert specializing in e-commerce. Generate a compelling meta description for this product. **Product:** {{ $product->name }} **Price:** ${{ number_format($product->price, 2) }} **Product Description:** --- {!! $product->description !!} --- @if($product->discount_percentage > 0) **Special Offer:** {{ $product->discount_percentage }}% OFF - Limited Time! @endif Requirements: - Maximum 160 characters - Include the product name and key benefits - Create urgency if there's a discount - Target keywords: {{ implode(', ', $keywords) }} ``` -------------------------------- ### Alternative Prompt Access Notations (PHP) Source: https://context7.com/chimit/prompt/llms.txt Demonstrates accessing Chimit prompts using either dot notation (similar to Laravel views) or slash notation (path style). Both methods are functionally equivalent and resolve to the same prompt file located in the resources/prompts directory. This allows for flexible prompt referencing. Dependencies include the Chimit library. ```php 'John Doe', 'userType' => 'premium' ]); // Slash notation (path style) - equivalent to above $prompt2 = Prompt::get('ai/chatbot/welcome', [ 'userName' => 'John Doe', 'userType' => 'premium' ]); // Both resolve to: resources/prompts/ai/chatbot/welcome.md ``` -------------------------------- ### Dynamic Prompt Generation with Blade Loops and Conditionals (PHP) Source: https://context7.com/chimit/prompt/llms.txt Renders a complex prompt using Blade templating, incorporating loops for sections and key points, and conditionals for including specific instructions. It takes structured data, processes it through the Chimit Prompt::get method, and prepares it for an AI service call. Dependencies include the Chimit library and sample data. Outputs a formatted prompt string. ```php 'Sustainable Web Development', 'tone' => 'professional', 'targetAudience' => 'software developers', 'sections' => [ 'Introduction', 'Best Practices', 'Tools and Technologies', 'Conclusion' ], 'keyPoints' => [ 'Reduce carbon footprint of web applications', 'Optimize asset delivery and caching', 'Use green hosting providers', 'Implement efficient algorithms' ], 'wordCount' => 1500, 'includeCodeExamples' => true ]; // Render complex prompt with loops and conditionals $prompt = Prompt::get('content/blog-writer', $blogData); // Use the prompt with your AI service $response = openai_api_call($prompt); ``` ```markdown You are a professional technical writer specializing in software development. **Assignment:** Write a comprehensive blog post about "{{ $topic }}" **Target Audience:** {{ $targetAudience }} **Tone:** {{ ucfirst($tone) }} **Word Count:** Approximately {{ number_format($wordCount) }} words **Required Sections:** @foreach($sections as $index => $section) {{ $index + 1 }}. {{ $section }} @endforeach **Key Points to Cover:** @foreach($keyPoints as $point) - {{ $point }} @endforeach @if($includeCodeExamples) **Important:** Include practical code examples where relevant to demonstrate concepts. @endif **Style Guidelines:** - Use clear, concise language - Include real-world examples - Provide actionable insights - Maintain {{ $tone }} tone throughout ``` -------------------------------- ### Render AI Prompts with Blade Data (PHP) Source: https://github.com/chimit/prompt/blob/main/README.md Renders a prompt file using the Prompt::get() method, passing dynamic data. This method takes the prompt file path and an array of variables to be used within the Blade syntax of the prompt. It returns the rendered prompt string. ```php use Chimit\Prompt; $prompt = Prompt::get('seo/product-meta', [ 'product' => $product, 'keywords' => ['wireless headphones', 'bluetooth', 'noise cancelling'] ]); ``` -------------------------------- ### Robust Error Handling for Prompt Generation (PHP) Source: https://context7.com/chimit/prompt/llms.txt Provides a function `generateAiPrompt` that handles potential errors during prompt rendering, such as missing prompt files or invalid data. It uses try-catch blocks to manage `FileNotFoundException`, `InvalidArgumentException`, and general exceptions, logging errors appropriately. Returns the generated prompt string or null if an error occurs. Dependencies include the Chimit library and Laravel's logging facilities. ```php $e->getMessage() ]); return null; } catch (\InvalidArgumentException $e) { // Log validation errors \Log::warning("Invalid prompt data: {$e->getMessage()}"); return null; } catch (\Exception $e) { // Catch any other errors \Log::error("Error rendering prompt: {$e->getMessage()}"); return null; } } // Usage $prompt = generateAiPrompt('analysis/code-review', [ 'context' => 'Laravel controller', 'code' => $sourceCode, 'language' => 'PHP' ]); if ($prompt !== null) { // Send to AI service $aiResponse = callAiService($prompt); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.