
    Fd                    x    d dl mZ d dlmZm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  G d d	e
          ZdS )    )annotations)ListOptionalN)Model)CompletionModelInfo)logger)	Singletonc                  F    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
ddZdS )
ApiManagerc                L    d| _         d| _        d| _        d| _        d | _        d S )Nr   total_prompt_tokenstotal_completion_tokens
total_costtotal_budgetmodelsselfs    KC:\Users\Administrator\Downloads\Auto-GPT-master\autogpt\llm\api_manager.py__init__zApiManager.__init__   s,    #$ '($-1    c                L    d| _         d| _        d| _        d| _        d | _        d S )Nr   g        r   r   s    r   resetzApiManager.reset   s,    #$ '($r   c                   ddl m} |                    d          r
|dd         n|}||         }| xj        |z  c_        | xj        |z  c_        | xj        ||j        z  dz  z  c_        t          t          |          t                    r| xj        ||j
        z  dz  z  c_        t          j        d| j        d           dS )	a'  
        Update the total cost, prompt tokens, and completion tokens.

        Args:
        prompt_tokens (int): The number of tokens used in the prompt.
        completion_tokens (int): The number of tokens used in the completion.
        model (str): The model used for the API call.
        r   )OPEN_AI_MODELSz-v2Ni  zTotal running cost: $z.3f)autogpt.llm.providers.openair   endswithr   r   r   prompt_token_cost
issubclasstyper   completion_token_costr   debug)r   prompt_tokenscompletion_tokensmodelr   
model_infos         r   update_costzApiManager.update_cost   s     	@?????#nnU33>crc

#E*
  M1  $$(99$$=:+GG$NNd:&&(;<< 	OO!J$DDtKOO 	BT_BBBCCCCCr   c                    || _         dS )z
        Sets the total user-defined budget for API calls.

        Args:
        total_budget (float): The total budget for API calls.
        Nr   )r   r   s     r   set_total_budgetzApiManager.set_total_budget5   s     )r   c                    | j         S )zz
        Get the total number of prompt tokens.

        Returns:
        int: The total number of prompt tokens.
        )r   r   s    r   get_total_prompt_tokensz"ApiManager.get_total_prompt_tokens>   s     ''r   c                    | j         S )z
        Get the total number of completion tokens.

        Returns:
        int: The total number of completion tokens.
        )r   r   s    r   get_total_completion_tokensz&ApiManager.get_total_completion_tokensG   s     ++r   c                    | j         S )zp
        Get the total cost of API calls.

        Returns:
        float: The total cost of API calls.
        )r   r   s    r   get_total_costzApiManager.get_total_costP   s     r   c                    | j         S )z
        Get the total user-defined budget for API calls.

        Returns:
        float: The total budget for API calls.
        r*   r   s    r   get_total_budgetzApiManager.get_total_budgetY   s       r   returnList[Model]c                    | j         5t          j                                        d         }d |D             | _         | j         S )zr
        Get list of available GPT models.

        Returns:
        list: List of available GPT models.

        Ndatac                &    g | ]}d |d         v |S )gptid ).0r&   s     r   
<listcomp>z)ApiManager.get_models.<locals>.<listcomp>l   s&    QQQUEU4[<P<P5<P<P<Pr   )r   openair   list)r   
all_modelss     r   
get_modelszApiManager.get_modelsb   sA     ;**,,V4JQQjQQQDK{r   N)r4   r5   )__name__
__module____qualname__r   r   r(   r+   r-   r/   r1   r3   rA   r;   r   r   r   r      s        2 2 2  D D D2) ) )( ( (, , ,  ! ! !     r   r   )	metaclass)
__future__r   typingr   r   r>   r   autogpt.llm.baser   autogpt.logsr   autogpt.singletonr	   r   r;   r   r   <module>rK      s    " " " " " " ! ! ! ! ! ! ! !        0 0 0 0 0 0       ' ' ' ' ' 'a a a a a9 a a a a a ar   