
    Zi              
           d dl Z d dlZd dlmZmZmZ ddlmZmZ efde	de	de
fdZefd	ee         d
e
deee	e	f                  fdZdS )    N)SequenceListDict   )DEFAULT_MODEL_ENCODINGDEFAULT_MAX_TOKENSstringencoding_namereturnc                 r    t          j        |          }|                    |           }t          |          S )zk
        Get total amount of tokens from string using the specified encoding (based on openai compute)
    )tiktokenencoding_for_modelencodelen)r	   r
   encodingtokenss       G/root/projects/butler/venv/lib/python3.11/site-packages/tavily/utils.pyget_total_tokens_from_stringr      s1     *=99H__V$$Fv;;    data
max_tokensc                     g }d}| D ]G}t          j        |          }|t          |          z   }||k    r n|                    |           |}H|S )zd
        Get max items from list of items based on defined max tokens (based on openai compute)
    r   )jsondumpsr   append)r   r   resultcurrent_tokensitemitem_strnew_total_tokenss          r   get_max_items_from_listr!      sn     FN . .:d##),H,R,RRj((EMM$-NNMr   )r   r   typingr   r   r   configr   r   strintr   dictr!    r   r   <module>r(      s      ' ' ' ' ' ' ' ' ' ' > > > > > > > > DZ   S ^a     EW  (4. c [_`dehilel`m[n      r   