-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
177 lines (156 loc) Β· 6.58 KB
/
test_api.py
File metadata and controls
177 lines (156 loc) Β· 6.58 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
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
#!/usr/bin/env python3
"""
Test script for Thinking Engine API
Run this to test the API functionality without starting a server.
Usage:
python test_api.py
"""
from run_model import ThinkingModelInterface
import json
import time
def test_model_directly():
"""Test the model directly without API server"""
print("π§ͺ Testing Thinking Engine Model Directly")
print("=" * 50)
# Initialize model
model = ThinkingModelInterface()
# Test queries
test_queries = [
"hi",
"what is 2+5? show python code",
"how to create a variable?",
"what is machine learning?",
"who is harisha p c"
]
for query in test_queries:
print(f"\nβ Query: {query}")
print("-" * 30)
start_time = time.time()
response = model.think(query)
processing_time = time.time() - start_time
print(f"π€ Response: {response[:200]}{'...' if len(response) > 200 else ''}")
print(".2f")
def simulate_api_calls():
"""Simulate API calls that would be made to the server"""
print("\nπ Simulating API Calls")
print("=" * 50)
# This simulates what the API server would do
model = ThinkingModelInterface()
# Simulate different API endpoints
api_calls = [
# Unified chat endpoint
{"endpoint": "/chat", "method": "POST", "data": {"query": "what is 10*5?"}},
{"endpoint": "/think", "method": "POST", "data": {"query": "explain variables in python"}},
# Agent-specific endpoints
{"endpoint": "/agents/web", "method": "POST", "data": {"query": "what is AI?"}},
{"endpoint": "/agents/code", "method": "POST", "data": {"code": "print('Hello World')"}},
{"endpoint": "/agents/file", "method": "POST", "data": {"action": "read", "file_path": "data/python_knowledge.json"}},
{"endpoint": "/agents/reasoning", "method": "POST", "data": {"query": "If all cats are mammals and some mammals are pets, are all cats pets?"}},
]
for call in api_calls:
endpoint = call["endpoint"]
method = call["method"]
data = call["data"]
print(f"\nπ¨ API Call: {method} {endpoint}")
print(f" Data: {json.dumps(data, indent=2)}")
# Simulate processing based on endpoint
start_time = time.time()
if endpoint == "/chat":
response = model.think(data["query"])
api_response = {
"response": response,
"query": data["query"],
"processing_time": round(time.time() - start_time, 2),
"timestamp": "2025-01-11T12:00:00"
}
elif endpoint == "/think":
response = model.cortex.reason(data["query"])
api_response = {
"response": response,
"query": data["query"],
"processing_time": round(time.time() - start_time, 2),
"method": "direct_reasoning",
"timestamp": "2025-01-11T12:00:00"
}
elif endpoint == "/agents/web":
result = model.cortex.web_agent.run(None, query=data["query"])
api_response = {
"response": result.get("summary", "No results found"),
"query": data["query"],
"processing_time": round(time.time() - start_time, 2),
"agent": "web_agent",
"status": result.get("status", "unknown"),
"timestamp": "2025-01-11T12:00:00"
}
elif endpoint == "/agents/code":
result = model.cortex.code_agent.run("execute", code=data["code"])
api_response = {
"response": result,
"code_length": len(data["code"]),
"processing_time": round(time.time() - start_time, 2),
"agent": "code_agent",
"timestamp": "2025-01-11T12:00:00"
}
elif endpoint == "/agents/file":
result = model.cortex.file_agent.run(None, data["action"], path=data["file_path"])
api_response = {
"response": result,
"action": data["action"],
"file_path": data["file_path"],
"processing_time": round(time.time() - start_time, 2),
"agent": "file_agent",
"timestamp": "2025-01-11T12:00:00"
}
elif endpoint == "/agents/reasoning":
result = model.cortex.reasoning_agent.run(None, data["query"])
api_response = {
"response": result,
"query": data["query"],
"processing_time": round(time.time() - start_time, 2),
"agent": "reasoning_agent",
"timestamp": "2025-01-11T12:00:00"
}
print(f"π¨ API Response: {json.dumps(api_response, indent=2)[:400]}...")
def show_deployment_info():
"""Show information about deployment options"""
print("\nπ Deployment Information")
print("=" * 50)
print("π Model Format: .think (JSON-based)")
print("π API Endpoints:")
print(" POST /chat - Unified AI chat interface")
print(" POST /think - Direct model reasoning")
print(" POST /agents/web - Web search and research")
print(" POST /agents/file - File operations")
print(" POST /agents/code - Code execution and analysis")
print(" POST /agents/reasoning - Logical reasoning")
print(" GET /health - Check service health")
print(" GET /info - Get model information")
print()
print("πββοΈ To start API server:")
print(" python deploy_api.py")
print()
print("π³ Docker deployment:")
print(" docker build -t thinking-engine .")
print(" docker run -p 8080:8080 thinking-engine")
print()
print("βοΈ Cloud deployment options:")
print(" β’ AWS Lambda")
print(" β’ Google Cloud Functions")
print(" β’ Azure Functions")
print(" β’ Heroku")
print(" β’ DigitalOcean App Platform")
print()
print("π§ Agent-Specific Usage Examples:")
print(" curl -X POST http://localhost:8080/agents/web \\")
print(" -H 'Content-Type: application/json' \\")
print(" -d '{\"query\": \"what is machine learning?\"}'")
print()
print(" curl -X POST http://localhost:8080/agents/code \\")
print(" -H 'Content-Type: application/json' \\")
print(" -d '{\"code\": \"print(2+3)\"}'")
if __name__ == "__main__":
test_model_directly()
simulate_api_calls()
show_deployment_info()
print("\nβ
All tests completed successfully!")
print("π Your Thinking Engine is ready for production deployment!")