diff --git a/.semversioner/next-release/patch-20250430230945680958.json b/.semversioner/next-release/patch-20250430230945680958.json new file mode 100644 index 00000000..4817ae4f --- /dev/null +++ b/.semversioner/next-release/patch-20250430230945680958.json @@ -0,0 +1,4 @@ +{ + "type": "patch", + "description": "Fix Community Report prompt tuning response" +} diff --git a/graphrag/prompt_tune/generator/entity_types.py b/graphrag/prompt_tune/generator/entity_types.py index d40a079d..d68ab521 100644 --- a/graphrag/prompt_tune/generator/entity_types.py +++ b/graphrag/prompt_tune/generator/entity_types.py @@ -47,7 +47,10 @@ async def generate_entity_types( if json_mode: response = await model.achat( - entity_types_prompt, history=history, json_model=EntityTypesResponse + entity_types_prompt, + history=history, + json=json_mode, + json_model=EntityTypesResponse, ) parsed_model = response.parsed_response return parsed_model.entity_types if parsed_model else [] diff --git a/graphrag/prompt_tune/prompt/entity_types.py b/graphrag/prompt_tune/prompt/entity_types.py index 99b21db6..ff3e799a 100644 --- a/graphrag/prompt_tune/prompt/entity_types.py +++ b/graphrag/prompt_tune/prompt/entity_types.py @@ -84,6 +84,6 @@ END OF EXAMPLE 3 REAL DATA: The following section is the real data. You should use only this real data to prepare your answer. Generate Entity Types only. Task: {task} Text: {input_text} -JSON response: +JSON response format: {{"entity_types": [] }} """ diff --git a/graphrag/prompt_tune/prompt/language.py b/graphrag/prompt_tune/prompt/language.py index 68fd0402..b8425e69 100644 --- a/graphrag/prompt_tune/prompt/language.py +++ b/graphrag/prompt_tune/prompt/language.py @@ -6,7 +6,7 @@ DETECT_LANGUAGE_PROMPT = """ You are an intelligent assistant that helps a human to analyze the information in a text document. Given a sample text, help the user by determining what's the primary language of the provided texts. -Examples are: "English", "Spanish", "Japanese", "Portuguese" among others. +Examples are: "English", "Spanish", "Japanese", "Portuguese" among others. Reply ONLY with the language name. Text: {input_text} Language:""" diff --git a/graphrag/prompt_tune/template/community_report_summarization.py b/graphrag/prompt_tune/template/community_report_summarization.py index db3f6c13..b0d037ab 100644 --- a/graphrag/prompt_tune/template/community_report_summarization.py +++ b/graphrag/prompt_tune/template/community_report_summarization.py @@ -18,22 +18,22 @@ The report should include the following sections: - DETAILED FINDINGS: A list of 5-10 key insights about the community. Each insight should have a short summary followed by multiple paragraphs of explanatory text grounded according to the grounding rules below. Be comprehensive. Return output as a well-formed JSON-formatted string with the following format. Don't use any unnecessary escape sequences. The output should be a single JSON object that can be parsed by json.loads. - {{ + {{{{ "title": , "summary": , "rating": , "rating_explanation": , "findings": [ - {{ + {{{{ "summary":, "explanation": - }}, - {{ + }}}}, + {{{{ "summary":, "explanation": - }} + }}}} ] - }} + }}}} # Grounding Rules Points supported by data should list their data references as follows: @@ -48,6 +48,7 @@ For example: where 1, 5, 7, 23, 2, 34, 46, and 64 represent the id (not the index) of the relevant data record. Do not include information where the supporting evidence for it is not provided. +Your answers should be in {language}. # Example Input ----------- @@ -70,30 +71,30 @@ id,source,target,description 43,HARMONY ASSEMBLY,UNITY MARCH,Harmony Assembly is organizing the Unity March Output: -{{ +{{{{ "title": "Verdant Oasis Plaza and Unity March", "summary": "The community revolves around the Verdant Oasis Plaza, which is the location of the Unity March. The plaza has relationships with the Harmony Assembly, Unity March, and Tribune Spotlight, all of which are associated with the march event.", "rating": 5.0, "rating_explanation": "The impact severity rating is moderate due to the potential for unrest or conflict during the Unity March.", "findings": [ - {{ + {{{{ "summary": "Verdant Oasis Plaza as the central location", "explanation": "Verdant Oasis Plaza is the central entity in this community, serving as the location for the Unity March. This plaza is the common link between all other entities, suggesting its significance in the community. The plaza's association with the march could potentially lead to issues such as public disorder or conflict, depending on the nature of the march and the reactions it provokes. [Data: Entities (5), Relationships (37, 38, 39, 40, 41,+more)]" - }}, - {{ + }}}}, + {{{{ "summary": "Harmony Assembly's role in the community", "explanation": "Harmony Assembly is another key entity in this community, being the organizer of the march at Verdant Oasis Plaza. The nature of Harmony Assembly and its march could be a potential source of threat, depending on their objectives and the reactions they provoke. The relationship between Harmony Assembly and the plaza is crucial in understanding the dynamics of this community. [Data: Entities(6), Relationships (38, 43)]" - }}, - {{ + }}}}, + {{{{ "summary": "Unity March as a significant event", "explanation": "The Unity March is a significant event taking place at Verdant Oasis Plaza. This event is a key factor in the community's dynamics and could be a potential source of threat, depending on the nature of the march and the reactions it provokes. The relationship between the march and the plaza is crucial in understanding the dynamics of this community. [Data: Relationships (39)]" - }}, - {{ + }}}}, + {{{{ "summary": "Role of Tribune Spotlight", "explanation": "Tribune Spotlight is reporting on the Unity March taking place in Verdant Oasis Plaza. This suggests that the event has attracted media attention, which could amplify its impact on the community. The role of Tribune Spotlight could be significant in shaping public perception of the event and the entities involved. [Data: Relationships (40)]" - }} + }}}} ] -}} +}}}} # Real Data