user-defined topic propagated to prompt
Browse files- src/generator.py +8 -3
- src/services/prompt.py +5 -4
src/generator.py
CHANGED
|
@@ -5,8 +5,13 @@ from typing import Optional
|
|
| 5 |
|
| 6 |
from langfuse.decorators import langfuse_context, observe
|
| 7 |
|
| 8 |
-
from src.compilation import (
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# from datetime import datetime
|
| 11 |
from src.database import retrive_files_from_db
|
| 12 |
from src.processing import create_output_folder, find_used_gfx
|
|
@@ -64,7 +69,7 @@ def generate_presentation(
|
|
| 64 |
LOGGER.error("❌ No documents found for the topic: %s", config.topic)
|
| 65 |
return "❌ No documents found for the given topic.", trace_id, None
|
| 66 |
|
| 67 |
-
prompt = build_prompt(documents, metadatas, config.aspect_ratio)
|
| 68 |
|
| 69 |
# Generate the presentation code
|
| 70 |
model_name = config.model_name
|
|
|
|
| 5 |
|
| 6 |
from langfuse.decorators import langfuse_context, observe
|
| 7 |
|
| 8 |
+
from src.compilation import (
|
| 9 |
+
compile_presentation,
|
| 10 |
+
escape_latex_special_chars,
|
| 11 |
+
json_to_tex,
|
| 12 |
+
replace_unicode_greek,
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
# from datetime import datetime
|
| 16 |
from src.database import retrive_files_from_db
|
| 17 |
from src.processing import create_output_folder, find_used_gfx
|
|
|
|
| 69 |
LOGGER.error("❌ No documents found for the topic: %s", config.topic)
|
| 70 |
return "❌ No documents found for the given topic.", trace_id, None
|
| 71 |
|
| 72 |
+
prompt = build_prompt(documents, metadatas, config.aspect_ratio, config.topic)
|
| 73 |
|
| 74 |
# Generate the presentation code
|
| 75 |
model_name = config.model_name
|
src/services/prompt.py
CHANGED
|
@@ -127,11 +127,12 @@ def get_prompt(
|
|
| 127 |
return prompt
|
| 128 |
|
| 129 |
|
| 130 |
-
def get_prompt_json(aspect_ratio: str = "16:9") -> str:
|
| 131 |
"""
|
| 132 |
JSON-based prompt for structured LLM output.
|
| 133 |
Args:
|
| 134 |
aspect_ratio (str): The desired aspect ratio for the presentation, e.g., "16:9".
|
|
|
|
| 135 |
Returns:
|
| 136 |
str: The JSON prompt string for generating a structured presentation.
|
| 137 |
"""
|
|
@@ -182,11 +183,11 @@ You must output only a **valid JSON object** with the following fields:
|
|
| 182 |
- Do not invent or modify the image paths.
|
| 183 |
- Desired aspect ratio of the presentation is {aspect_ratio}. Your content must be suitable for this aspect ratio.
|
| 184 |
|
| 185 |
-
Return only the JSON object. Do not include any explanations, LaTeX, or Markdown.
|
| 186 |
"""
|
| 187 |
|
| 188 |
|
| 189 |
-
def build_prompt(documents, metadatas, aspect_ratio) -> str:
|
| 190 |
"""
|
| 191 |
Build the prompt for the LLM based on the provided documents and metadata.
|
| 192 |
Args:
|
|
@@ -196,7 +197,7 @@ def build_prompt(documents, metadatas, aspect_ratio) -> str:
|
|
| 196 |
Returns:
|
| 197 |
str: The complete prompt string ready for LLM input.
|
| 198 |
"""
|
| 199 |
-
prompt = get_prompt_json(aspect_ratio)
|
| 200 |
for passage, metas in zip(documents, metadatas):
|
| 201 |
passage_oneline = passage.replace("\n", " ")
|
| 202 |
prompt += f"PASSAGE: {passage_oneline}\n"
|
|
|
|
| 127 |
return prompt
|
| 128 |
|
| 129 |
|
| 130 |
+
def get_prompt_json(aspect_ratio: str = "16:9", topic: str = "") -> str:
|
| 131 |
"""
|
| 132 |
JSON-based prompt for structured LLM output.
|
| 133 |
Args:
|
| 134 |
aspect_ratio (str): The desired aspect ratio for the presentation, e.g., "16:9".
|
| 135 |
+
topic (str): User-defined topic of the presentation, used for context.
|
| 136 |
Returns:
|
| 137 |
str: The JSON prompt string for generating a structured presentation.
|
| 138 |
"""
|
|
|
|
| 183 |
- Do not invent or modify the image paths.
|
| 184 |
- Desired aspect ratio of the presentation is {aspect_ratio}. Your content must be suitable for this aspect ratio.
|
| 185 |
|
| 186 |
+
Return only the JSON object. Do not include any explanations, LaTeX, or Markdown. The user-desired topic is "{topic}".
|
| 187 |
"""
|
| 188 |
|
| 189 |
|
| 190 |
+
def build_prompt(documents, metadatas, aspect_ratio, topic) -> str:
|
| 191 |
"""
|
| 192 |
Build the prompt for the LLM based on the provided documents and metadata.
|
| 193 |
Args:
|
|
|
|
| 197 |
Returns:
|
| 198 |
str: The complete prompt string ready for LLM input.
|
| 199 |
"""
|
| 200 |
+
prompt = get_prompt_json(aspect_ratio, topic)
|
| 201 |
for passage, metas in zip(documents, metadatas):
|
| 202 |
passage_oneline = passage.replace("\n", " ")
|
| 203 |
prompt += f"PASSAGE: {passage_oneline}\n"
|