Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.

Commit a0d987c

Browse files
Update Frontend app to accommodate recent changes in big merge - Fixes #242 (#243)
1 parent ced825c commit a0d987c

File tree

4 files changed

+49
-13
lines changed

4 files changed

+49
-13
lines changed

frontend/src/components/index_pipeline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ def build_index_step(self):
110110
)
111111

112112
response = self.client.build_index(
113-
storage_name=storage_selection,
114-
index_name=index_name,
113+
storage_container_name=storage_selection,
114+
index_container_name=index_name,
115115
entity_extraction_prompt_filepath=entity_prompt,
116116
summarize_description_prompt_filepath=summarize_prompt,
117117
community_prompt_filepath=community_prompt,

frontend/src/components/tabs.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,11 @@ def get_query_tab(client: GraphragAPI) -> None:
221221
with col1:
222222
query_type = st.selectbox(
223223
"Query Type",
224-
["Global Streaming", "Local Streaming", "Global", "Local"],
225-
help="Select the query type - Each yeilds different results of specificity. Global queries focus on the entire graph structure. Local queries focus on a set of communities (subgraphs) in the graph that are more connected to each other than they are to the rest of the graph structure and can focus on very specific entities in the graph. Global streaming is a global query that displays results as they appear live.",
224+
# ["Global Streaming", "Local Streaming", "Global", "Local"],
225+
["Global", "Local"],
226+
help=(
227+
"Select the query type - Each yeilds different results of specificity. Global queries focus on the entire graph structure. Local queries focus on a set of communities (subgraphs) in the graph that are more connected to each other than they are to the rest of the graph structure and can focus on very specific entities in the graph."
228+
),
226229
)
227230
with col2:
228231
search_indexes = client.get_index_names()

frontend/src/functions.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33

4+
import json
45
import os
56
from pathlib import Path
67
from typing import Optional
@@ -116,13 +117,31 @@ def generate_and_extract_prompts(
116117
client.generate_prompts(
117118
storage_name=storage_name, zip_file_name=zip_file_name, limit=limit
118119
)
119-
_extract_prompts_from_zip(zip_file_name)
120-
update_session_state_prompt_vars(initial_setting=True)
120+
_extract_prompts_from_json(zip_file_name)
121+
update_session_state_prompt_vars(initial_setting=True, prompt_dir=".")
121122
return
122123
except Exception as e:
123124
return e
124125

125126

127+
def _extract_prompts_from_json(json_file_name: str = "prompts.zip"):
128+
with open(json_file_name, "r", encoding="utf-8") as file:
129+
json_data = file.read()
130+
131+
json_data = json.loads(json_data)
132+
133+
with open("entity_extraction_prompt.txt", "w", encoding="utf-8") as file:
134+
file.write(json_data["entity_extraction_prompt"])
135+
136+
with open("summarization_prompt.txt", "w", encoding="utf-8") as file:
137+
file.write(json_data["entity_summarization_prompt"])
138+
139+
with open("community_summarization_prompt.txt", "w", encoding="utf-8") as file:
140+
file.write(json_data["community_summarization_prompt"])
141+
142+
return json_data
143+
144+
126145
def _extract_prompts_from_zip(zip_file_name: str = "prompts.zip"):
127146
with ZipFile(zip_file_name, "r") as zip_ref:
128147
zip_ref.extractall()

frontend/src/graphrag_api.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ def get_storage_container_names(
4444
print(f"Error: {str(e)}")
4545
return e
4646

47-
def upload_files(self, file_payloads: dict, input_storage_name: str):
47+
def upload_files(
48+
self, file_payloads: dict, container_name: str, overwrite: bool = True
49+
):
4850
"""
4951
Upload files to Azure Blob Storage Container.
5052
"""
@@ -53,7 +55,7 @@ def upload_files(self, file_payloads: dict, input_storage_name: str):
5355
self.api_url + "/data",
5456
headers=self.upload_headers,
5557
files=file_payloads,
56-
params={"storage_name": input_storage_name},
58+
params={"container_name": container_name, "overwrite": overwrite},
5759
)
5860
if response.status_code == 200:
5961
return response
@@ -78,8 +80,8 @@ def get_index_names(
7880

7981
def build_index(
8082
self,
81-
storage_name: str,
82-
index_name: str,
83+
storage_container_name: str,
84+
index_container_name: str,
8385
entity_extraction_prompt_filepath: str | StringIO = None,
8486
community_prompt_filepath: str | StringIO = None,
8587
summarize_description_prompt_filepath: str | StringIO = None,
@@ -112,7 +114,10 @@ def build_index(
112114
return requests.post(
113115
url,
114116
files=prompt_files if len(prompt_files) > 0 else None,
115-
params={"index_name": index_name, "storage_name": storage_name},
117+
params={
118+
"storage_container_name": storage_container_name,
119+
"index_container_name": index_container_name,
120+
},
116121
headers=self.headers,
117122
)
118123

@@ -146,11 +151,20 @@ def query_index(self, index_name: str | list[str], query_type: str, query: str):
146151
"""
147152
Submite query to GraphRAG API using specific index and query type.
148153
"""
154+
155+
if isinstance(index_name, list) and len(index_name) > 1:
156+
st.error(
157+
"Multiple index names are currently not supported via the UI. This functionality is being moved into the graphrag library and will be available in a coming release."
158+
)
159+
return {"result": ""}
160+
161+
index_name = index_name if isinstance(index_name, str) else index_name[0]
162+
149163
try:
150164
request = {
151165
"index_name": index_name,
152166
"query": query,
153-
"reformat_context_data": True,
167+
# "reformat_context_data": True,
154168
}
155169
response = requests.post(
156170
f"{self.api_url}/query/{query_type.lower()}",
@@ -223,7 +237,7 @@ def generate_prompts(
223237
Generate graphrag prompts using data provided in a specific storage container.
224238
"""
225239
url = self.api_url + "/index/config/prompts"
226-
params = {"storage_name": storage_name, "limit": limit}
240+
params = {"container_name": storage_name, "limit": limit}
227241
with requests.get(url, params=params, headers=self.headers, stream=True) as r:
228242
r.raise_for_status()
229243
with open(zip_file_name, "wb") as f:

0 commit comments

Comments
 (0)