
    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  G d de      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BaseDynamicContextProviderc                   6    e Zd ZU dZ edd      Zee   ed<   y)BatchReviewSentimentInputSchemaz)Schema for multiple user review contents..z&List of text contents of user reviews.descriptionreviewsN)	__name__
__module____qualname____doc__r   r   r   str__annotations__     @/var/www/html/hubwallet-dev/src/core/batch_sentiment_analyzer.pyr   r      s     3<GT#Y r   r   c                       e Zd ZU dZ edd      Zeed<    edd      Ze	e
eef      ed<    edd      Ze
eef   ed	<    edd
      Ze
eef   ed<   y)ReviewSentimentOutputSchemaa  
    Schema for analyzed sentiment data from the review.

    overall_sentiment: One of (positive, negative, mixed, neutral)
    relevant_emotions_with_arousal: List of dict mapping emotion to arousal (e.g. [{"anger": "passive"}])
    relevant_topics_sentiment: Dict mapping topics (e.g. Food Quality) to sentiment (e.g. "Positive")
    important_words_sentiment: Dict mapping important words to sentiment (e.g. {"delicious": "Positive"})
    .z Overall sentiment of the review.r   overall_sentimentz4List of relevant emotions with their arousal levels.relevant_emotions_with_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      s     #34VWsW;@O<"Dc3h$8  16=1tCH~  16S1tCH~ r   r   c                   6    e Zd ZU dZ edd      Zee   ed<   y) BatchReviewSentimentOutputSchemaz9Schema for analyzed sentiment data from multiple reviews..zList of analysis results for each review containing: overall_sentiment, relevant_emotions_with_arousal, relevant_topics_sentiment, and important_words_sentimentr   
sentimentsN)	r   r   r   r   r   r$   r   r   r   r   r   r   r#   r#   '   s%    C49G5J01 r   r#   c                   :    e Zd ZddedefdZdee   dee   fdZy)	BatchReviewSentimentAnalyzermodeltemperaturec                     t        dgg dddg      }t        ||||      }t        t        t        f   |      | _        y)	a  
        Initialize the BatchReviewSentimentAnalyzer 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.)z*   Evaluate each of the following topics: zBService Experience, Cleanliness & Hygiene, Ambiance & Atmosphere, zCPricing & Value, Online Ordering & Delivery, Complaint Resolution, z@Customer Loyalty, Menu Preferences, Waiting Time, Portion Size, zCStaff Friendliness, Payment Experience, Special Requests Handling, zDReservation Experience, Parking & Accessibility, Food Presentation, z2Seasonal 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.zReturn a JSON object whose value is an array of JSON objects. Each object must have the keys: overall_sentiment (str), relevant_emotions_with_arousal (list of dict), relevant_topics_sentiment (dict), and important_words_sentiment (dict).uP   Do not wrap the JSON in markdown or add any extra text—only emit the raw JSON.)
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%BatchReviewSentimentAnalyzer.__init__3   s`     #8f$Z c!+#
< #$;	
 !!@Bb!bckqr
r   r   returnc                 T    t        |      }| 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   r0   run)r1   r   
input_dataresults       r   analyze_reviewsz,BatchReviewSentimentAnalyzer.analyze_reviewsb   s'     5WE

+ r   N)zgpt-4g?)	r   r   r   r   floatr2   r   r   r8   r   r   r   r&   r&   2   s6    -sc -s% -s^tCy T:U5V r   r&   N)typingr   r   pydanticr   atomic_agentsr   r   r   r	   r
   atomic_agents.contextr   r   r   r   r   r#   r&   r   r   r   <module>r>      sH     
 [ Z ` `l , (	| 	> >r   