function ajax_about() { if ( ! current_user_can( 'manage_options' ) || ! check_ajax_referer( 'sd_qa_about', '_n', false ) ) { wp_send_json_error( 'Auth failed' ); } $o = get_option( self::OPT, array() ); $provider = isset( $o['ai_provider'] ) ? $o['ai_provider'] : 'gemini'; $okey = isset( $o['openai_key'] ) ? $o['openai_key'] : ''; $gkey = isset( $o['gemini_key'] ) ? $o['gemini_key'] : ''; if ( 'openai' === $provider && ! $okey ) { wp_send_json_error( 'Add your OpenAI API key in SaveDealy → Settings.' ); } if ( 'gemini' === $provider && ! $gkey ) { wp_send_json_error( 'Add your Gemini API key in SaveDealy → Settings (free at aistudio.google.com/apikey).' ); } $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : ''; $aff = isset( $_POST['aff'] ) ? esc_url_raw( wp_unslash( $_POST['aff'] ) ) : ''; $context = ''; if ( $aff ) { $resp = wp_remote_get( $aff, array( 'timeout' => 8, 'redirection' => 5, 'user-agent' => 'Mozilla/5.0', 'sslverify' => false ) ); if ( ! is_wp_error( $resp ) ) { $body = wp_remote_retrieve_body( $resp ); if ( preg_match( '/]+name=["\']description["\'][^>]+content=["\']([^"\']+)/i', $body, $mm ) ) { $context = $mm[1]; } elseif ( preg_match( '/]*>([^<]+)/i', $body, $mm ) ) { $context = $mm[1]; } } } $prompt = "Write an SEO-optimized \"About {$name}\" section for a coupon & deals website. 2 short paragraphs, natural tone, mention {$name} coupons, promo codes and savings, and encourage shoppers to check this page before buying. No headings, no markdown, no quotes."; if ( $context ) { $prompt .= " Brand context: {$context}"; } if ( 'gemini' === $provider ) { $model = 'gemini-2.0-flash'; $url = 'https://generativelanguage.googleapis.com/v1beta/models/' . $model . ':generateContent?key=' . rawurlencode( $gkey ); $r = wp_remote_post( $url, array( 'timeout' => 45, 'headers' => array( 'Content-Type' => 'application/json' ), 'body' => wp_json_encode( array( 'contents' => array( array( 'parts' => array( array( 'text' => $prompt ) ) ) ), 'generationConfig' => array( 'temperature' => 0.7, 'maxOutputTokens' => 600 ), ) ), ) ); if ( is_wp_error( $r ) ) { wp_send_json_error( 'Gemini error: ' . $r->get_error_message() ); } $data = json_decode( wp_remote_retrieve_body( $r ), true ); if ( isset( $data['candidates'][0]['content']['parts'][0]['text'] ) ) { wp_send_json_success( trim( $data['candidates'][0]['content']['parts'][0]['text'] ) ); } if ( isset( $data['error']['message'] ) ) { wp_send_json_error( 'Gemini: ' . $data['error']['message'] ); } wp_send_json_error( 'Unexpected Gemini response' ); } $r = wp_remote_post( 'https://api.openai.com/v1/chat/completions', array( 'timeout' => 45, 'headers' => array( 'Authorization' => 'Bearer ' . $okey, 'Content-Type' => 'application/json' ), 'body' => wp_json_encode( array( 'model' => 'gpt-4o-mini', 'messages' => array( array( 'role' => 'user', 'content' => $prompt ) ), 'temperature' => 0.7, 'max_tokens' => 500, ) ), ) ); if ( is_wp_error( $r ) ) { wp_send_json_error( 'API error: ' . $r->get_error_message() ); } $data = json_decode( wp_remote_retrieve_body( $r ), true ); if ( isset( $data['choices'][0]['message']['content'] ) ) { wp_send_json_success( trim( $data['choices'][0]['message']['content'] ) ); } if ( isset( $data['error']['message'] ) ) { wp_send_json_error( 'OpenAI: ' . $data['error']['message'] ); } wp_send_json_error( 'Unexpected AI response' ); } Search - SaveDealy

All Deals & Coupons

Showing deals and coupons located in Montgomery