def run_from_config(config_path: str | Path) -> ConfigLoader:
"""Execute a task based on a configuration file."""
try:
config: ConfigLoader = load_config(str(config_path))
print(f"✓ Konfiguration geladen: {config}")
except (FileNotFoundError, ValueError, Exception) as e:
print(f"❌ Fehler beim Laden der Konfiguration: {e}")
sys.exit(1)
# Create LLM client
llm_config = config.get_llm_config()
try:
llm_client = LLMClient(api_choice=llm_config.get("api_choice"), llm=llm_config.get("model"))
print(f"✓ LLM: {llm_client.api_choice} / {llm_client.llm}")
except Exception as e:
print(f"❌ Fehler beim Initialisieren des LLM-Clients: {e}")
sys.exit(1)
# Execute task based on configuration
task = config.get_task()
output_config = config.get_output_config()
# Validate PDF path
try:
pdf_filename = config.config["pdf"]["filename"]
pdf_path = validate_pdf_path(str(config.folder_path), pdf_filename)
except (KeyError, ValueError, FileNotFoundError) as e:
print(f"❌ Fehler beim Validieren des PDF-Pfads: {e}")
sys.exit(1)
if task == "colloquium":
coll_config = config.get_colloquium_config()
gemini_config = config.get_gemini_emark_config()
if coll_config is None:
print("❌ Fehler: Kolloquium-Konfiguration fehlt")
sys.exit(1)
coll_workflow_config = ColloquiumWorkflowConfig(
pdf_path=pdf_path,
date=coll_config["date"],
time=coll_config["time"],
llm_client=llm_client,
groq_free=llm_config.get("groq_free", False),
output_folder=(Path(output_config["folder"]) if output_config.get("folder") else None),
compile_pdf=output_config.get("compile_pdf", True),
fill_form_only=output_config.get("fill_form_only", False),
location_type=coll_config["location_type"], # type: ignore
room=coll_config.get("room"),
company_name=coll_config.get("company_name"),
company_address=coll_config.get("company_address"),
zoom_link=coll_config.get("zoom_link"),
zcode=coll_config.get("zcode"),
gemini_emark_enabled=gemini_config.get("enabled", False),
gemini_model=gemini_config.get("model"),
gemini_use_text_extraction=gemini_config.get("use_text_extraction", True),
)
coll_result = run_pipeline(coll_workflow_config)
print("\n✓ Kolloquium-Pipeline abgeschlossen:")
if coll_result.tex_path:
print(f" • LaTeX: {coll_result.tex_path}")
if coll_result.pdf_path:
print(f" • PDF: {coll_result.pdf_path}")
if coll_result.email_path:
print(f" • E-Mail: {coll_result.email_path}")
if coll_result.metadata_path:
print(f" • Web-Metadaten: {coll_result.metadata_path}")
elif task == "project":
proj_config = config.get_project_config() or {}
mark = proj_config.get("mark")
work_type = proj_config.get("work_type")
proj_workflow_config = ProjectWorkflowConfig(
pdf_path=pdf_path,
llm_client=llm_client,
output_folder=(Path(output_config["folder"]) if output_config.get("folder") else None),
compile_pdf=output_config.get("compile_pdf", True),
signature_file=output_config.get("signature_file", "signature.png"),
mark=mark,
create_feedback_mail=output_config.get("create_feedback_mail", True),
work_type=work_type,
)
proj_result = run_project_pipeline(proj_workflow_config)
print("\n✓ Projektarbeits-Pipeline abgeschlossen:")
print(f" • LaTeX: {proj_result.tex_path}")
if proj_result.pdf_path:
print(f" • PDF: {proj_result.pdf_path}")
if proj_result.service_email_path:
print(f" • E-Mail (Prüfungsservice): {proj_result.service_email_path}")
if proj_result.student_email_path:
print(f" • E-Mail (Student): {proj_result.student_email_path}")
if proj_result.metadata_path:
print(f" • Web-Metadaten: {proj_result.metadata_path}")
elif task == "review":
md_path = run_review_pipeline(
pdf_path=pdf_path,
llm_client=llm_client,
groq_free=llm_config.get("groq_free", False),
output_folder=output_config.get("folder"),
)
print("\n✓ Review-Pipeline abgeschlossen:")
print(f" • Markdown: {md_path}")
return config