[KM-493] [DED][AI] Fix source extraction in chat
Browse fileschanges:
- Add .vscode/launch.json with debugpy config for FastAPI via uvicorn on port 7860
- Fix _extract_sources in chat.py to read metadata from nested `data` key
- Add debug log for extracted sources
tikcet: https://bukittechnology.atlassian.net/browse/KM-493
- .vscode/launch.json +25 -0
- src/api/v1/chat.py +4 -3
.vscode/launch.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
// Use IntelliSense to learn about possible attributes.
|
| 3 |
+
// Hover to view descriptions of existing attributes.
|
| 4 |
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
| 5 |
+
"version": "0.2.0",
|
| 6 |
+
"configurations": [
|
| 7 |
+
{
|
| 8 |
+
"name": "DataEyond: FastAPI (debug)",
|
| 9 |
+
"type": "debugpy",
|
| 10 |
+
"request": "launch",
|
| 11 |
+
"module": "uvicorn",
|
| 12 |
+
"args": [
|
| 13 |
+
"main:app",
|
| 14 |
+
"--host", "0.0.0.0",
|
| 15 |
+
"--port", "7860",
|
| 16 |
+
"--reload"
|
| 17 |
+
],
|
| 18 |
+
"jinja": true,
|
| 19 |
+
"justMyCode": true,
|
| 20 |
+
"envFile": "${workspaceFolder}/.env",
|
| 21 |
+
"console": "integratedTerminal",
|
| 22 |
+
"cwd": "${workspaceFolder}"
|
| 23 |
+
}
|
| 24 |
+
]
|
| 25 |
+
}
|
src/api/v1/chat.py
CHANGED
|
@@ -66,10 +66,11 @@ def _extract_sources(results: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
|
|
| 66 |
if key not in seen:
|
| 67 |
seen.add(key)
|
| 68 |
sources.append({
|
| 69 |
-
"document_id": meta.get("document_id"),
|
| 70 |
-
"filename": meta.get("filename", "Unknown"),
|
| 71 |
-
"page_label": meta.get("page_label"),
|
| 72 |
})
|
|
|
|
| 73 |
return sources
|
| 74 |
|
| 75 |
|
|
|
|
| 66 |
if key not in seen:
|
| 67 |
seen.add(key)
|
| 68 |
sources.append({
|
| 69 |
+
"document_id": meta.get("data", {}).get("document_id"),
|
| 70 |
+
"filename": meta.get("data", {}).get("filename", "Unknown"),
|
| 71 |
+
"page_label": meta.get("data", {}).get("page_label", "Unknown"),
|
| 72 |
})
|
| 73 |
+
logger.debug(f"Extracted sources: {sources}")
|
| 74 |
return sources
|
| 75 |
|
| 76 |
|