
    7g#                     R    S SK Jr  S SKJr  S SKJr  \" 5         S SKr " S S5      rg)    )ChatPromptTemplate)
ChatOpenAI)load_dotenvNc                   F    \ rS rSr\R
                  " S5      4S jrS rSrg)EmotionClass   
BASE_MODELc                 <    S U l         S U l        [        US9U l        g )N)model)chatEmotionr   	chatmodel)selfr   s     C   /Users/zhangyaohui/Desktop/AI课程/xiaolang/backend/src/Emotion.py__init__EmotionClass.__init__   s    	#%0    c                 2   Un[        U5      S:  a  US S n[        S[        U5       35        [        SU 35        SSSSS/ S	QS
.SS/ SQS
.S.SS/S.nU R                  R                  U5      nSn[        R
                  " SU4SU4/5      U-  n UR                  5       (       d  [        S5        g Ub"  UR                  SU05      n[        SU 35        O[        S5      eXpl	        U$ ! [         a!  n[        S[        U5       35         S nAg S nAff = f)Nd   zPInput is too long, only the first 100 characters will be used. Original length: zProcessing input: emotionsz7emotion analysis with feeling type and negativity scoreobjectstringz)the emotional state detected in the input)defaultupbeatangrycheerful	depressedfriendly)typedescriptionenumzNnegativity score from 1 to 10, where 10 represents extremely negative emotions)
12345678910)feelingscorer,   r-   )titler    r   
propertiesrequiredu@  
        分析用户输入的文本情绪，返回情绪类型和负面程度评分。

        评分规则：
        - 分数范围为1-10
        - 分数越高表示情绪越负面
        - 1-3分：积极正面的情绪
        - 4-5分：中性或轻微情绪波动
        - 6-8分：明显的负面情绪
        - 9-10分：强烈的负面情绪

        情绪类型对照：
        - default: 中性、平静的情绪状态
        - upbeat: 积极向上、充满活力的情绪
        - angry: 愤怒、生气的情绪
        - cheerful: 开心愉快、充满欢乐的情绪
        - depressed: 沮丧、压抑的情绪
        - friendly: 友好、亲切的情绪

        情绪分类指南：
        1. default: 用于表达中性或普通的情绪状态
        2. upbeat: 用于表达积极向上、充满干劲的状态
        3. angry: 用于表达愤怒、不满、生气的情绪
        4. cheerful: 用于表达欢快、喜悦的情绪
        5. depressed: 用于表达消极、低落、压抑的情绪
        6. friendly: 用于表达友善、亲切的情绪

        示例：
        - "我特别生气！" -> {{"feeling": "angry", "score": "8"}}
        - "今天天气真好" -> {{"feeling": "cheerful", "score": "2"}}
        - "随便吧，都可以" -> {{"feeling": "default", "score": "5"}}
        - "我很难过" -> {{"feeling": "depressed", "score": "9"}}
        - "谢谢你的帮助" -> {{"feeling": "friendly", "score": "1"}}

        用户输入内容: {input}
        请根据以上规则分析情绪并返回相应的feeling和score。
        systemuserzEmpty input receivedinputzAPI response: z*EmotionChain is not properly instantiated.zError in Emotion_Sensing: )lenprintr   with_structured_outputr   from_messagesstripinvoke
ValueErrorr   	Exceptionstr)	r   r3   original_inputjson_schemallmprompt_emotionEmotionChainresultes	            r   Emotion_SensingEmotionClass.Emotion_Sensing   sS   u:$3KEdehiwexdyz{"5'*+  T %#N %#sO #G,'
, nn33K@$N *77(N9SV\^cUd8efill	;;==,-'%,,gu-=>vh/0 !MNN!LM 	.s1vh78	s    C+ 37C+ +
D5DD)r   r   r   N)	__name__
__module____qualname____firstlineno__osgetenvr   rD   __static_attributes__ r   r   r   r      s    IIl3 1
Zr   r   )langchain_core.promptsr   langchain_openair   dotenvr   rJ   r   rM   r   r   <module>rQ      s"    5 '   	` `r   