from crewai import LLM
from user_journey_service.core.config import settings
import yaml
from pathlib import Path

prompts_path = 'user_journey_service/config/prompts.yaml'

class Synthesizer:
    def __init__(self):
        self.llm = LLM(
          model=f"{settings.PROVIDER}/{settings.LLM_FOR_REVIEW}",
          temperature=settings.TEMPERATURE,
          api_key=settings.OPENAI_KEY2,
          api_base=settings.ENDPOINT2,
          api_version=settings.API_VERSION2,
          seed=settings.SEED,                # For reproducible results
          timeout=settings.TIMEOUT
	    )
        self.prompts = self.load_prompts()

    def load_prompts(self):
        with open(Path(prompts_path), "r") as f:
            return yaml.safe_load(f)

    def review_and_combine(self,designation,skills,experience,content1,content2):
        print("Inside synthesizer function....")
        prompt_template = self.prompts["user_journey_synthesizer"]
        prompt = prompt_template.format(
            designation=designation,
            experience=experience,
            skills=skills,
            content1=content1,
            content2=content2
        )
        # prompt = f"""

        # You are an expert product strategist and instructional designer.
        # Below are two user journeys generated for a user with the following profile:

        # Designation: {designation}
        # Skills: {skills}
        # Experience: {experience}

        # User Journey 1 :
        # {content1}
        # User Journey 2:
        # {content2}
        # Task:

        # Carefully compare both user journeys.

        # Identify overlaps, differences, strengths, and any missing elements based on the user's profile.

        # Combine them to create a single, refined, logically ordered, and practical combined user journey that is aligned to the given user profile.

        # Ensure the combined journey avoids redundancy, resolves conflicts, and integrates complementary steps effectively.

        # Output format:
        # Same as the already given  user  journey in markdown with stages
        # """

        # LLM message format for CrewAI
        messages = [{'role': 'user', 'content': prompt}]

        # Call the LLM
        response = self.llm.call(messages)

        return response