o
    Kh.                     @   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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_API_VERSIONzazure/Csqr-gpt-4o-minig        )api_keyapi_baseapi_versiontemperature)lmc                   @   sF   e Zd ZU dZe Zeed< e Z	eed< ej
ddZeed< dS )FinalAssessmentSignaturea  
    You are an Overall User Performance Assessor.
    Review all question-answer pairs and generate an overall feedback summary.

    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}

    Review all the user's answers and provide an overall final feedback summary in a single sentence.
    This is the users response {users_response}
    A comprehensive final feedback sentence summarizing the user's overall performance across all questions.
    
    company_contextqa_textz?A single comprehensive sentence summarizing overall performance)descfinal_feedbackN)__name__
__module____qualname____doc__dspy
InputFieldr   str__annotations__r   OutputFieldr    r   r   /home/azureuser/microlearn/backend/user_journey_with_openai/agentic_workflow/src/user_journey_service/tools/custom_final_assess_tool.pyr      s   
 r   c                       s$   e Zd Z fddZdd Z  ZS )FinalAssessmentModulec                    sZ   t    tt| _tjddddddg}dd }tj|d	}|j	| 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
                    a  
                    "What is SQL used for?":"SQL is useful for querying structured data, though I struggle with advanced joins."
                    "How does regression help in finance?":"Regression detects trends but I need practice applying it to forecasting."
                    "Why is visualization important?":"It communicates insights, though my design skills are limited."
                    zThe learner demonstrates a fair grasp of fundamentals but needs improvement in applying advanced concepts and communication clarity.)r   r   r   r   r   c                 S   sD   t |ddpd}|ddkp| d}t|o t| dkS )Nr    .   (   )getattrcountstripendswithintlensplit)goldpredtraceoutputis_single_sentencer   r   r   feedback_metricT   s   z7FinalAssessmentModule.__init__.<locals>.feedback_metric)metric)trainset)super__init__r   Predictr   	predictorExamplewith_inputsBootstrapFewShotcompileoptimized_predictor)selfr3   r1   	optimizer	__class__r   r   r5   9   s   

zFinalAssessmentModule.__init__c                 C   s   | j ||dS )Nr   r   )r<   )r=   r   r   r   r   r   forward]   s   zFinalAssessmentModule.forward)r   r   r   r5   rB   __classcell__r   r   r?   r   r    8   s    $r    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 ed< dS )FinalAssessmentInputz%Input schema for FinalAssessmentTool..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
Compliancez9List of Q&A pairs, each dict must have {question, answer}qa_pairsN)r   r   r   r   r   rF   r   r   rG   rH   rI   rJ   rK   rL   rM   rN   listdictr   r   r   r   rD   e   s   
 rD   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e defddZdS )FinalAssessmentToolzFinal Assessment Toolnamez[Reviews all user answers and generates a one-sentence overall performance feedback summary.rE   args_schemarF   rG   rH   rI   rJ   rK   rL   rM   rN   returnc
                 C   sd   d| d| d| d| 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	
        
c                 S   s$   g | ]}d |d  d|d  qS )zQ: questionz
A: answerr   ).0pairr   r   r   
<listcomp>   s   $ z,FinalAssessmentTool._run.<locals>.<listcomp>rA   )joinr    rB   r   )r=   rF   rG   rH   rI   rJ   rK   rL   rM   rN   r   r   assessorresultr   r   r   _runz   s4   zFinalAssessmentTool._runN)r   r   r   rR   r   r   rE   rD   rS   r   r   rO   rP   r^   r   r   r   r   rQ   s   s4   
 
	
rQ   )typingr   crewai.toolsr   pydanticr   r   r   osdotenvr   getenvazure_api_keyazure_api_hostazure_api_versionLMr   	configure	Signaturer   Moduler    rD   rQ   r   r   r   r   <module>   s,    



-