This repository was archived by the owner on May 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 421
Expand file tree
/
Copy pathgraph.py
More file actions
63 lines (57 loc) · 2 KB
/
graph.py
File metadata and controls
63 lines (57 loc) · 2 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
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import os
import traceback
from fastapi import (
APIRouter,
Depends,
HTTPException,
)
from fastapi.responses import StreamingResponse
from graphrag_app.logger.load_logger import load_pipeline_logger
from graphrag_app.utils.azure_clients import AzureClientManager
from graphrag_app.utils.common import (
sanitize_name,
subscription_key_check,
validate_index_file_exist,
)
graph_route = APIRouter(
prefix="/graph",
tags=["Graph Operations"],
)
if os.getenv("KUBERNETES_SERVICE_HOST"):
graph_route.dependencies.append(Depends(subscription_key_check))
@graph_route.get(
"/graphml/{container_name}",
summary="Retrieve a GraphML file of the knowledge graph",
response_description="GraphML file successfully downloaded",
)
async def get_graphml_file(
container_name, sanitized_container_name: str = Depends(sanitize_name)
):
# validate graphml file existence
azure_client_manager = AzureClientManager()
graphml_filename = "graph.graphml"
blob_filepath = f"output/{graphml_filename}" # expected file location of the graph based on the workflow
validate_index_file_exist(sanitized_container_name, blob_filepath)
try:
blob_client = azure_client_manager.get_blob_service_client().get_blob_client(
container=sanitized_container_name, blob=blob_filepath
)
blob_stream = blob_client.download_blob().chunks()
return StreamingResponse(
blob_stream,
media_type="application/octet-stream",
headers={"Content-Disposition": f"attachment; filename={graphml_filename}"},
)
except Exception as e:
logger = load_pipeline_logger()
logger.error(
message="Could not fetch graphml file",
cause=e,
stack=traceback.format_exc(),
)
raise HTTPException(
status_code=500,
detail=f"Could not fetch graphml file for '{container_name}'.",
)