Ë
    ™hÚ  ã                   ó˜   — d dl 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 d dlZ G d„ de«      Z G d„ d	e«      Z G d
„ d«      Zy)é    )ÚListÚDict)ÚField)ÚAtomicAgentÚAgentConfigÚBaseIOSchemaÚBaseToolÚBaseToolConfig)ÚChatHistoryÚSystemPromptGeneratorÚBaseDynamicContextProviderNc                   ó6   — e Zd ZU dZ edd¬«      Zee   ed<   y)ÚReviewSentimentInputSchemazJ
    Schema for a batch of user reviews to be analyzed for sentiment.
    .z List of user reviews to analyze.©ÚdescriptionÚreviewsN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   ÚstrÚ__annotations__© ó    ú:/var/www/html/hubwallet-dev/src/core/sentiment_analyzer.pyr   r      s   … ññ ˜sÐ0RÔS€GˆT#‰YÔSr   r   c                   óÂ   — e Zd ZU dZ edd¬«      Zeed<    edd¬«      Ze	e   ed<    edd¬«      Z
eed	<    edd
¬«      Zeeef   ed<    edd¬«      Zeeef   ed<   y)ÚReviewSentimentOutputSchemaz=
    Schema for analyzed sentiment data from the review.
    .z Overall sentiment of the review.r   Úoverall_sentimentzList of relevant emotions.Úrelevant_emotionsz)Overall arousal level: active or passive.Úarousalz"Sentiment for each relevant topic.Úrelevant_topics_sentimentz8Sentiment for important words extracted from the review.Úimportant_words_sentimentN)r   r   r   r   r   r   r   r   r   r   r    r!   r   r"   r   r   r   r   r      s‡   … ññ # 3Ð4VÔWÐsÓWÙ#(¨Ð:VÔ#WÐt˜C‘yÓWÙ˜Ð*UÔV€GˆSÓVÙ05ØÐ=ô1Ð˜t C¨ H™~ó ñ 16ØÐSô1Ð˜t C¨ H™~ô r   r   c                   óJ   — e Zd Zd
dedefd„Zdee   dee   fd„Zdedefd„Z	y	)ÚReviewSentimentAnalyzerÚmodelÚtemperaturec                 ó‚   — t        dgg d¢dg¬«      }t        ||||¬«      }t        t        t        f   |¬«      | _        y)a  
        Initialize the ReviewSentimentAnalyzer for batch processing.

        Args:
            client: The LLM client (e.g., from instructor.from_openai)
            model: The model identifier to use
            temperature: Sampling temperature for the LLM
        zTYou are an expert sentiment analysis system that processes multiple reviews at once.)z7Analyze each review in the provided list independently.zFor each review, determine:z91. Overall sentiment (positive, negative, mixed, neutral)zG2. Relevant emotions with arousal levels (e.g., [{'anger': 'passive'}])z>3. Sentiment for relevant topics (Service, Food Quality, etc.)z5Evaluate sentiment for each of the following topics: zSService Experience, Cleanliness & Hygiene, Ambiance & Atmosphere, Pricing & Value, zdOnline Ordering & Delivery, Complaint Resolution, Customer Loyalty, Menu Preferences, Waiting Time, ziPortion Size, Staff Friendliness, Payment Experience, Special Requests Handling, Reservation Experience, z^Parking & Accessibility, Food Presentation, Seasonal Trends, Offer & Promotions, Food Quality.z.4. Sentiment for important words in the reviewzMMaintain the exact same order of reviews in your output as received in input.z3Return all results in a single structured response.a>  Return a JSON object with a single key 'results' that contains a list of dicts.
                Each dict includes:
                - overall_sentiment
                - relevant_emotions
                - arousal
                - relevant_topics_sentiment
                - important_words_sentiment
                )Ú
backgroundÚstepsÚoutput_instructions)Úclientr%   r&   Úsystem_prompt_generator)ÚconfigN)r   r   r   r   r   Úagent)Úselfr+   r%   r&   r,   r-   s         r   Ú__init__z ReviewSentimentAnalyzer.__init__"   sW   € ô #8ØnÐoòð ð	!ô##
Ðô: ØØØ#Ø$;ô	
ˆô !Ô!;Ô<WÐ!XÑYÐagÔhˆ
r   r   Úreturnc                 óh   — t        |¬«      }| j                  j                  |«      }|j                  S )zã
        Analyze multiple reviews in a single batch request.

        Args:
            reviews: List of review texts to analyze

        Returns:
            List of analysis results in the same order as input reviews
        )r   )r   r.   ÚrunÚresults)r/   r   Ú
input_dataÚresults       r   Úanalyze_reviewsz'ReviewSentimentAnalyzer.analyze_reviewsS   s*   € ô 0¸Ô@ˆ
Ø—‘—‘ 
Ó+ˆØ~‰~Ðr   Úreviewc                 ó8   — | j                  |g«      }|r|d   S i S )zd
        Analyzes a single review by wrapping it in a list and extracting the first result.
        r   )r7   )r/   r8   r4   s      r   Úanalyze_reviewz&ReviewSentimentAnalyzer.analyze_reviewb   s'   € ð ×&Ñ&¨ xÓ0ˆÙ$ˆwq‰zÐ,¨"Ð,r   N)zgpt-4gš™™™™™É?)
r   r   r   r   Úfloatr0   r   r   r7   r:   r   r   r   r$   r$   !   sG   „ ñ/i cð /iÀ%ó /iðb t¨C¡yð °T¸$±Zó ð- Sð -¨Tô -r   r$   )Útypingr   r   Úpydanticr   Úatomic_agentsr   r   r   r	   r
   Úatomic_agents.contextr   r   r   Útimer   r   r$   r   r   r   ú<module>rA      sC   ðß Ý ÷ [Õ Zß `Ñ `ã ôT ô Tô ,ô ÷F-ò F-r   