o
    չh                     @   s   d Z ddlZddlZddlmZmZ ddlmZ ejej	d e
eZdedee defd	d
ZedkrWddddddddddddgZedeZeejedd dS dS )z,
Ultra-simple department matching using LLM
    N)DictList)
ChatOllama)leveluser_promptdepartmentsreturnc              
   C   s  zt ddd}ddd |D }d|  d| d	}||j }td
|  z0d|v rYd|v rY||d|dd  }t	
|}|dd|d|dddW W S W nA t	jtfy } z2td|  | }	|D ]}
|
d  |	v r|
d |
d dd  W  Y d}~W S qsW Y d}~nd}~ww ddddW S  ty } ztd|  dddt|dW  Y d}~S d}~ww )zW
    Match user goal to department using LLM.
    Simple. Direct. No overthinking.
    z
gemma3:12bg?)modeltemperature
c                 S   s&   g | ]}d |d  d|d  dqS )z- namez (ID: id) ).0dr   r   I/var/www/eduai.edurigo.com/doc_train/edurigo_ai/TNA/testing/department.py
<listcomp>   s   & z&analyze_department.<locals>.<listcomp>zGAnalyze this goal and match it to the most relevant department.

Goal: z

Available Departments:
z

Respond in JSON format:
{"department_name": "exact name from list", "department_id": number, "confidence": "high/medium/low"}

If no good match, use: {"department_name": "", "department_id": null, "confidence": "none"}

Response:zLLM response: {}   department_name department_id
confidencelow)identified_departmentr   r   z&JSON parse failed, trying text match: r   r   mediumNnonezAnalysis failed: )r   r   r   error)r   joininvokecontentstriploggerinfoindexrindexjsonloadsgetJSONDecodeError
ValueErrorwarninglower	Exceptionr   str)r   r   llm	dept_listpromptresponsejson_strresulteresponse_lowerdeptr   r   r   analyze_department   sZ   



r:   __main__r   zHuman Resources)r   r      zInformation Technology   Sales   	Marketingz6I want to improve team communication and collaboration)indent)__doc__r(   loggingtypingr   r   langchain_ollamar   basicConfigINFO	getLogger__name__r$   r0   r:   test_departmentsr6   printdumpsr   r   r   r   <module>   s(    
J