
    j j                         d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	  e	d            e e j
        d          	          Zd
ZdedefdZdS )    N)Path)OpenAI)read_file_content)load_dotenvT)overrideOPENAI_API_KEY)api_keya  You are a pharma document classifier.

Classify the uploaded document based on its content.

Return JSON only with these exact fields:
{
  "filename": "<filename>",
  "document_type": one of ["SOP", "Batch Record", "Equipment Log", "LIMS Results", "Maintenance Log", "Deviation Report", "Unknown"],
  "document_type_code": one of ["SOP", "BMR", "EQP", "LIMS", "MAINT", "DEV", "UNKNOWN"],
  "confidence": number between 0 and 100,
  "batch_id": string or null,
  "product_name": string or null,
  "equipment_id": string or null,
  "plant": string or null,
  "date_range": string or null,
  "key_fields_found": array of strings,
  "missing_context": array of strings
}

Document filename: <filename>
Document content:
<content>
	file_pathreturnc           
        K   	 t          |           }t                              d| j                  }|                    d|d d                   }t          j        j                            ddddd|dgd	d
id          }|j        d         j	        j
        }t          j        |          }| j        |d<   d|d<   |                    dd          }|dk    rd|d<   n|dk    rd|d<   nd|d<   |S # t          j        $ r&}| j        dddddt          |          dcY d }~S d }~wt           $ r&}| j        dddddt          |          dcY d }~S d }~ww xY w)Nz
<filename>z	<content>i  zgpt-4osystemzFYou are a pharma document classifier. Return JSON only. No extra text.)rolecontentusertypejson_objectr   )modelmessagesresponse_formattemperaturefilename
classifiedstatus
confidenceU   VERIFIEDverification_status<   zNEEDS REVIEWzLOW CONFIDENCEUnknownUNKNOWNparse_error)r   document_typedocument_type_coder   r   r   errorr$   )r   CLASSIFY_PROMPTreplacenameclientchatcompletionscreatechoicesmessager   jsonloadsgetJSONDecodeErrorstr	Exception)r
   r   promptresponserawresultr   es           EC:\Users\Terasoftware\OneDrive\Desktop\faahhh\fyndo\fyndo\classify.pyclassify_documentr:   $   s     9
#I.. ((y~FFWUdU^<<;*11 %g 
 #% 	 $]3 2 
 
  q!)1C&^z'x ZZa00
 	=,6F())2 	=,:F()),<F() 	
 	
 	
!&"+#3#VV
 
 	
 	
 	
 	
 	
 	
  	
 	
 	
!&"+#3VV
 
 	
 	
 	
 	
 	
 	
	
s0   C-C2 2ED"E"E/E
EE)osr.   pathlibr   openair   file_readerr   dotenvr   getenvr(   r%   dictr:        r9   <module>rD      s    				              ) ) ) ) ) )       T    			"233	4	4	42:
t :
 :
 :
 :
 :
 :
 :
rC   