Spaces:
Sleeping
Sleeping
Commit ·
88e7ced
1
Parent(s): e0b2bb1
Rm convo
Browse filesFiles changed (5)
- utils/augment.py+8-9
- utils/cloud_llm.py+23-42
- utils/local_llm.py+22-41
- utils/processor.py+16-24
- utils/rag.py+4-16
223 unmodified lines22422522622722822923023123223323439 unmodified lines27427527627727827928028128215 unmodified lines298299300301302303304305306307223 unmodified linesretry_text = paraphraser.paraphrase(text, difficulty="easy")elif attempt == 1:# Second try: More aggressive paraphrasing with medical focusmedical_prompt = f"Rewrite this medical response to be more professional and accurate:\n\n{text}"retry_text = paraphraser.paraphrase(text, difficulty="hard", custom_prompt=medical_prompt)else:# Third try: Direct medical content generationmedical_prompt = f"Provide a professional medical response to this question:\n\n{text}"retry_text = paraphraser.paraphrase(text, difficulty="hard", custom_prompt=medical_prompt)if retry_text and not is_invalid_response(retry_text):39 unmodified linesreturn enhancedelse:prompt = ("Improve the medical terminology in this text while preserving all factual information:\n\n"f"{text}\n\n""Return only the improved text with better medical terminology:")enhanced = paraphraser.paraphrase(text, difficulty="hard", custom_prompt=prompt)15 unmodified lineselse:# Fallback to original implementationcontext_prompts = [f"Rewrite this medical question as if asked by a patient in an emergency room:\n\n{question}",f"Rewrite this medical question as if asked by a patient in a routine checkup:\n\n{question}",f"Rewrite this medical question as if asked by a patient with chronic conditions:\n\n{question}",f"Rewrite this medical question as if asked by a patient's family member:\n\n{question}"]for i, prompt in enumerate(context_prompts):223 unmodified lines22422522622722822923023123223323439 unmodified lines27427527627727827928028115 unmodified lines297298299300301302303304305306223 unmodified linesretry_text = paraphraser.paraphrase(text, difficulty="easy")elif attempt == 1:# Second try: More aggressive paraphrasing with medical focusmedical_prompt = f"Rewrite this medical response to be more professional and accurate. Return only the rewritten response without any introduction or commentary:\n\n{text}"retry_text = paraphraser.paraphrase(text, difficulty="hard", custom_prompt=medical_prompt)else:# Third try: Direct medical content generationmedical_prompt = f"Provide a professional medical response to this question. Return only the medical response without any introduction or commentary:\n\n{text}"retry_text = paraphraser.paraphrase(text, difficulty="hard", custom_prompt=medical_prompt)if retry_text and not is_invalid_response(retry_text):39 unmodified linesreturn enhancedelse:prompt = ("Improve the medical terminology in this text while preserving all factual information. Return only the improved text with better medical terminology without any introduction or commentary:\n\n"f"{text}")enhanced = paraphraser.paraphrase(text, difficulty="hard", custom_prompt=prompt)15 unmodified lineselse:# Fallback to original implementationcontext_prompts = [f"Rewrite this medical question as if asked by a patient in an emergency room. Return only the rewritten question without any introduction or commentary:\n\n{question}",f"Rewrite this medical question as if asked by a patient in a routine checkup. Return only the rewritten question without any introduction or commentary:\n\n{question}",f"Rewrite this medical question as if asked by a patient with chronic conditions. Return only the rewritten question without any introduction or commentary:\n\n{question}",f"Rewrite this medical question as if asked by a patient's family member. Return only the rewritten question without any introduction or commentary:\n\n{question}"]for i, prompt in enumerate(context_prompts):
152 unmodified lines15315415515615715815916016116216316416516616719 unmodified lines1871881891901911921931941951961971981992002018 unmodified lines2102112122132142152162172182192202212222232245 unmodified lines2302312322332342352362372382392402412422432446 unmodified lines2512522532542552562572582592602612622632642657 unmodified lines2732742752762772782792802818 unmodified lines290291292293294295296297298299300301302303304305306307308309310311312313314315152 unmodified lines# Optimized medical paraphrasing prompts based on difficultyif difficulty == "easy":prompt = ("You are a medical professional. Rewrite the following medical text using different words while preserving all medical facts, clinical terms, and meaning. Keep the same level of detail and accuracy.\n\n"f"Original medical text: {text}\n\n""Rewritten medical text:")else: # hard difficultyprompt = ("You are a medical expert. Rewrite the following medical text using more sophisticated medical language and different sentence structures while preserving all clinical facts, medical terminology, and diagnostic information. Maintain professional medical tone.\n\n"f"Original medical text: {text}\n\n""Enhanced medical text:")# Optimize temperature and token limits based on difficulty19 unmodified lines# Optimized medical translation promptsif target_lang == "vi":prompt = ("You are a medical translator. Translate the following English medical text to Vietnamese while preserving all medical terminology, clinical facts, and professional medical language. Use appropriate Vietnamese medical terms.\n\n"f"English medical text: {text}\n\n""Vietnamese medical translation:")else:prompt = (f"You are a medical translator. Translate the following medical text to {target_lang} while preserving all medical terminology, clinical facts, and professional medical language.\n\n"f"Original medical text: {text}\n\n"f"{target_lang} medical translation:")out = self.nv.generate(prompt, temperature=0.0, max_tokens=min(800, len(text)+100))8 unmodified lines# Optimized backtranslation prompt with medical focusif via_lang == "vi":prompt = ("You are a medical translator. Translate the following Vietnamese medical text back to English while preserving all medical terminology, clinical facts, and professional medical language. Ensure the translation is medically accurate.\n\n"f"Vietnamese medical text: {mid}\n\n""English medical translation:")else:prompt = (f"You are a medical translator. Translate the following {via_lang} medical text back to English while preserving all medical terminology, clinical facts, and professional medical language.\n\n"f"{via_lang} medical text: {mid}\n\n""English medical translation:")out = self.nv.generate(prompt, temperature=0.0, max_tokens=min(900, len(text)+150))5 unmodified linesdef consistency_check(self, user: str, output: str) -> bool:"""Return True if 'output' appears supported by 'user' (context/question). Optimized medical validation."""prompt = ("You are a medical quality assurance expert. Evaluate if the medical answer is consistent with the question/context and medically accurate. Consider:\n""1. Medical accuracy and clinical appropriateness\n""2. Consistency with the question asked\n""3. Safety and professional medical standards\n""4. Completeness of the medical information\n\n""Reply with exactly 'PASS' if the answer is medically sound and consistent, otherwise 'FAIL'.\n\n"f"Question/Context: {user}\n\n"f"Medical Answer: {output}\n\n""Evaluation:")out = self.nv.generate(prompt, temperature=0.0, max_tokens=5)if not out:6 unmodified linesreturn Falseprompt = ("You are a medical accuracy validator. Evaluate if the medical answer is accurate and appropriate for the question. Consider:\n""1. Medical facts and clinical knowledge\n""2. Appropriate medical terminology\n""3. Clinical reasoning and logic\n""4. Safety considerations\n\n""Reply with exactly 'ACCURATE' if the answer is medically correct, otherwise 'INACCURATE'.\n\n"f"Medical Question: {question}\n\n"f"Medical Answer: {answer}\n\n""Medical Accuracy Assessment:")out = self.nv.generate(prompt, temperature=0.0, max_tokens=5)7 unmodified linesreturn textprompt = ("You are a medical terminology expert. Improve the medical terminology in the following text while preserving all factual information and clinical accuracy. Use more precise medical terms where appropriate.\n\n"f"Original text: {text}\n\n""Enhanced medical text:")out = self.nv.generate(prompt, temperature=0.1, max_tokens=min(800, len(text)+100))8 unmodified lines# Different clinical context promptscontext_prompts = [("Rewrite this medical question as if asked by a patient in an emergency room setting:","emergency_room"),("Rewrite this medical question as if asked by a patient during a routine checkup:","routine_checkup"),("Rewrite this medical question as if asked by a patient with chronic conditions:","chronic_care"),("Rewrite this medical question as if asked by a patient's family member:","family_inquiry")]for prompt_template, scenario_type in context_prompts:try:prompt = f"{prompt_template}\n\nOriginal question: {question}\n\nRewritten question:"scenario_question = self.paraphrase(question, difficulty="hard", custom_prompt=prompt)if scenario_question and not self._is_invalid_response(scenario_question):152 unmodified lines15315415515615715815916016116216316416519 unmodified lines1851861871881891901911921931941951961978 unmodified lines2062072082092102112122132142152162172185 unmodified lines2242252262272282292302312326 unmodified lines2392402412422432442452462477 unmodified lines2552562572582592602612628 unmodified lines271272273274275276277278279280281282283284285286287288289290291292293294295296152 unmodified lines# Optimized medical paraphrasing prompts based on difficultyif difficulty == "easy":prompt = ("Rewrite the following medical text using different words while preserving all medical facts, clinical terms, and meaning. Keep the same level of detail and accuracy. Return only the rewritten text without any introduction or commentary.\n\n"f"{text}")else: # hard difficultyprompt = ("Rewrite the following medical text using more sophisticated medical language and different sentence structures while preserving all clinical facts, medical terminology, and diagnostic information. Maintain professional medical tone. Return only the rewritten text without any introduction or commentary.\n\n"f"{text}")# Optimize temperature and token limits based on difficulty19 unmodified lines# Optimized medical translation promptsif target_lang == "vi":prompt = ("Translate the following English medical text to Vietnamese while preserving all medical terminology, clinical facts, and professional medical language. Use appropriate Vietnamese medical terms. Return only the translation without any introduction or commentary.\n\n"f"{text}")else:prompt = (f"Translate the following medical text to {target_lang} while preserving all medical terminology, clinical facts, and professional medical language. Return only the translation without any introduction or commentary.\n\n"f"{text}")out = self.nv.generate(prompt, temperature=0.0, max_tokens=min(800, len(text)+100))8 unmodified lines# Optimized backtranslation prompt with medical focusif via_lang == "vi":prompt = ("Translate the following Vietnamese medical text back to English while preserving all medical terminology, clinical facts, and professional medical language. Ensure the translation is medically accurate. Return only the translation without any introduction or commentary.\n\n"f"{mid}")else:prompt = (f"Translate the following {via_lang} medical text back to English while preserving all medical terminology, clinical facts, and professional medical language. Return only the translation without any introduction or commentary.\n\n"f"{mid}")out = self.nv.generate(prompt, temperature=0.0, max_tokens=min(900, len(text)+150))5 unmodified linesdef consistency_check(self, user: str, output: str) -> bool:"""Return True if 'output' appears supported by 'user' (context/question). Optimized medical validation."""prompt = ("Evaluate if the medical answer is consistent with the question/context and medically accurate. Consider medical accuracy, clinical appropriateness, consistency with the question, safety standards, and completeness of medical information. Reply with exactly 'PASS' if the answer is medically sound and consistent, otherwise 'FAIL'.\n\n"f"Question/Context: {user}\n\n"f"Medical Answer: {output}")out = self.nv.generate(prompt, temperature=0.0, max_tokens=5)if not out:6 unmodified linesreturn Falseprompt = ("Evaluate if the medical answer is accurate and appropriate for the question. Consider medical facts, clinical knowledge, appropriate medical terminology, clinical reasoning, logic, and safety considerations. Reply with exactly 'ACCURATE' if the answer is medically correct, otherwise 'INACCURATE'.\n\n"f"Medical Question: {question}\n\n"f"Medical Answer: {answer}")out = self.nv.generate(prompt, temperature=0.0, max_tokens=5)7 unmodified linesreturn textprompt = ("Improve the medical terminology in the following text while preserving all factual information and clinical accuracy. Use more precise medical terms where appropriate. Return only the improved text without any introduction or commentary.\n\n"f"{text}")out = self.nv.generate(prompt, temperature=0.1, max_tokens=min(800, len(text)+100))8 unmodified lines# Different clinical context promptscontext_prompts = [("Rewrite this medical question as if asked by a patient in an emergency room setting. Return only the rewritten question without any introduction or commentary:\n\n{question}","emergency_room"),("Rewrite this medical question as if asked by a patient during a routine checkup. Return only the rewritten question without any introduction or commentary:\n\n{question}","routine_checkup"),("Rewrite this medical question as if asked by a patient with chronic conditions. Return only the rewritten question without any introduction or commentary:\n\n{question}","chronic_care"),("Rewrite this medical question as if asked by a patient's family member. Return only the rewritten question without any introduction or commentary:\n\n{question}","family_inquiry")]for prompt_template, scenario_type in context_prompts:try:prompt = prompt_template.format(question=question)scenario_question = self.paraphrase(question, difficulty="hard", custom_prompt=prompt)if scenario_question and not self._is_invalid_response(scenario_question):
267 unmodified lines2682692702712722732742752762772782792802812829 unmodified lines29229329429529629729829930030130230330430530612 unmodified lines3193203213223233243253263273283293303313323332 unmodified lines3363373383393403413423433443453463473483493505 unmodified lines3563573583593603613623633643653663673683693705 unmodified lines3763773783793803813823833846 unmodified lines391392393394395396397398399400401402403404405406407408409267 unmodified lines# Medical-specific paraphrasing prompts based on difficultyif difficulty == "easy":prompt = ("You are a medical professional. Rewrite the following medical text using different words while preserving all medical facts, clinical terms, and meaning. Keep the same level of detail and accuracy.\n\n"f"Original medical text: {text}\n\n""Rewritten medical text:")else: # hard difficultyprompt = ("You are a medical expert. Rewrite the following medical text using more sophisticated medical language and different sentence structures while preserving all clinical facts, medical terminology, and diagnostic information. Maintain professional medical tone.\n\n"f"Original medical text: {text}\n\n""Enhanced medical text:")# Adjust temperature based on difficulty9 unmodified lines# Medical-specific translation promptif target_lang == "vi":prompt = ("You are a medical translator. Translate the following English medical text to Vietnamese while preserving all medical terminology, clinical facts, and professional medical language. Use appropriate Vietnamese medical terms.\n\n"f"English medical text: {text}\n\n""Vietnamese medical translation:")else:prompt = (f"You are a medical translator. Translate the following medical text to {target_lang} while preserving all medical terminology, clinical facts, and professional medical language.\n\n"f"Original medical text: {text}\n\n"f"{target_lang} medical translation:")result = self.client.generate(prompt, max_tokens=min(800, len(text)+100), temperature=0.0)12 unmodified lines# Then translate back to English with medical focusif via_lang == "vi":prompt = ("You are a medical translator. Translate the following Vietnamese medical text back to English while preserving all medical terminology, clinical facts, and professional medical language. Ensure the translation is medically accurate.\n\n"f"Vietnamese medical text: {translated}\n\n""English medical translation:")else:prompt = (f"You are a medical translator. Translate the following {via_lang} medical text back to English while preserving all medical terminology, clinical facts, and professional medical language.\n\n"f"{via_lang} medical text: {translated}\n\n""English medical translation:")result = self.client.generate(prompt, max_tokens=min(900, len(text)+150), temperature=0.0)2 unmodified linesdef consistency_check(self, user: str, output: str) -> bool:"""Check consistency using MedAlpaca with medical validation focus"""prompt = ("You are a medical quality assurance expert. Evaluate if the medical answer is consistent with the question/context and medically accurate. Consider:\n""1. Medical accuracy and clinical appropriateness\n""2. Consistency with the question asked\n""3. Safety and professional medical standards\n""4. Completeness of the medical information\n\n""Reply with exactly 'PASS' if the answer is medically sound and consistent, otherwise 'FAIL'.\n\n"f"Question/Context: {user}\n\n"f"Medical Answer: {output}\n\n""Evaluation:")result = self.client.generate(prompt, max_tokens=5, temperature=0.0)5 unmodified linesreturn Falseprompt = ("You are a medical accuracy validator. Evaluate if the medical answer is accurate and appropriate for the question. Consider:\n""1. Medical facts and clinical knowledge\n""2. Appropriate medical terminology\n""3. Clinical reasoning and logic\n""4. Safety considerations\n\n""Reply with exactly 'ACCURATE' if the answer is medically correct, otherwise 'INACCURATE'.\n\n"f"Medical Question: {question}\n\n"f"Medical Answer: {answer}\n\n""Medical Accuracy Assessment:")result = self.client.generate(prompt, max_tokens=5, temperature=0.0)5 unmodified linesreturn textprompt = ("You are a medical terminology expert. Improve the medical terminology in the following text while preserving all factual information and clinical accuracy. Use more precise medical terms where appropriate.\n\n"f"Original text: {text}\n\n""Enhanced medical text:")result = self.client.generate(prompt, max_tokens=min(800, len(text)+100), temperature=0.1)6 unmodified lines# Different clinical context promptscontext_prompts = [("You are a medical professional. Rewrite this medical question as if asked by a patient in an emergency room setting:\n\nOriginal question: {question}\n\nEmergency room question:","emergency_room"),("You are a medical professional. Rewrite this medical question as if asked by a patient during a routine checkup:\n\nOriginal question: {question}\n\nRoutine checkup question:","routine_checkup"),("You are a medical professional. Rewrite this medical question as if asked by a patient with chronic conditions:\n\nOriginal question: {question}\n\nChronic care question:","chronic_care"),("You are a medical professional. Rewrite this medical question as if asked by a patient's family member:\n\nOriginal question: {question}\n\nFamily inquiry question:","family_inquiry")]267 unmodified lines2682692702712722732742752762772782792809 unmodified lines29029129229329429529629729829930030130212 unmodified lines3153163173183193203213223233243253263272 unmodified lines3303313323333343353363373385 unmodified lines3443453463473483493503513525 unmodified lines3583593603613623633643656 unmodified lines372373374375376377378379380381382383384385386387388389390267 unmodified lines# Medical-specific paraphrasing prompts based on difficultyif difficulty == "easy":prompt = ("Rewrite the following medical text using different words while preserving all medical facts, clinical terms, and meaning. Keep the same level of detail and accuracy. Return only the rewritten text without any introduction or commentary.\n\n"f"{text}")else: # hard difficultyprompt = ("Rewrite the following medical text using more sophisticated medical language and different sentence structures while preserving all clinical facts, medical terminology, and diagnostic information. Maintain professional medical tone. Return only the rewritten text without any introduction or commentary.\n\n"f"{text}")# Adjust temperature based on difficulty9 unmodified lines# Medical-specific translation promptif target_lang == "vi":prompt = ("Translate the following English medical text to Vietnamese while preserving all medical terminology, clinical facts, and professional medical language. Use appropriate Vietnamese medical terms. Return only the translation without any introduction or commentary.\n\n"f"{text}")else:prompt = (f"Translate the following medical text to {target_lang} while preserving all medical terminology, clinical facts, and professional medical language. Return only the translation without any introduction or commentary.\n\n"f"{text}")result = self.client.generate(prompt, max_tokens=min(800, len(text)+100), temperature=0.0)12 unmodified lines# Then translate back to English with medical focusif via_lang == "vi":prompt = ("Translate the following Vietnamese medical text back to English while preserving all medical terminology, clinical facts, and professional medical language. Ensure the translation is medically accurate. Return only the translation without any introduction or commentary.\n\n"f"{translated}")else:prompt = (f"Translate the following {via_lang} medical text back to English while preserving all medical terminology, clinical facts, and professional medical language. Return only the translation without any introduction or commentary.\n\n"f"{translated}")result = self.client.generate(prompt, max_tokens=min(900, len(text)+150), temperature=0.0)2 unmodified linesdef consistency_check(self, user: str, output: str) -> bool:"""Check consistency using MedAlpaca with medical validation focus"""prompt = ("Evaluate if the medical answer is consistent with the question/context and medically accurate. Consider medical accuracy, clinical appropriateness, consistency with the question, safety standards, and completeness of medical information. Reply with exactly 'PASS' if the answer is medically sound and consistent, otherwise 'FAIL'.\n\n"f"Question/Context: {user}\n\n"f"Medical Answer: {output}")result = self.client.generate(prompt, max_tokens=5, temperature=0.0)5 unmodified linesreturn Falseprompt = ("Evaluate if the medical answer is accurate and appropriate for the question. Consider medical facts, clinical knowledge, appropriate medical terminology, clinical reasoning, logic, and safety considerations. Reply with exactly 'ACCURATE' if the answer is medically correct, otherwise 'INACCURATE'.\n\n"f"Medical Question: {question}\n\n"f"Medical Answer: {answer}")result = self.client.generate(prompt, max_tokens=5, temperature=0.0)5 unmodified linesreturn textprompt = ("Improve the medical terminology in the following text while preserving all factual information and clinical accuracy. Use more precise medical terms where appropriate. Return only the improved text without any introduction or commentary.\n\n"f"{text}")result = self.client.generate(prompt, max_tokens=min(800, len(text)+100), temperature=0.1)6 unmodified lines# Different clinical context promptscontext_prompts = [("Rewrite this medical question as if asked by a patient in an emergency room setting. Return only the rewritten question without any introduction or commentary:\n\n{question}","emergency_room"),("Rewrite this medical question as if asked by a patient during a routine checkup. Return only the rewritten question without any introduction or commentary:\n\n{question}","routine_checkup"),("Rewrite this medical question as if asked by a patient with chronic conditions. Return only the rewritten question without any introduction or commentary:\n\n{question}","chronic_care"),("Rewrite this medical question as if asked by a patient's family member. Return only the rewritten question without any introduction or commentary:\n\n{question}","family_inquiry")]
211 unmodified lines2122132142152162172182192202212222232242252262272282292302312322332342352 unmodified lines238239240241242243244245246247248249250251252253254255256257258259260261211 unmodified lines"""Generate style-specific prompts for answer enhancement with medical focus"""prompts = {"concise": ("You are a medical professional. Rewrite this medical answer to be more concise while preserving all key medical information, clinical facts, and diagnostic details:\n\n"f"Original answer: {original_answer}\n\n""Concise medical answer:"),"detailed": ("You are a medical expert. Expand this medical answer with more detailed explanations, clinical context, and additional medical information while maintaining accuracy:\n\n"f"Original answer: {original_answer}\n\n""Detailed medical answer:"),"clinical": ("You are a clinical specialist. Rewrite this answer using more formal clinical language, precise medical terminology, and professional medical communication style:\n\n"f"Original answer: {original_answer}\n\n""Clinical medical answer:"),"patient_friendly": ("You are a medical professional. Rewrite this medical answer in simpler, more patient-friendly language while keeping it medically accurate and informative:\n\n"f"Original answer: {original_answer}\n\n""Patient-friendly medical answer:")}return prompts.get(strategy, f"Paraphrase this medical answer: {original_answer}")2 unmodified lines"""Generate style-specific prompts for question enhancement with medical focus"""prompts = {"clarifying": ("You are a medical professional. Rewrite this medical question to ask for clarification or more specific medical information:\n\n"f"Original question: {original_question}\n\n""Clarifying medical question:"),"follow_up": ("You are a medical professional. Create a follow-up question that a patient might ask after this medical question, focusing on related medical concerns:\n\n"f"Original question: {original_question}\n\n""Follow-up medical question:"),"symptom_focused": ("You are a medical professional. Rewrite this question to focus more on symptoms, their characteristics, and clinical presentation:\n\n"f"Original question: {original_question}\n\n""Symptom-focused medical question:"),"treatment_focused": ("You are a medical professional. Rewrite this question to focus more on treatment options, management strategies, and therapeutic approaches:\n\n"f"Original question: {original_question}\n\n""Treatment-focused medical question:")}return prompts.get(strategy, f"Paraphrase this medical question: {original_question}")211 unmodified lines2122132142152162172182192202212222232242252262272282292302312 unmodified lines234235236237238239240241242243244245246247248249250251252253211 unmodified lines"""Generate style-specific prompts for answer enhancement with medical focus"""prompts = {"concise": ("Rewrite this medical answer to be more concise while preserving all key medical information, clinical facts, and diagnostic details. Return only the rewritten answer without any introduction or commentary:\n\n"f"{original_answer}"),"detailed": ("Expand this medical answer with more detailed explanations, clinical context, and additional medical information while maintaining accuracy. Return only the expanded answer without any introduction or commentary:\n\n"f"{original_answer}"),"clinical": ("Rewrite this answer using more formal clinical language, precise medical terminology, and professional medical communication style. Return only the rewritten answer without any introduction or commentary:\n\n"f"{original_answer}"),"patient_friendly": ("Rewrite this medical answer in simpler, more patient-friendly language while keeping it medically accurate and informative. Return only the rewritten answer without any introduction or commentary:\n\n"f"{original_answer}")}return prompts.get(strategy, f"Paraphrase this medical answer: {original_answer}")2 unmodified lines"""Generate style-specific prompts for question enhancement with medical focus"""prompts = {"clarifying": ("Rewrite this medical question to ask for clarification or more specific medical information. Return only the rewritten question without any introduction or commentary:\n\n"f"{original_question}"),"follow_up": ("Create a follow-up question that a patient might ask after this medical question, focusing on related medical concerns. Return only the follow-up question without any introduction or commentary:\n\n"f"{original_question}"),"symptom_focused": ("Rewrite this question to focus more on symptoms, their characteristics, and clinical presentation. Return only the rewritten question without any introduction or commentary:\n\n"f"{original_question}"),"treatment_focused": ("Rewrite this question to focus more on treatment options, management strategies, and therapeutic approaches. Return only the rewritten question without any introduction or commentary:\n\n"f"{original_question}")}return prompts.get(strategy, f"Paraphrase this medical question: {original_question}")
55 unmodified lines5657585960616263646566676869707172737418 unmodified lines9394959697989910010110210310410555 unmodified linesif not text or len(text.strip()) < 10:return textprompt = f"""You are a medical data cleaning expert. Clean the following text by:1. Remove conversational elements (greetings, pleasantries)2. Remove non-medical small talk and social interactions3. Keep only medically relevant information4. Preserve clinical facts, symptoms, diagnoses, treatments, and medical advice5. Maintain professional medical language6. Return only cleaned medical content in 1-2 concise sentences suitable for dense retrieval embeddings. No lists, no headers.Text to clean:{text}Cleaned medical content:"""try:if self.is_local and self.medalpaca_client:18 unmodified linesif not question or not answer:return ""prompt = f"""You are a medical knowledge expert. Given a medical question and its answer, generate a brief relevant medical context that helps retrieval. Limit to 1–2 sentences, concise, avoid boilerplate, no enumerations.Question: {question}Answer: {answer}Generate a concise medical context:"""try:if self.is_local and self.medalpaca_client:55 unmodified lines56575859606162636418 unmodified lines838485868788899091929355 unmodified linesif not text or len(text.strip()) < 10:return textprompt = f"""Clean the following text by removing conversational elements (greetings, pleasantries), non-medical small talk, and social interactions. Keep only medically relevant information while preserving clinical facts, symptoms, diagnoses, treatments, and medical advice. Maintain professional medical language. Return only cleaned medical content in 1-2 concise sentences suitable for dense retrieval embeddings. No lists, no headers, no introduction or commentary:{text}"""try:if self.is_local and self.medalpaca_client:18 unmodified linesif not question or not answer:return ""prompt = f"""Given a medical question and its answer, generate a brief relevant medical context that helps retrieval. Limit to 1–2 sentences, concise, avoid boilerplate, no enumerations. Return only the medical context without any introduction or commentary:Question: {question}Answer: {answer}"""try:if self.is_local and self.medalpaca_client:
utils/augment.py+8-9
utils/cloud_llm.py+23-42
utils/local_llm.py+22-41
utils/processor.py+16-24
utils/rag.py+4-16