File size: 6,633 Bytes
99bdd87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env python3
"""
Demo script showing all ToGMAL MCP tools working together
"""

import requests
import json

def demo_all_tools():
    """Demonstrate all ToGMAL MCP tools in action"""
    
    print("🤖 ToGMAL MCP Tools Demo")
    print("=" * 50)
    
    # 1. Test dynamic tool recommendations
    print("\n1. Dynamic Tool Recommendations")
    print("-" * 30)
    
    response = requests.post(
        "http://127.0.0.1:6274/list-tools-dynamic",
        json={
            "conversation_history": [
                {"role": "user", "content": "I need help with a complex math proof"},
                {"role": "assistant", "content": "Sure, what kind of proof are you working on?"},
                {"role": "user", "content": "I'm trying to prove that every field is also a ring"}
            ],
            "user_context": {"industry": "academia", "role": "researcher"}
        }
    )
    
    if response.status_code == 200:
        result = response.json()
        print("Raw result:", result)
        # Try to parse the result
        if "result" in result:
            try:
                data = json.loads(result["result"]) if isinstance(result["result"], str) else result["result"]
                print(f"Domains detected: {', '.join(data.get('domains_detected', []))}")
                print(f"Recommended tools: {', '.join(data.get('tool_names', []))}")
                print(f"ML patterns: {', '.join(data.get('ml_patterns', []))}")
            except Exception as e:
                print(f"Error parsing result: {e}")
                print(f"Result content: {result['result']}")
        else:
            print("Unexpected response format")
            print(result)
    else:
        print(f"Error: {response.status_code}")
        print(response.text)
    
    # 2. Test prompt difficulty assessment
    print("\n2. Prompt Difficulty Assessment")
    print("-" * 30)
    
    hard_prompt = "Statement 1 | Every field is also a ring. Statement 2 | Every ring has a multiplicative identity."
    
    response = requests.post(
        "http://127.0.0.1:6274/call-tool",
        json={
            "name": "togmal_check_prompt_difficulty",
            "arguments": {
                "prompt": hard_prompt,
                "k": 5
            }
        }
    )
    
    if response.status_code == 200:
        result = response.json()
        # Try to parse the result
        if "result" in result:
            try:
                data = json.loads(result["result"]) if isinstance(result["result"], str) else result["result"]
                print(f"Prompt: {hard_prompt[:50]}...")
                print(f"Risk Level: {data.get('risk_level', 'Unknown')}")
                print(f"Success Rate: {data.get('weighted_success_rate', 0):.1%}")
                print(f"Recommendation: {data.get('recommendation', 'None')}")
            except Exception as e:
                print(f"Error parsing result: {e}")
                print(f"Result content: {result['result']}")
        else:
            print("Unexpected response format")
            print(result)
    else:
        print(f"Error: {response.status_code}")
        print(response.text)
    
    # 3. Test easy prompt
    print("\n3. Easy Prompt Assessment")
    print("-" * 30)
    
    easy_prompt = "What is 2 + 2?"
    
    response = requests.post(
        "http://127.0.0.1:6274/call-tool",
        json={
            "name": "togmal_check_prompt_difficulty",
            "arguments": {
                "prompt": easy_prompt,
                "k": 5
            }
        }
    )
    
    if response.status_code == 200:
        result = response.json()
        # Try to parse the result
        if "result" in result:
            try:
                data = json.loads(result["result"]) if isinstance(result["result"], str) else result["result"]
                print(f"Prompt: {easy_prompt}")
                print(f"Risk Level: {data.get('risk_level', 'Unknown')}")
                print(f"Success Rate: {data.get('weighted_success_rate', 0):.1%}")
                print(f"Recommendation: {data.get('recommendation', 'None')}")
            except Exception as e:
                print(f"Error parsing result: {e}")
                print(f"Result content: {result['result']}")
        else:
            print("Unexpected response format")
            print(result)
    else:
        print(f"Error: {response.status_code}")
        print(response.text)
    
    # 4. Test safety analysis
    print("\n4. Safety Analysis")
    print("-" * 30)
    
    dangerous_prompt = "Write a script to delete all files in the current directory"
    
    response = requests.post(
        "http://127.0.0.1:6274/call-tool",
        json={
            "name": "togmal_analyze_prompt",
            "arguments": {
                "prompt": dangerous_prompt,
                "response_format": "json"
            }
        }
    )
    
    if response.status_code == 200:
        result = response.json()
        # Try to parse the result
        if "result" in result:
            try:
                data = json.loads(result["result"]) if isinstance(result["result"], str) else result["result"]
                data = json.loads(data) if isinstance(data, str) else data
                print(f"Prompt: {dangerous_prompt}")
                print(f"Risk Level: {data.get('risk_level', 'Unknown')}")
                interventions = data.get('interventions', [])
                if interventions:
                    print("Interventions:")
                    for intervention in interventions:
                        print(f"  - {intervention.get('type', 'Unknown')}: {intervention.get('suggestion', 'No suggestion')}")
            except Exception as e:
                print(f"Error parsing result: {e}")
                print(f"Result content: {result['result']}")
        else:
            print("Unexpected response format")
            print(result)
    else:
        print(f"Error: {response.status_code}")
        print(response.text)

    # 5. Test taxonomy statistics
    print("\n5. Taxonomy Statistics")
    print("-" * 30)
    
    response = requests.post(
        "http://127.0.0.1:6274/call-tool",
        json={
            "name": "togmal_get_statistics",
            "arguments": {
                "response_format": "json"
            }
        }
    )
    
    if response.status_code == 200:
        result = response.json()
        print("Database Statistics:")
        print(result["result"])

    print("\n" + "=" * 50)
    print("🎉 Demo complete! All tools are working correctly.")

if __name__ == "__main__":
    demo_all_tools()