forked from Minima-AI-Inc/minima
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequestor.py
More file actions
31 lines (27 loc) · 923 Bytes
/
Copy pathrequestor.py
File metadata and controls
31 lines (27 loc) · 923 Bytes
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
import httpx
import logging
import asyncio
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
REQUEST_DATA_URL = "http://indexer:8000/query"
REQUEST_HEADERS = {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
async def request_data(query):
payload = {
"query": query
}
async with httpx.AsyncClient() as client:
try:
logger.info(f"Requesting data from indexer with query: {query}")
response = await client.post(REQUEST_DATA_URL,
headers=REQUEST_HEADERS,
json=payload)
response.raise_for_status()
data = response.json()
logger.info(f"Received data: {data}")
return data
except Exception as e:
logger.error(f"HTTP error: {e}")
return { "error": str(e) }