File size: 3,081 Bytes
aedcabb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Demo Client Script simulating 'my tool' communicating with the server:
Workflow: my tool <----> server <----> DeepSeek API
"""

import json
import urllib.request

SERVER_URL = "http://127.0.0.1:8000"

def call_api(endpoint: str, method: str = "GET", payload: dict = None):
    url = f"{SERVER_URL}{endpoint}"
    data = json.dumps(payload).encode("utf-8") if payload else None
    req = urllib.request.Request(url, data=data, method=method)
    req.add_header("Content-Type", "application/json")
    try:
        with urllib.request.urlopen(req) as resp:
            return json.loads(resp.read().decode("utf-8"))
    except Exception as e:
        print(f"Error calling {url}: {e}")
        return None

def main():
    print("=" * 65)
    print("🛠️ MY TOOL CLIENT - PURE PYTHON SERVER TEST SUITE")
    print("Workflow: [my tool] <----> [server] <----> [DeepSeek API]")
    print("=" * 65)

    # 1. Health Check
    print("\n1. Health Check & Active Session Tab:")
    health = call_api("/health")
    print(json.dumps(health, indent=2))

    # 2. List Tabs
    print("\n2. Fetching Available Chat Tabs / Sessions:")
    tabs_info = call_api("/v1/tabs")
    print(json.dumps(tabs_info, indent=2))

    # 3. Query WITHOUT model specified (Testing default auto-selection of DeepSeek-V3 Standard)
    print("\n3. Query WITHOUT model parameter (Testing Default Fallback):")
    req_default = {
        "messages": [
            {"role": "user", "content": "What is the default model being used?"}
        ]
    }
    resp1 = call_api("/v1/chat/completions", method="POST", payload=req_default)
    if resp1:
        print("   Resolved Model:", resp1.get("model"))
        print("   Is Default Fallback:", resp1.get("model_resolution", {}).get("is_default_fallback"))
        print("   Chat Session ID:", resp1.get("chat_session_id"))
        print("   Response:", resp1["choices"][0]["message"]["content"][:250])

    # 4. Follow-up query in same tab
    print("\n4. Follow-up query in same tab (Testing Continuous Session Context):")
    req_followup = {
        "messages": [
            {"role": "user", "content": "Can you summarize your response in 1 concise sentence?"}
        ]
    }
    resp2 = call_api("/v1/chat/completions", method="POST", payload=req_followup)
    if resp2:
        print("   Chat Session ID:", resp2.get("chat_session_id"))
        print("   Response:", resp2["choices"][0]["message"]["content"][:250])

    # 5. Query WITH explicit model specified
    print("\n5. Query WITH explicit model specified ('DeepSeek-R1'):")
    req_explicit = {
        "model": "DeepSeek-R1",
        "messages": [
            {"role": "user", "content": "Solve: 25 * 4 + 10"}
        ]
    }
    resp3 = call_api("/v1/chat/completions", method="POST", payload=req_explicit)
    if resp3:
        print("   Resolved Model:", resp3.get("model"))
        print("   Response:", resp3["choices"][0]["message"]["content"][:250])

    print("\n" + "=" * 65)
    print("✅ TEST SUITE COMPLETED SUCCESSFULLY!")
    print("=" * 65)

if __name__ == "__main__":
    main()