-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_thinking_filter.py
More file actions
83 lines (70 loc) · 2.6 KB
/
test_thinking_filter.py
File metadata and controls
83 lines (70 loc) · 2.6 KB
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
#!/usr/bin/env python3
"""Test script for Qwen thinking block filtering."""
import asyncio
import os
import sys
from qwen_cli import QwenCLI
async def test_thinking_filter():
"""Test that thinking blocks are properly filtered."""
print("Testing Qwen thinking block filtering...")
# Initialize Qwen CLI
qwen = QwenCLI()
# Test prompts that should trigger thinking
test_prompts = [
{
"messages": [{"role": "user", "content": "What can you do?"}],
"description": "Simple capability question"
},
{
"messages": [{"role": "user", "content": "Help me write a Python function to calculate fibonacci numbers"}],
"description": "Code generation request"
},
{
"messages": [{"role": "user", "content": "Explain the concept of recursion"}],
"description": "Explanation request"
}
]
for test_case in test_prompts:
print(f"\n{'='*60}")
print(f"Test: {test_case['description']}")
print(f"Prompt: {test_case['messages'][0]['content']}")
print(f"{'='*60}")
response_text = ""
try:
async for chunk in qwen.stream_completion(
messages=test_case['messages'],
model="qwen3-coder-plus",
temperature=0.7,
max_tokens=500
):
response_text += chunk
print(chunk, end='', flush=True)
except Exception as e:
print(f"\nError: {e}")
continue
print(f"\n{'='*60}")
# Check if common thinking patterns are in the response
thinking_indicators = [
"The user is asking",
"The user wants",
"Based on the system information",
"available tools",
"I need to",
"I should"
]
found_thinking = False
for indicator in thinking_indicators:
if indicator.lower() in response_text.lower():
print(f"⚠️ WARNING: Found thinking pattern in response: '{indicator}'")
found_thinking = True
if not found_thinking:
print("✅ No thinking patterns detected - filtering successful!")
else:
print("❌ Thinking patterns found - filtering may need adjustment")
print("\n" + "="*60)
print("Test completed!")
if __name__ == "__main__":
# Set environment for testing
os.environ['DEBUG'] = '0'
os.environ['NODE_ENV'] = 'production'
asyncio.run(test_thinking_filter())