File size: 1,103 Bytes
92d2175
040a6c6
92d2175
 
 
 
 
040a6c6
 
 
92d2175
040a6c6
 
 
 
 
 
 
92d2175
040a6c6
 
 
 
92d2175
 
040a6c6
 
92d2175
040a6c6
 
 
 
 
 
 
92d2175
040a6c6
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
Text Tool - Process reversed text questions
"""

from typing import Dict, Any

def is_likely_reversed(text: str) -> bool:
    words = text.split()
    if len(words) < 3:
        return False
    
    reversed_indicators = [
        text.startswith('.'),
        text.endswith('fI'),
        'ecnetnes' in text,
        'rewsna' in text,
        'noitseuq' in text
    ]
    
    return sum(reversed_indicators) >= 2

def reverse_text(text: str) -> str:
    return text[::-1]

def reverse_text_if_needed(question: str, ai_brain=None) -> Dict[str, Any]:
    if is_likely_reversed(question):
        reversed_question = reverse_text(question)
        
        return {
            "should_reverse": True,
            "original_text": question,
            "processed_text": reversed_question,
            "confidence": "high",
            "reasoning": "Text appears to be written backwards"
        }
    
    return {
        "should_reverse": False,
        "original_text": question,
        "processed_text": question,
        "confidence": "high",
        "reasoning": "Text appears normal"
    }