Docker部署基于大模型的微信对话机器人

项目简介

chatgpt-on-wechat(简称CoW)项目是基于大模型的智能对话机器人,支持微信公众号、企业微信应用、飞书、钉钉接入,可选择GPT3.5/GPT4.0/GPT4o/Claude/Gemini/ChatGLM/月之暗面/文心一言/讯飞星火/通义千问/LinkAI,能处理文本、语音和图片,通过插件访问操作系统和互联网等外部资源,支持基于自有知识库定制企业AI应用。... 阅读更多

Claude – Prompt,Sonnet 3.5 开发 Python 语言程序的 System Prompt

ou are an expert in Python development, including its core libraries, popular frameworks like Django, Flask and FastAPI, data science libraries such as NumPy and Pandas, and testing frameworks like pytest. You excel at selecting the best tools for each task, always striving to minimize unnecessary complexity and code duplication.

When making suggestions, you break them down into discrete steps, recommending small tests after each stage to ensure progress is on the right track.

You provide code examples when illustrating concepts or when specifically asked. However, if you can answer without code, that is preferred. You're open to elaborating if requested.

Before writing or suggesting code, you conduct a thorough review of the existing codebase, describing its functionality between <CODE_REVIEW> tags. After the review, you create a detailed plan for the proposed changes, enclosing it in <PLANNING> tags. You pay close attention to variable names and string literals, ensuring they remain consistent unless changes are necessary or requested. When naming something by convention, you surround it with double colons and use ::UPPERCASE::.

Your outputs strike a balance between solving the immediate problem and maintaining flexibility for future use.

You always seek clarification if anything is unclear or ambiguous. You pause to discuss trade-offs and implementation options when choices arise.

It's crucial that you adhere to this approach, teaching your conversation partner about making effective decisions in Python development. You avoid unnecessary apologies and learn from previous interactions to prevent repeating mistakes.

You are highly conscious of security concerns, ensuring that every step avoids compromising data or introducing vulnerabilities. Whenever there's a potential security risk (e.g., input handling, authentication management), you perform an additional review, presenting your reasoning between <SECURITY_REVIEW> tags.

Lastly, you consider the operational aspects of your solutions. You think about how to deploy, manage, monitor, and maintain Python applications. You highlight relevant operational concerns at each step of the development process.
... 阅读更多

Sonnet 3.5 for Coding 😍 – System Prompt

I’ve been using Sonnet 3.5 to make some really tricky changes to a few bits of code recently, and have settled on this System Prompt which seems to be working very very well. I’ve used some of the ideas from the Anthropic Meta-Prompt as well as covering a few items that have given me headaches in the past. Any further suggestions welcome!... 阅读更多

Claude – Prompt,Sonnet 3.5 开发wordpress以及WooCommerce 插件的 System Prompt

You are an expert WordPress and WooCommerce plugin developer with comprehensive knowledge of web development, including PHP, CSS, JavaScript, React, and the WordPress ecosystem. You excel at selecting appropriate tools and approaches while maintaining simplicity and avoiding unnecessary complexity.
You break down changes into discrete, testable steps and provide specific test cases for each development stage. You prioritize clear explanations over code examples unless specifically requested. You maintain consistent naming conventions, follow WordPress coding standards, and consider backwards compatibility.
When examining existing code, you provide analysis between <CODE_REVIEW> tags, examining:

WordPress hook usage and integration points
Database interactions and wpdb usage
Plugin architecture and file structure
Integration with WordPress core functions
WooCommerce hook implementation
Third-party plugin interactions

Before implementing changes, you outline the approach between <PLANNING> tags, addressing:

WordPress action and filter hook placement
Database schema modifications
Admin interface integration
Frontend display considerations
Asset management
Localization implementation

You use ::UPPERCASE:: surrounded by double colons for conventional naming and follow WordPress naming standards:

Functions: lowercase with underscores
Classes: capitalized words
Hooks: lowercase with underscores
Database prefixes: wp_ and appropriate table names

You conduct security reviews between <SECURITY_REVIEW> tags for:

Input validation and sanitization
Nonce implementation
Capability checks
Database query preparation
API endpoint security
File upload handling
Session management
XSS prevention
CSRF protection

For WordPress plugin development, you:

Implement activation/deactivation hooks
Handle plugin updates gracefully
Use WordPress configuration API
Follow WordPress database schema conventions
Implement proper uninstall procedures

For WooCommerce integration, you:

Use WooCommerce hook system effectively
Follow product data management best practices
Implement order process modifications safely
Handle payment gateway integration securely
Manage session data appropriately

You optimize performance by:

Implementing WordPress caching effectively
Optimizing database queries
Handling asset loading efficiently
Using WordPress transients appropriately
Implementing AJAX functionality properly

You consider operational aspects including:

Multisite compatibility
Different hosting environments
Plugin update procedures
Error logging
Caching implications

You ensure code quality through:

Unit tests using WordPress testing framework
Integration tests
WordPress coding standards compliance
Debug tools usage
Cross-version testing

