@@ -39,8 +39,8 @@ def build_prompt(self, project_id: int, prompt_name: str, chunk_text: Optional[s
3939 prompt_record = self .prompt_repository .get_by_name (prompt_name )
4040 if prompt_record :
4141 prompt_template = prompt_record [2 ] # content is the third column (index 2)
42- elif prompt_name == "default" :
43- # Hardcoded default prompt template for dataset generation
42+ elif prompt_name == "default" or prompt_name == "qa_pairs" :
43+ # Hardcoded default prompt template for Q&A dataset generation
4444 prompt_template = """Generate {datasets_per_chunk} question-answer pairs from the following content.
4545
4646Content: {chunk}
@@ -52,6 +52,8 @@ def build_prompt(self, project_id: int, prompt_name: str, chunk_text: Optional[s
5252- Vary question types (factual, analytical, applicative)
5353- Focus on key concepts, important details, and relationships in the content
5454
55+ {taxonomy_instructions}
56+
5557{purpose_context}{audience_context}{complexity_level_context}
5658
5759Format your response as a JSON array of objects with this structure:
@@ -84,6 +86,12 @@ def build_prompt(self, project_id: int, prompt_name: str, chunk_text: Optional[s
8486 # Ensure datasets_per_chunk is in param_dict
8587 param_dict ['datasets_per_chunk' ] = datasets_per_chunk
8688
89+ # Ensure taxonomy-related parameters exist
90+ param_dict .setdefault ('taxonomy_instructions' , '' )
91+ param_dict .setdefault ('taxonomy_name' , '' )
92+ param_dict .setdefault ('taxonomy_description' , '' )
93+ param_dict .setdefault ('taxonomy_categories' , '' )
94+
8795 # Load taxonomy if specified
8896 taxonomy_info = None
8997 if taxonomy_project and taxonomy_name :
@@ -108,6 +116,9 @@ def build_prompt(self, project_id: int, prompt_name: str, chunk_text: Optional[s
108116 if taxonomy_info :
109117 param_dict .update (taxonomy_info )
110118
119+ # Handle legacy {Na} placeholder (maps to taxonomy_name)
120+ param_dict .setdefault ('Na' , param_dict .get ('taxonomy_name' , '' ))
121+
111122 # Replace {chunk} with actual chunk text if provided
112123 if chunk_text is not None :
113124 if "{chunk}" in prompt_template :
@@ -244,12 +255,39 @@ def build_question_generation_prompt(self, project_id: int, chunk_text: str,
244255 except Exception as e :
245256 logger .warning (f"Could not load taxonomy { taxonomy_project } /{ taxonomy_name } : { e } " )
246257
258+ # Ensure taxonomy-related parameters exist even when no taxonomy is loaded
259+ param_dict .setdefault ('taxonomy_instructions' , '' )
260+ param_dict .setdefault ('taxonomy_name' , '' )
261+ param_dict .setdefault ('taxonomy_description' , '' )
262+ param_dict .setdefault ('taxonomy_categories' , '' )
263+
247264 prompt_record = self .prompt_repository .get_by_name ("question_generation" )
248265 if prompt_record :
249266 prompt_template = prompt_record [2 ]
250267 else :
251268 # Fallback template
252- prompt_template = "Generate a question based on the following content: {chunk_text}"
269+ prompt_template = """Generate {datasets_per_chunk} questions from the following content.
270+
271+ Content: {chunk_text}
272+
273+ Instructions:
274+ - Create diverse, high-quality questions that test understanding of the content
275+ - Ensure questions are answerable using only the provided information
276+ - Vary question types (factual, analytical, applicative)
277+ - Focus on key concepts, important details, and relationships in the content
278+
279+ {taxonomy_instructions}
280+
281+ {purpose_context}{audience_context}{complexity_level_context}
282+
283+ Format your response as a JSON array of objects with this structure:
284+ [
285+ {{
286+ "question": "Your question here",
287+ "category": "content_category",
288+ "difficulty": "easy|medium|hard"
289+ }}
290+ ]"""
253291
254292 # Format the prompt with the parameters and the chunk text
255293 final_prompt = prompt_template .format (
@@ -319,12 +357,39 @@ def build_answer_generation_prompt(self, project_id: int, chunk_text: str,
319357 except Exception as e :
320358 logger .warning (f"Could not load taxonomy { taxonomy_project } /{ taxonomy_name } : { e } " )
321359
360+ # Ensure taxonomy-related parameters exist even when no taxonomy is loaded
361+ param_dict .setdefault ('taxonomy_instructions' , '' )
362+ param_dict .setdefault ('taxonomy_name' , '' )
363+ param_dict .setdefault ('taxonomy_description' , '' )
364+ param_dict .setdefault ('taxonomy_categories' , '' )
365+
322366 prompt_record = self .prompt_repository .get_by_name ("answer_generation" )
323367 if prompt_record :
324368 prompt_template = prompt_record [2 ]
325369 else :
326370 # Fallback template
327- prompt_template = "Generate an answer for the following content: {chunk_text}"
371+ prompt_template = """Generate {datasets_per_chunk} answers for the following question based on the content.
372+
373+ Question: {question}
374+ Content: {chunk_text}
375+
376+ Instructions:
377+ - Provide accurate, comprehensive answers based only on the given content
378+ - Ensure answers are supported by the provided information
379+ - Include relevant details and context from the content
380+
381+ {taxonomy_instructions}
382+
383+ {purpose_context}{audience_context}{complexity_level_context}
384+
385+ Format your response as a JSON array of objects with this structure:
386+ [
387+ {{
388+ "answer": "Your answer here",
389+ "category": "content_category",
390+ "confidence": 0.0-1.0
391+ }}
392+ ]"""
328393
329394 # Format the prompt with the parameters and the chunk text
330395 final_prompt = prompt_template .format (
@@ -394,12 +459,38 @@ def build_summarization_prompt(self, project_id: int, chunk_text: str,
394459 except Exception as e :
395460 logger .warning (f"Could not load taxonomy { taxonomy_project } /{ taxonomy_name } : { e } " )
396461
462+ # Ensure taxonomy-related parameters exist even when no taxonomy is loaded
463+ param_dict .setdefault ('taxonomy_instructions' , '' )
464+ param_dict .setdefault ('taxonomy_name' , '' )
465+ param_dict .setdefault ('taxonomy_description' , '' )
466+ param_dict .setdefault ('taxonomy_categories' , '' )
467+
397468 prompt_record = self .prompt_repository .get_by_name ("summarization" )
398469 if prompt_record :
399470 prompt_template = prompt_record [2 ]
400471 else :
401472 # Fallback template
402- prompt_template = "Summarize the following content in a concise manner: {chunk_text}"
473+ prompt_template = """Generate {datasets_per_chunk} summaries from the following content.
474+
475+ Content: {chunk_text}
476+
477+ Instructions:
478+ - Create concise, accurate summaries that capture the main points
479+ - Focus on key concepts and important details
480+ - Maintain factual accuracy from the source content
481+
482+ {taxonomy_instructions}
483+
484+ {purpose_context}{audience_context}{complexity_level_context}
485+
486+ Format your response as a JSON array of objects with this structure:
487+ [
488+ {{
489+ "summary": "Your summary here",
490+ "key_points": ["Point 1", "Point 2", "Point 3"],
491+ "category": "content_category"
492+ }}
493+ ]"""
403494
404495 # Format the prompt with the parameters and the chunk text
405496 final_prompt = prompt_template .format (
0 commit comments