| |
| """ |
| Test the phase marker formatting fixes |
| """ |
|
|
| import re |
|
|
| def filter_internal_tags(text): |
| """Apply the same filtering logic as the main app""" |
|
|
| |
| text = re.sub(r'</?(?:thinking|reflection|search_quality|query_analysis)>', '', text, flags=re.IGNORECASE) |
| text = re.sub(r'</?(result|answer)>', '', text) |
|
|
| |
| phase_patterns = [ |
| |
| (r'(?<!\*)π―\s*PLANNING:(?!\*)', r'**π― PLANNING:**'), |
| (r'(?<!\*)π§\s*EXECUTING:(?!\*)', r'**π§ EXECUTING:**'), |
| (r'(?<!\*)π€\s*REFLECTING:(?!\*)', r'**π€ REFLECTING:**'), |
| (r'(?<!\*)β
\s*SYNTHESIS:(?!\*)', r'**β
SYNTHESIS:**'), |
| (r'(?<!\*)β
\s*ANSWER:(?!\*)', r'**β
ANSWER:**'), |
|
|
| |
| (r'(?<!\n)(\*\*π―\s*PLANNING:\*\*)', r'\n\n\1'), |
| (r'(?<!\n)(\*\*π§\s*EXECUTING:\*\*)', r'\n\n\1'), |
| (r'(?<!\n)(\*\*π€\s*REFLECTING:\*\*)', r'\n\n\1'), |
| (r'(?<!\n)(\*\*β
\s*SYNTHESIS:\*\*)', r'\n\n\1'), |
| (r'(?<!\n)(\*\*β
\s*ANSWER:\*\*)', r'\n\n\1'), |
|
|
| |
| (r'(\*\*π―\s*PLANNING:\*\*)', r'\1\n'), |
| (r'(\*\*π§\s*EXECUTING:\*\*)', r'\1\n'), |
| (r'(\*\*π€\s*REFLECTING:\*\*)', r'\1\n'), |
| (r'(\*\*β
\s*SYNTHESIS:\*\*)', r'\1\n'), |
| (r'(\*\*β
\s*ANSWER:\*\*)', r'\1\n'), |
| ] |
|
|
| for pattern, replacement in phase_patterns: |
| text = re.sub(pattern, replacement, text) |
|
|
| |
| text = re.sub(r'[ \t]+', ' ', text) |
| text = re.sub(r'\n{4,}', '\n\n\n', text) |
| text = re.sub(r'^\n+', '', text) |
| text = re.sub(r'\n+$', '\n', text) |
|
|
| return text.strip() |
|
|
| |
| problematic_text = """π **Search Progress:** Completed 1/1 searches |
| |
| β **Completed:** pubmed β search_pubmed `Omega-3 and omega-6 fatty acids in ALS treatment`π€ REFLECTING: Based on the search results, it appears that there are some relevant studies related to the role of Omega-3 and omega-6 fatty acids in ALS treatment. However, the information provided is limited to brief summaries and abstracts of research papers. To answer comprehensively, it would be beneficial to investigate further and gather more detailed information about the specific studies, their methodologies, and findings. |
| |
| There are important aspects that need more investigation, such as the specific types and amounts of Omega-3 and omega-6 fatty acids that have been studied, the duration of the studies, and the population samples used. Refining search terms or trying different databases may help to uncover more relevant information and provide a more comprehensive understanding of the topic. |
| |
| Therefore, I will refine my search terms and try different databases to gather more information before proceeding to synthesis. |
| |
| π― PLANNING: To address the role of Omega-3 and omega-6 fatty acids in ALS treatment, I will search PubMed and bioRxiv/medRxiv for peer-reviewed research papers and preprints. |
| |
| π§ EXECUTING: I have searched PubMed and bioRxiv/medRxiv using the planned search terms. |
| |
| π€ REFLECTING: Upon evaluating the search results, I have found relevant studies. |
| |
| β
SYNTHESIS: Based on the available information...""" |
|
|
| print("=" * 70) |
| print("TESTING PHASE MARKER FORMATTING FIXES") |
| print("=" * 70) |
|
|
| print("\n### Original problematic text issues:") |
| print("-" * 40) |
|
|
| |
| issues = [] |
|
|
| |
| if "π€ REFLECTING:" in problematic_text and "**π€ REFLECTING:**" not in problematic_text: |
| issues.append("β Found 'REFLECTING:' without asterisks") |
|
|
| |
| lines = problematic_text.split('\n') |
| for line in lines: |
| if 'π€ REFLECTING:' in line and not line.strip().startswith('π€ REFLECTING:'): |
| issues.append(f"β 'REFLECTING:' not at start of line: {line[:60]}...") |
| if 'π― PLANNING:' in line and not line.strip().startswith('π― PLANNING:') and not line.strip().startswith('**π― PLANNING:**'): |
| issues.append(f"β 'PLANNING:' not at start of line: {line[:60]}...") |
|
|
| |
| phase_markers = ["PLANNING:", "EXECUTING:", "REFLECTING:", "SYNTHESIS:"] |
| for marker in phase_markers: |
| count = problematic_text.count(marker) |
| if count > 1: |
| issues.append(f"β '{marker}' appears {count} times (should be 1)") |
|
|
| print("Issues found:") |
| for issue in issues: |
| print(f" {issue}") |
|
|
| print("\n### After applying filters:") |
| print("-" * 40) |
|
|
| |
| filtered = filter_internal_tags(problematic_text) |
|
|
| |
| print("\nFiltered text (first 500 chars):") |
| print(filtered[:500]) |
| print("...") |
|
|
| print("\n### Verification:") |
| print("-" * 40) |
|
|
| |
| correct_markers = [ |
| "**π― PLANNING:**", |
| "**π§ EXECUTING:**", |
| "**π€ REFLECTING:**", |
| "**β
SYNTHESIS:**" |
| ] |
|
|
| for marker in correct_markers: |
| count = filtered.count(marker) |
| if count == 1: |
| print(f"β
{marker} appears exactly once") |
| |
| marker_pos = filtered.find(marker) |
| if marker_pos > 0: |
| |
| char_before = filtered[marker_pos - 1] |
| if char_before == '\n': |
| print(f" β
On its own line") |
| else: |
| print(f" β Not on its own line (preceded by: {repr(char_before)})") |
| elif count == 0: |
| print(f"βͺ {marker} not found") |
| else: |
| print(f"β {marker} appears {count} times") |
|
|
| |
| incorrect_formats = ["π€ REFLECTING:", "π― PLANNING:", "π§ EXECUTING:", "β
SYNTHESIS:"] |
| for wrong in incorrect_formats: |
| if wrong in filtered and f"**{wrong}**" not in filtered: |
| print(f"β Still contains incorrect format: {wrong}") |
|
|
| print("\n" + "=" * 70) |
| print("SUMMARY") |
| print("=" * 70) |
| print(""" |
| The filtering patterns have been enhanced to: |
| 1. Fix missing asterisks (π€ REFLECTING: β **π€ REFLECTING:**) |
| 2. Ensure markers appear on new lines (add \\n\\n before) |
| 3. Add spacing after markers |
| 4. Clean up excessive whitespace |
| |
| The system prompt has also been updated to: |
| 1. Explicitly require asterisks for bold formatting |
| 2. Emphasize markers must be on new lines |
| 3. Clarify each phase should appear EXACTLY ONCE |
| 4. Show examples of correct vs incorrect formats |
| """) |