Skip to content

Commit 100818c

Browse files
committed
add new example
1 parent 5122775 commit 100818c

File tree

1 file changed

+148
-0
lines changed

1 file changed

+148
-0
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
"""
2+
State of Mika API Examples
3+
-------------------------
4+
This file demonstrates the usage of each tool available in the State of Mika API.
5+
Each example includes:
6+
- Feature description
7+
- Example API request
8+
- Expected response
9+
10+
All requests are routed through the universal router, which intelligently
11+
directs queries to the appropriate tool.
12+
"""
13+
14+
import requests
15+
import json
16+
from typing import Dict, Any
17+
18+
BASE_URL = "http://localhost:8000/api/v1"
19+
API_KEY = "4f53316d-d945-4f17-a898-804e0ab5bfc9"
20+
21+
22+
def route_query(query: str) -> Dict:
23+
"""Helper function to route all queries through the universal router"""
24+
print("\n=== Starting API Request ===")
25+
26+
# Set up headers for multipart/form-data
27+
headers = {"X-API-Key": API_KEY, "accept": "application/json"}
28+
29+
# Set up form data
30+
form_data = {
31+
"query": (None, query),
32+
"tool": (None, ""),
33+
"parameters_str": (None, ""),
34+
"file": (None, ""),
35+
}
36+
37+
url = f"{BASE_URL}/"
38+
print(f"URL: {url}")
39+
print(f"Headers: {json.dumps(headers, indent=2)}")
40+
print(f"Form data: {form_data}")
41+
42+
try:
43+
print("\nMaking request...")
44+
response = requests.post(
45+
url,
46+
headers=headers,
47+
files=form_data, # Use files parameter for multipart/form-data
48+
)
49+
print(f"Status code: {response.status_code}")
50+
51+
if response.status_code != 200:
52+
print(f"Error response: {response.text}")
53+
else:
54+
print("Request successful!")
55+
56+
return response.json()
57+
except Exception as e:
58+
print(f"Error making request: {str(e)}")
59+
return {"error": str(e)}
60+
61+
62+
def test_connection():
63+
"""Test basic connectivity with a simple query"""
64+
print("\nTesting API connection...")
65+
result = route_query("What is 2 + 2?")
66+
print("\nFull response:")
67+
print(json.dumps(result, indent=2))
68+
return result
69+
70+
71+
def test_news():
72+
"""Test news endpoint"""
73+
print("\nTesting news endpoint...")
74+
result = route_query("Show me the latest crypto news about Bitcoin and Ethereum")
75+
print("\nFull response:")
76+
print(json.dumps(result, indent=2))
77+
return result
78+
79+
80+
def test_math():
81+
"""Test math endpoint"""
82+
print("\nTesting math endpoint...")
83+
result = route_query("Calculate 15% of 150 and add 500")
84+
print("\nFull response:")
85+
print(json.dumps(result, indent=2))
86+
return result
87+
88+
89+
def test_token_price():
90+
"""Test token price endpoint"""
91+
print("\nTesting token price endpoint...")
92+
result = route_query("What is the current price of Solana?")
93+
print("\nFull response:")
94+
print(json.dumps(result, indent=2))
95+
return result
96+
97+
98+
def test_scraper():
99+
"""Test scraper endpoint"""
100+
print("\nTesting scraper endpoint...")
101+
result = route_query("Summarize the article at https://example.com/crypto-article")
102+
print("\nFull response:")
103+
print(json.dumps(result, indent=2))
104+
return result
105+
106+
107+
def test_dex_sales():
108+
"""Test DEX sales endpoint"""
109+
print("\nTesting DEX sales endpoint...")
110+
result = route_query(
111+
"Show me SOL token sales in the last hour for address SOL_TOKEN_MINT_ADDRESS"
112+
)
113+
print("\nFull response:")
114+
print(json.dumps(result, indent=2))
115+
return result
116+
117+
118+
def test_dex_buys():
119+
"""Test DEX buys endpoint"""
120+
print("\nTesting DEX buys endpoint...")
121+
result = route_query("Show me all SOL purchases by wallet WALLET_ADDRESS")
122+
print("\nFull response:")
123+
print(json.dumps(result, indent=2))
124+
return result
125+
126+
127+
def run_all_tests():
128+
"""Run all test functions"""
129+
tests = [
130+
test_connection,
131+
test_news,
132+
test_math,
133+
test_token_price,
134+
test_scraper,
135+
test_dex_sales,
136+
test_dex_buys,
137+
]
138+
139+
for test in tests:
140+
print(f"\n{'=' * 50}")
141+
print(f"Running {test.__name__}")
142+
print("=" * 50)
143+
test()
144+
145+
146+
if __name__ == "__main__":
147+
print("Run test_connection() to test basic connectivity")
148+
print("Run run_all_tests() to test all endpoints")

0 commit comments

Comments
 (0)