Skip to content

Commit a9f8e1f

Browse files
committed
added improvements
1 parent c2382fe commit a9f8e1f

File tree

3 files changed

+281
-237
lines changed

3 files changed

+281
-237
lines changed

src/services/api/routes/retrieve.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,51 +159,57 @@ async def get_entities(
159159
)
160160

161161
@retrieve_router.get(path="/structured-data/types")
162-
async def get_structured_data_types():
162+
async def get_structured_data_types(
163+
brain_id: str = "default",
164+
):
163165
"""
164166
Get all unique types from structured data.
165167
"""
166-
return await get_structured_data_types_controller()
168+
return await get_structured_data_types_controller(brain_id)
167169

168170
@retrieve_router.get(path="/structured-data/{id}")
169171
async def get_structured_data_by_id(
170172
id: str,
173+
brain_id: str = "default",
171174
):
172175
"""
173176
Get structured data by ID.
174177
"""
175-
return await get_structured_data_by_id_controller(id)
178+
return await get_structured_data_by_id_controller(id, brain_id)
176179

177180
@retrieve_router.get(path="/structured-data")
178181
async def get_structured_data_list(
179182
limit: int = 10,
180183
skip: int = 0,
181184
types: Optional[str] = None,
182185
query_text: Optional[str] = None,
186+
brain_id: str = "default",
183187
):
184188
"""
185189
Get a list of structured data.
186190
"""
187191
if types:
188192
types = types.split(",")
189-
return await get_structured_data_list_controller(limit, skip, types, query_text)
193+
return await get_structured_data_list_controller(limit, skip, types, query_text, brain_id)
190194

191195
@retrieve_router.get(path="/observations/labels")
192-
async def get_observation_labels():
196+
async def get_observation_labels(
197+
brain_id: str = "default",
198+
):
193199
"""
194200
Get all unique labels from observations.
195201
"""
196-
return await get_observation_labels_controller()
202+
return await get_observation_labels_controller(brain_id)
197203

198204
@retrieve_router.get(path="/observations/{id}")
199205
async def get_observation_by_id(
200206
id: str,
207+
brain_id: str = "default",
201208
):
202209
"""
203210
Get observation by ID.
204211
"""
205-
return await get_observation_by_id_controller(id)
206-
212+
return await get_observation_by_id_controller(id, brain_id)
207213

208214
@retrieve_router.get(path="/observations")
209215
async def get_observations_list(
@@ -212,10 +218,11 @@ async def get_observations_list(
212218
resource_id: Optional[str] = None,
213219
labels: Optional[str] = None,
214220
query_text: Optional[str] = None,
221+
brain_id: str = "default",
215222
):
216223
"""
217224
Get a list of observations.
218225
"""
219226
if labels:
220227
labels = labels.split(",")
221-
return await get_observations_list_controller(limit, skip, resource_id, labels, query_text)
228+
return await get_observations_list_controller(limit, skip, resource_id, labels, query_text, brain_id)

src/services/api/routes/tasks.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,40 @@
99
"""
1010
import json
1111
from src.utils.logging import log
12-
from fastapi import APIRouter, HTTPException
12+
from fastapi import APIRouter
1313
from src.services.kg_agent.main import cache_adapter
1414

1515
tasks_router = APIRouter(prefix="/tasks", tags=["tasks"])
1616

17-
1817
@tasks_router.get("/{task_id}")
1918
async def get_task(task_id: str, brain_id: str = "default"):
2019
"""
2120
Get the result of a task by its ID.
2221
"""
2322
try:
2423
str_result = cache_adapter.get(f"task:{task_id}", brain_id=brain_id)
25-
2624
if str_result is None:
27-
raise HTTPException(status_code=404, detail="Task not found")
28-
25+
return {
26+
"task_id": task_id,
27+
"status": "pending",
28+
"result": {"message": "Task is still processing or not found"}
29+
}
2930
if isinstance(str_result, bytes):
3031
result = json.loads(str_result.decode("utf-8"))
3132
else:
3233
result = json.loads(str_result)
33-
3434
return {
3535
"task_id": task_id,
36-
"status": result.get("status", "pending"),
36+
"status": result.get("status", "unknown"),
3737
"result": result
3838
}
3939
except Exception as e:
4040
log(f"Error in get_task: {type(e).__name__}: {str(e)}")
4141
return {
4242
"task_id": task_id,
4343
"status": "error",
44-
"result": {"error": str(e)}
44+
"result": {
45+
"error": str(e),
46+
"error_type": type(e).__name__
47+
}
4548
}

0 commit comments

Comments
 (0)