编程

在 Laravel 应用中使用 Markdown 和 Blade 管理 AI 提示(Prompt)

22 2025-10-13 10:24:00

@chimit 为 Laravel 开发的 Prompt 包提供了一种简单的方法来管理 Markdown 文件中的 AI 提示,并充分利用了 Blade 的强大功能。你可以在 resources/prompts 文件夹中定义提示模板,其内容可能类似于以下示例:

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) }}

你可以使用该包的 Prompt 类渲染这些模板:

use Chimit\Prompt;
 
$prompt = Prompt::get('seo/product-meta', [
    'product' => $product,
    'keywords' => ['wireless headphones', 'bluetooth', 'noise canceling']
]);

目前,该软件包缺少配置选项或使用 Artisan 命令创建新模板的功能;然而,其背后的理念是一种使用 Blade 等工具渲染动态提示的有趣方法。

👩‍💻 在 GitHub 上开始使用此软件包:chimit/prompt

下一篇