deepseek-proxy / test_tool_client.py
adityaxess's picture
Deploy 24/7 DeepSeek Proxy Server
aedcabb
Raw History Blame Contribute Delete
3.08 kB
"""
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()