
    Ng	                        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j        e          Z G d de	          Z G d	 d
e          ZdS )    )annotationsN)OptionalType)CallbackManagerForToolRun)	BaseModelFieldHttpUrl)
EdenaiToolc                  2    e Zd ZU  ed          Zded<   dS )InvoiceParsingInputzurl of the document to parse)descriptionr	   queryN)__name__
__module____qualname__r   r   __annotations__     n/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/tools/edenai/ocr_invoiceparser.pyr   r      s1         U'EFFFEFFFFFFr   r   c                  ~    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Z	 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

    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]languageocrfeatureinvoice_parser
subfeatureresponselistreturnc                (   g }t          |          dk    r)|                     |d         d         d         |           n@|D ]=}|                    d          dk    r"|                     |d         d         |           >d                    |          S )N   r   extracted_dataproviderzeden-ai
)len_parse_json_multilevelgetjoin)selfr!   formatted_listentrys       r   _parse_responsez(EdenAiParsingInvoiceTool._parse_response2   s    !x==A'',-a0.    "  99Z((I55//./2N   yy(((r   r   run_manager#Optional[CallbackManagerForToolRun]c                B    || j         dd}|                     |          S )zUse the tool.F)file_urlr   attributes_as_list)r   _call_eden_ai)r-   r   r1   query_paramss       r   _runzEdenAiParsingInvoiceTool._runB   s1     "'
 
 !!,///r   )r!   r"   r#   r   )N)r   r   r1   r2   r#   r   )r   r   r   __doc__r   r   r   r   r   r   r   r    r0   r8   r   r   r   r   r      s         	 	 )D((((	C      $7K6666"H"""" G&J&&&&) ) ) )& <@0 0 0 0 0 0 0r   r   )
__future__r   loggingtypingr   r   langchain_core.callbacksr   pydanticr   r   r	   1langchain_community.tools.edenai.edenai_base_toolr
   	getLoggerr   loggerr   r   r   r   r   <module>rB      s    " " " " " "  ! ! ! ! ! ! ! ! > > > > > > . . . . . . . . . . H H H H H H		8	$	$G G G G G) G G G<0 <0 <0 <0 <0z <0 <0 <0 <0 <0r   