
    h                         d dl mZmZmZ d dlmZ d dlmZmZm	Z	m
Z
mZ d dlmZmZmZ  G d de	      Z G d de	      Z G d	 d
e	      Z G d d      Zy)    )DictListUnion)Field)AtomicAgentAgentConfigBaseIOSchemaBaseToolBaseToolConfig)ChatHistorySystemPromptGeneratorBaseDynamicContextProviderc                       e Zd ZU dZeed<   eeeeef   f   ed<   eeef   ed<   eeeeef   f   ed<   eeef   ed<   eed<   y)	RecommendationInputSchemaax  
    Schema for aggregated customer feedback for recommendations.
   
    Attributes:
      overall_sentiment_score: An integer score representing the overall sentiment.
      topic_sentiment: A dictionary mapping business topics to sentiment (e.g., {"Waiting Time": "negative"}).
      emotion_count: A dictionary counting emotions (e.g., {"joy": 2, "anger": 12}).
      words_sentiment: A dictionary mapping key words to sentiment (e.g., {"delicious": "positive"}).
      sentiment_breakdown: A dictionary representing the percentage breakdown of sentiments (e.g., {"positive": 70, "negative": 20, "mixed": 2, "neutral": 8}).
    overall_sentiment_scoretopic_sentimentemotion_countwords_sentimentsentiment_breakdowntotal_reviewsN)__name__
__module____qualname____doc__int__annotations__r   str     </var/www/html/hubwallet-dev/src/core/recommendation_agent.pyr   r      sa    	 ! #tCH~-..S>!#tCH~-..c3h'r   r   c                       e Zd ZU dZ edd      Zeed<    edd      Zeed<    edd      Z	eed	<    edd
      Z
eed<   y)RecommendationRowScemazt_summary_
 
    Args:
        BaseIOSchema (_type_): _description_
 
    Returns:
        _type_: _description_
    .z$Recommendation for a specific topic.descriptionrecommendationz+Topic for which the recommendation is made.topiczSeverity of the recommendation.severityzRank of the recommendation.rankN)r   r   r   r   r   r%   r   r   r&   r'   r(   r   r   r   r    r"   r"      sQ      1WXNCXs(UVE3V#+LMHcMc'DED#Er   r"   c                   6    e Zd ZU dZ edd      Zee   ed<   y)RecommendationOutputSchemaz
    Schema for business recommendations based on feedback.
   
    Attributes:
      recommendations: A dictionary mapping business topics to recommended actions.
    .zADictionary mapping business topics to actionable recommendations.r#   recommendationsN)	r   r   r   r   r   r+   r   r"   r   r   r   r    r*   r*   .   s&     5:\5OT01 r   r*   c                   .    e Zd ZddedefdZdedefdZy)	RecommendationAgentmodeltemperaturec                     t        dgg dg d      }t        ||||      }t        t        t        f   |      | _        y)a   
        Initialize the RecommendationAgent.
 
        Args:
            client: The LLM client (e.g., from instructor.from_openai).
            model: The identifier for the model to use.
            temperature: Sampling temperature for the LLM.
        zQYou are an expert business consultant specializing in customer feedback analysis.)z>Review the aggregated customer feedback provided in the input.ztConsider the overall sentiment score, topic sentiment, emotion counts, words sentiment, and the sentiment breakdown.zvIdentify the areas needing improvement (e.g., if 'Waiting Time' is negative or if emotion counts indicate high anger).zlGenerate clear and actionable recommendations for each relevant topic or words to help the business improve.)zqReturn the output as a JSON object with a single key 'recommendations' which is a list of recommendation entries.zlEach entry in the list should be a dictionary containing: 'recommendation', 'topic', 'severity', and 'rank'.zInclude recommendations for each topic or word that shows significant negative or mixed sentiment, or important business opportunity.zKRank recommendations based on urgency and severity, where 1 is most urgent.uQ   Do not group multiple topics into one recommendation — each should be separate.)
backgroundstepsoutput_instructions)clientr.   r/   system_prompt_generator)configN)r   r   r   r   r*   agent)selfr4   r.   r/   r5   r6   s         r    __init__zRecommendationAgent.__init__;   sR     #8kl!
#
& #$;	
 !!:;U!UV^de
r   aggregated_feedbackreturnc                 R    t        di |}| j                  j                  |      }|S )a`  
        Generate business recommendations based on aggregated feedback.
 
        Args:
            aggregated_feedback: A dictionary containing overall_sentiment_score, topic_sentiment, emotion_count, words_sentiment, and sentiment_breakdown.
 
        Returns:
            An instance of RecommendationOutputSchema with the recommendations.
        r   )r   r7   run)r8   r:   
input_dataresults       r    generate_recommendationsz,RecommendationAgent.generate_recommendationsb   s)     /E1DE

+r   N)zgpt-4o-minig?)	r   r   r   r   floatr9   dictr*   r@   r   r   r    r-   r-   :   s-    %fc %f %fND E_ r   r-   N)typingr   r   r   pydanticr   atomic_agentsr   r   r	   r
   r   atomic_agents.contextr   r   r   r   r"   r*   r-   r   r   r    <module>rG      sM    $ $  [ Z ` `
 &F\ F 	 	4 4r   