From 49e79e0fdd5a7471330a20cef2c475243b333449 Mon Sep 17 00:00:00 2001 From: OwusuBlessing Date: Wed, 9 Apr 2025 01:16:22 +0100 Subject: [PATCH] fix mixup --- config.py | 5 ++++- utils/utils.py | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/config.py b/config.py index 82c8a78..3825883 100644 --- a/config.py +++ b/config.py @@ -17,4 +17,7 @@ QUIZ_TYPES = { {"question": "Your question here", "options": ["True", "False"], "correct_answer": "True or False"} """ } -} \ No newline at end of file +} + +MODEL = "gpt-4o-mini" +TEMPERATURE = 0.7 \ No newline at end of file diff --git a/utils/utils.py b/utils/utils.py index 467db7b..b1d81ab 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -6,9 +6,10 @@ from PyPDF2 import PdfReader base_path = os.path.join("data", "config_files") THEME_CONTEXT_PATH = os.path.join(base_path, "theme_context.json") -with open(THEME_CONTEXT_PATH, "r") as f: +with open(THEME_CONTEXT_PATH, "r", encoding="utf-8") as f: themes = json.load(f) + def delete_file(file_path): try: os.remove(file_path) @@ -70,4 +71,32 @@ def download_pdf_and_extract_text(url: str) -> str: # Delete the temporary file os.remove(temp_file_path) - return combined_text \ No newline at end of file + return combined_text + + +def format_qna_json_text(json_data): + """ + Format a list of Q&A JSON data into a text string with dashes. + + Parameters: + - json_data (list): A list of Q&A dictionaries with 'question' and 'answer' keys. + + Returns: + - str: A formatted text string. + """ + formatted_text = "" + + # Check if input is a list of Q&A dictionaries + if isinstance(json_data, list): + for item in json_data: + if 'question' in item and 'answer' in item: + formatted_text += f"- Question: {item['question']}\n" + formatted_text += f" Answer: {item['answer']}\n" + else: + formatted_text += "- Incomplete Q&A entry\n" + + return formatted_text.strip() + +# Example usage: + +