pyc • Lines: 896�
xq�j�] � �� � d Z ddlZddlZddlZddlZddlmZ ddlmZm Z ddl
Z
ddlmZ dZ
dZdZd Zd
ZdZdZd
ZdZd� Zd� Zd� Zdd�Zd� Zd� Zd� Zd� Zdd�Zd� Zdd�Z d� Z!d� Z"y)zJLLM tool implementations: web search, page fetching, image tools dispatch.� N)�datetime)� urlencode�urlparse)�M�
� ip � )z text/htmlz
text/plainzapplication/xhtmlzapplication/jsonzapplication/xmli N i� � g �?c �z � dD ] } | j |� c S | j dd�� S # t $ r Y �6w xY w)N)z utf-8-sig�utf-8�latin-1r
�replace��errors)�decode�UnicodeDecodeError)�raw�encs �2/home/palash/git/local-ai/server/features/tools.py�_decode_response_textr , sM � �0� �� ��:�:�c�?�"��
�:�:�i� �:�2�2�� "� �� �s �.� :�:c � � t j j t | � j � d j � }|xs dj d� d j
� j � }|dk( s|dk( s|j d� ry|d k( s|d
k( ry|dk( s|j d
� ry|dv s|dv ry|dk( r|dv r|dk( rdS |d
k( rdS dS y)ax Classify fetched content as ``pdf``/``csv``/``excel`` or ``None``.
Content-Type is trusted first, then the URL extension, then magic bytes.
Anything unrecognized returns ``None`` so :func:`fetch_page` declines it as
binary instead of trying to read it. Legacy ``.xls`` (OLE2 compound
documents) is detected separately since no parser is available for it.
� � �;r zapplication/pdf�.pdfs %PDF-�pdfztext/csv�.csv�csvz.xlss ��ࡱ��excel_xls_unsupported)zAapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheetzapplication/vnd.ms-excelzapplication/excel)�.xlsx�.xlsm�.xltm�.xltx�excelzapplication/octet-stream)r r r r! r"