| 1 | from graphrag_sdk.steps.Step import Step |
| 2 | from graphrag_sdk.models import GenerativeModelChatSession |
| 3 | |
| 4 | from graphrag_sdk.fixtures.prompts import GRAPH_QA_SYSTEM, GRAPH_QA_PROMPT |
| 5 | import logging |
| 6 | |
| 7 | logger = logging.getLogger(__name__) |
| 8 | logger.setLevel(logging.DEBUG) |
| 9 | |
| 10 | |
| 11 | class QAStep(Step): |
| 12 | """ |
| 13 | QA Step |
| 14 | """ |
| 15 | |
| 16 | def __init__( |
| 17 | self, |
| 18 | chat_session: GenerativeModelChatSession, |
| 19 | config: dict = None, |
| 20 | ) -> None: |
| 21 | self.config = config or {} |
| 22 | self.chat_session = chat_session |
| 23 | |
| 24 | def run(self, question: str, cypher: str, context: str): |
| 25 | |
| 26 | qa_prompt = GRAPH_QA_PROMPT.format( |
| 27 | context=context, cypher=cypher, question=question |
| 28 | ) |
| 29 | |
| 30 | # logger.debug(f"QA Prompt: {qa_prompt}") |
| 31 | qa_response = self.chat_session.send_message(qa_prompt) |
| 32 | |
| 33 | return qa_response.text |