Skip to content

Commit 7f02082

Browse files
Fix/json mode community reports (microsoft#1713)
* Patch json mode on Community Reports * Semversioner * Wording oopsie
1 parent 96219a2 commit 7f02082

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "patch",
3+
"description": "Patch json mode for community reports"
4+
}

graphrag/index/operations/summarize_communities/community_reports_extractor.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
"""A module containing 'CommunityReportsResult' and 'CommunityReportsExtractor' models."""
55

6+
import json
67
import logging
78
import traceback
89
from dataclasses import dataclass
@@ -79,12 +80,17 @@ async def __call__(self, inputs: dict[str, Any]):
7980
)
8081
response = await self._llm(
8182
prompt,
82-
json=True,
83+
json=True, # Leaving this as True to avoid creating new cache entries
8384
name="create_community_report",
84-
json_model=CommunityReportResponse,
85+
json_model=CommunityReportResponse, # A model is required when using json mode
8586
model_parameters={"max_tokens": self._max_report_length},
8687
)
87-
output = response.parsed_json
88+
89+
# TODO: Json mode is currently broken on fnllm: https://github.com/microsoft/essex-toolkit/issues/364
90+
# once fixed, just assign to output the response.parsed_json
91+
output = CommunityReportResponse.model_validate(
92+
json.loads(response.output.content)
93+
)
8894
except Exception as e:
8995
log.exception("error generating community report")
9096
self._on_error(e, traceback.format_exc(), None)

0 commit comments

Comments
 (0)