PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.3
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.3
4.9.3 4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 All 201 releases
← All changes | includes/REST/AIFaq.php +19 -2 4.5.6 → 4.9.3 View file →
@@ -78,13 +78,13 @@
78 78 $keywords = substr( $keywords, 0, self::MAX_KEYWORDS_LENGTH );
79 79 }
80 80
81 81 $prompt = sprintf(
82 - 'Generate an FAQ answer for the question related to %s. The question: %s',
82 + 'Write a clear, concise answer in plain text for the following FAQ question related to %s. The question: %s',
83 83 $keywords,
84 84 $question
85 85 );
86 - $system = __( 'You are a helpful assistant that writes clear, concise FAQ answers.', 'betterdocs' );
86 + $system = __( 'You are a helpful assistant that writes clear, concise FAQ answers in plain text. Do not use any Markdown or special formatting — no asterisks, bold, italics, headings, bullet points, backticks or code fences. Reply with a direct answer written in plain sentences.', 'betterdocs' );
87 87
88 88 $result = $write_ai->generate_text( $prompt, $system );
89 89
90 90 if ( empty( $result['success'] ) ) {
@@ -119,8 +119,25 @@
119 119 protected function clean_response( $text ) {
120 120 $text = trim( $text );
121 121 $text = preg_replace( '/^\s*answer\s*:\s*/i', '', $text );
122 122 $text = preg_replace( '/^\s*\?/', '', $text );
123 + $text = $this->strip_markdown( $text );
124 +
125 + return trim( $text );
126 + }
127 +
128 + /**
129 + * Safety net: strip the common Markdown the model may still emit despite the
130 + * plain-text instruction, so FAQ answers never render literal asterisks.
131 + */
132 + protected function strip_markdown( $text ) {
133 + $text = preg_replace( '/```.*?```/s', '', $text ); // fenced code blocks
134 + $text = preg_replace( '/\*\*(.+?)\*\*/s', '$1', $text ); // **bold**
135 + $text = preg_replace( '/__(.+?)__/s', '$1', $text ); // __bold__
136 + $text = preg_replace( '/`([^`]*)`/', '$1', $text ); // `inline code`
137 + $text = preg_replace( '/^\s{0,3}#{1,6}\s+/m', '', $text ); // # headings
138 + $text = preg_replace( '/^\s{0,3}>\s?/m', '', $text ); // > blockquotes
139 + $text = preg_replace( '/^\s{0,3}[-*+]\s+/m', '', $text ); // -, *, + bullet markers
123 140
124 141 return trim( $text );
125 142 }
126 143 }