Create chain to check if context provides complete answer.
(self)
| 290 | self.answer_check_chain = self._create_answer_check_chain() |
| 291 | |
| 292 | def _create_answer_check_chain(self): |
| 293 | """Create chain to check if context provides complete answer.""" |
| 294 | prompt = PromptTemplate( |
| 295 | input_variables=["query", "context"], |
| 296 | template=( |
| 297 | "Given the query: '{query}'\n\n" |
| 298 | "And the current context:\n{context}\n\n" |
| 299 | "Does this context provide a complete answer to the query? " |
| 300 | "If yes, provide the answer. If no, state that the answer is incomplete.\n\n" |
| 301 | "Is complete answer (Yes/No):\nAnswer (if complete):" |
| 302 | ) |
| 303 | ) |
| 304 | return prompt | self.llm.with_structured_output(AnswerCheck) |
| 305 | |
| 306 | def _truncate_context(self, text: str, max_tokens: int = LLM_CONTEXT_LIMIT) -> str: |
| 307 | """Truncate text to fit within token limit.""" |