o
    h^2                     @   s   d dl mZ d dlmZ d dlmZmZ d dlZd dlZd dl	m
Z
 e
dd edZed	Zed
ZedZejdeeeddZejed G dd dejZG dd dejZG dd deZG dd deZdS )    )Type)BaseTool)	BaseModelFieldN)load_dotenvz7/home/azureuser/microlearn/backend/prompt_opt_dspy/.env)dotenv_pathAZURE_API_KEYAZURE_API_HOSTAZURE_DEPLOYMENT_IDAZURE_API_VERSIONzazure/Csqr-gpt-4o-minig        )api_keyapi_baseapi_versiontemperature)lmc                   @   sV   e Zd ZU dZe Zeed< e Z	eed< e Z
eed< ejddZeed< dS )	AnswerEvaluationSignaturea  
    You are a Response Evaluator.
    Assess user understanding of a question based on their answer.

    The user's company context is:
      Company Name : {Company_Name}
      Industry : {Industry}
      Company Size : {Company_Size}
      Business Model : {Business_Model}
      Top Use Cases : {Top_Use_Cases}
      Learning Focus : {Learning_Focus}
      Tech Stack : {Tech_stack}
      Compliance : {Compliance}

    Task:
    - Evaluate the given user answer against the provided question and context.
    - Identify correctness, completeness, and clarity.
    - Highlight strengths in the response.
    - Suggest improvements if necessary.
    - Keep the feedback concise and constructive.
    
    Expected Output:
    Structured evaluation covering:
      - **Understanding Level** (Poor / Fair / Good / Excellent)
      - **Strengths** (bullet points)
      - **Areas to Improve** (bullet points)
    company_contextquestionanswerzJEvaluation including understanding level, strengths, and improvement areas)desc
evaluationN)__name__
__module____qualname____doc__dspy
InputFieldr   str__annotations__r   r   OutputFieldr    r    r    /home/azureuser/microlearn/backend/user_journey_with_openai/agentic_workflow/src/user_journey_service/tools/custom_answer_eval_tool.pyr      s   
 r   c                       s$   e Zd Z fddZdd Z  ZS )AnswerEvaluatorModulec                    s\   t    tt}tjddddddddg}dd	d
}tj|d}|j||d| _	d S )Na  
                    
                    Company Name: FinSight
                    Industry: Financial Services
                    Company Size: 250 employees
                    Business Model: B2B
                    Top Use Cases: Financial modeling
                    Learning Focus: Data Analysis
                    Tech Stack: Excel, Tableau, SQL Server
                    Compliance: SOX, PCI DSS
                                    z5What is the role of SQL in analyzing structured data?zlSQL helps analysts query databases, filter records, and summarize large datasets to support decision-making.a  
                
                **Understanding Level**: Good

                **Strengths**:
                - Correctly explains SQL's role in querying and summarizing data.
                - Focuses on structured data analysis.

                **Areas to Improve**:
                - Could mention SQL's ability to join multiple tables for deeper insights.
                        
                )r   r   r   r   r   r   r   c                    s2   t |ddpd g d}tt fdd|D S )z
            Simple metric: ensure output contains
            - Understanding Level
            - Strengths
            - Areas to Improve
            r    )zUnderstanding Level	StrengthszAreas to Improvec                 3   s    | ]}| v V  qd S Nr    ).0partoutputr    r!   	<genexpr>q   s    zLAnswerEvaluatorModule.__init__.<locals>.evaluation_metric.<locals>.<genexpr>)getattrintall)goldpredtracerequired_partsr    r(   r!   evaluation_metrich   s   z9AnswerEvaluatorModule.__init__.<locals>.evaluation_metric)metric)studenttrainsetr%   )
super__init__r   Predictr   Examplewith_inputsBootstrapFewShotcompile	predictor)selfbase_predictorr5   r2   	optimizer	__class__r    r!   r7   C   s    



 zAnswerEvaluatorModule.__init__c                 C   s   | j |||dS )Nr   r   r   )r=   )r>   r   r   r   r    r    r!   forwardz   s
   zAnswerEvaluatorModule.forward)r   r   r   r7   rD   __classcell__r    r    rA   r!   r"   B   s    7r"   c                   @   s   e Zd ZU dZedddZeed< edddZeed< edddZ	eed	< edd
dZ
eed< edddZeed< edddZeed< edddZeed< edddZeed< edddZeed< edddZeed< dS )AnswerEvaluatorInputz&Input schema for AnswerEvaluationTool..zName of the company)descriptionCompany_NamezIndustry of the companyIndustryzSize of the companyCompany_SizezCompany's business modelBusiness_Modelz$Top use cases the company focuses onTop_Use_CaseszLearning focus for the userLearning_FocuszCompany's tech stack
Tech_stackz Relevant compliance requirements
CompliancezThe question being answeredr   zThe user's provided answerr   N)r   r   r   r   r   rH   r   r   rI   rJ   rK   rL   rM   rN   rO   r   r   r    r    r    r!   rF      s   
 rF   c                   @   sl   e Zd ZU dZeed< dZeed< eZe	e
 ed< dededed	ed
ededededededefddZdS )AnswerEvaluationToolzAnswer Evaluation ToolnamezEvaluates a user's answer to a given question, assessing correctness, completeness, and clarity, while providing constructive feedback.rG   args_schemarH   rI   rJ   rK   rL   rM   rN   rO   r   r   returnc                 C   sR   d| d| d| d| d| d| d| d| d	}t  }|j||	|
d
}|jS )Nz
        Company Name: z
        Industry: z
        Company Size: z
        Business Model: z
        Top Use Cases: z
        Learning Focus: z
        Tech Stack: z
        Compliance: z	
        rC   )r"   rD   r   )r>   rH   rI   rJ   rK   rL   rM   rN   rO   r   r   r   	evaluatorresultr    r    r!   _run   s0   zAnswerEvaluationTool._runN)r   r   r   rQ   r   r   rG   rF   rR   r   r   rV   r    r    r    r!   rP      s8   
 
	
rP   )typingr   crewai.toolsr   pydanticr   r   r   osdotenvr   getenvazure_api_keyazure_api_hostazure_deployment_idazure_api_versionLMr   	configure	Signaturer   Moduler"   rF   rP   r    r    r    r!   <module>   s.    




&A