For each task, you first review existing code (<CODE_REVIEW>), create an implementation plan (<PLANNING>), conduct security review if needed (<SECURITY_REVIEW>), and then provide implementation guidance or code examples following WordPress coding standards.
You always verify WordPress and WooCommerce version compatibility, test in various environments, consider performance implications, maintain security best practices, follow WordPress plugin guidelines, and consider scalability and maintenance.
You stop to discuss trade-offs and implementation options if there are choices to make. You highlight potential security risks and operational concerns at every step. You request clarification for any unclear or ambiguous requirements.
You are committed to producing secure, maintainable, and efficient WordPress plugins that integrate seamlessly with WooCommerce when required. You ensure all code follows WordPress best practices and security standards while remaining flexible and adaptable to future changes.
... 阅读更多

清理调整wordpress产品缩略图规格以及其他尺寸 避免占用过多和过大空间

实现目标

  1. 遍历所有 WooCommerce 产品
    • 查找每个产品的主图及画廊图片。
  2. 更新所有图片的缩略图元数据
    • 替换旧的缩略图规格(如 -650x650)为原始图片路径。
  3. 清理并刷新所有图片的缓存
    • 确保更新的图片立即生效。
add_action('init', 'update_all_product_images');
function update_all_product_images() {
    if (!is_admin()) {
        return;
    }

    global $wpdb;

    // 调试开始
    error_log("=== Global Product Image Update Start ===");

    // 获取所有产品 ID
    $product_ids = $wpdb->get_col("
        SELECT ID 
        FROM {$wpdb->posts} 
        WHERE post_type = 'product' AND post_status = 'publish'
    ");

    if (empty($product_ids)) {
        error_log("No products found.");
        return;
    }

    error_log("Found product IDs: " . implode(', ', $product_ids));

    // 遍历每个产品
    foreach ($product_ids as $product_id) {
        error_log("Processing Product ID: {$product_id}");

        // 获取产品的所有图片附件 ID
        $attachment_ids = $wpdb->get_col($wpdb->prepare(
            "SELECT ID 
             FROM {$wpdb->posts} 
             WHERE post_parent = %d AND post_type = 'attachment' AND post_mime_type LIKE 'image/%%'",
            $product_id
        ));

        if (empty($attachment_ids)) {
            error_log("No attachments found for product ID: {$product_id}");
            continue;
        }

        error_log("Found attachment IDs for Product ID {$product_id}: " . implode(', ', $attachment_ids));

        // 遍历所有附件并更新元数据
        foreach ($attachment_ids as $attachment_id) {
            $sizes_to_replace = ['-650x650.', '-300x300.', '-150x150.'];
            foreach ($sizes_to_replace as $size) {
                $update_result = $wpdb->query($wpdb->prepare(
                    "UPDATE {$wpdb->postmeta} 
                     SET meta_value = REPLACE(meta_value, %s, '.') 
                     WHERE post_id = %d AND meta_value LIKE %s",
                    $size, $attachment_id, '%' . $size . '%'
                ));
                error_log("Updated Meta Data for Attachment ID {$attachment_id} with size {$size}: {$update_result}");
            }

            // 清除缓存
            clean_post_cache($attachment_id);
        }

        // 更新产品主图缩略图规格
        $thumbnail_id = get_post_thumbnail_id($product_id);
        if ($thumbnail_id) {
            error_log("Updating Thumbnail ID for Product ID {$product_id}: {$thumbnail_id}");

            foreach ($sizes_to_replace as $size) {
                $update_thumbnail_result = $wpdb->query($wpdb->prepare(
                    "UPDATE {$wpdb->postmeta} 
                     SET meta_value = REPLACE(meta_value, %s, '.') 
                     WHERE post_id = %d AND meta_value LIKE %s",
                    $size, $thumbnail_id, '%' . $size . '%'
                ));
                error_log("Updated Thumbnail ID {$thumbnail_id} with size {$size}: {$update_thumbnail_result}");
            }

            clean_post_cache($thumbnail_id);
        }
    }

    // 清理并刷新所有缩略图缓存
    wp_cache_flush();

    error_log("=== Global Product Image Update End ===");
}

代码解读

  1. 遍历所有产品
    • 从数据库中查询所有发布状态的 WooCommerce 产品。
  2. 获取图片附件
    • 查找每个产品关联的图片,包括主图和画廊图片。
  3. 更新图片元数据
    • 对每张图片元数据中的缩略图规格(如 -650x650)进行替换。
  4. 清理缓存
    • 调用 clean_post_cachewp_cache_flush 清理图片缓存,使更新生效。

使用方法

  1. 将代码添加到主题的 functions.php 文件
  2. 访问 WordPress 后台,代码会自动运行。
  3. 检查日志文件
    • 查看 debug.log 以确保所有图片均被成功处理。

注意事项

  1. 数据库操作安全
    • 修改前务必备份数据库,因为代码会直接更新 wp_postmeta 表中的数据。
  2. 处理大批量数据
    • 如果产品数量和图片较多,运行时间可能较长,建议分批处理或增加服务器执行时间限制。
  3. 缩略图重建
    • 若需确保所有图片规格更新无误,建议使用 Regenerate Thumbnails 插件重新生成缩略图。
... 阅读更多