a
    bg	                     @  s~   d dl mZ d dlZd dlmZmZ d dlmZ d dlm	Z	m
Z
mZ d dlmZ eeZG dd de	ZG d	d
 d
eZdS )    )annotationsN)OptionalType)CallbackManagerForToolRun)	BaseModelFieldHttpUrl)
EdenaiToolc                   @  s    e Zd ZU eddZded< dS )InvoiceParsingInputzurl of the document to parse)descriptionr   queryN)__name__
__module____qualname__r   r   __annotations__ r   r   /var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/tools/edenai/ocr_invoiceparser.pyr
      s   
r
   c                   @  s~   e Zd ZU dZdZded< dZded< eZded< d	Z	d
ed< dZ
ded< dZded< dddddZdddddddZd	S )EdenAiParsingInvoiceToolaa  Tool that queries the Eden AI Invoice parsing API.

    for api reference check edenai documentation:
    https://docs.edenai.co/reference/ocr_invoice_parser_create.

    To use, you should have
    the environment variable ``EDENAI_API_KEY`` set with your API token.
    You can find your token here: https://app.edenai.run/admin/account/settings

    Zedenai_invoice_parsingstrnamea  A wrapper around edenai Services invoice parsing. Useful for when you have to extract information from 
        an image it enables to take invoices 
        in a variety of formats and returns the data in contains
        (items, prices, addresses, vendor name, etc.)
        in a structured format to automate the invoice processing Input should be the string url of the document to parse.r   zType[BaseModel]args_schemaNzOptional[str]languageZocrfeatureZinvoice_parser
subfeaturelist)responsereturnc                 C  s`   g }t |dkr*| |d d d | n,|D ]&}|ddkr.| |d d | q.d|S )N   r   Zextracted_dataproviderzeden-ai
)lenZ_parse_json_multilevelgetjoin)selfr   Zformatted_listentryr   r   r   _parse_response2   s    z(EdenAiParsingInvoiceTool._parse_responsez#Optional[CallbackManagerForToolRun])r   run_managerr   c                 C  s   || j dd}| |S )zUse the tool.F)file_urlr   Zattributes_as_list)r   Z_call_eden_ai)r#   r   r&   Zquery_paramsr   r   r   _runB   s
    zEdenAiParsingInvoiceTool._run)N)r   r   r   __doc__r   r   r   r
   r   r   r   r   r%   r(   r   r   r   r   r      s   

	 r   )
__future__r   loggingtypingr   r   Zlangchain_core.callbacksr   Zpydanticr   r   r   Z1langchain_community.tools.edenai.edenai_base_toolr	   	getLoggerr   loggerr
   r   r   r   r   r   <module>   s   
