
    Fd                    \   d dl mZ d dlmZmZ d dlmZmZ d dlm	Z	m
Z
mZmZmZ e	rd dlmZ ed         Zed         Zee         Z	  G d d	e          Ze G d
 d                      Ze G d d                      Ze G d de                      Ze G d de                      Ze G d de                      Ze G d de                      Ze G d d                      Ze G d d                      Ze G d de                      Ze G d de                      ZdS )    )annotations)	dataclassfield)ceilfloor)TYPE_CHECKINGListLiteralOptional	TypedDict)OpenAIFunctionCall)systemuser	assistant)ai_responseaction_resultc                  $    e Zd ZU ded<   ded<   dS )MessageDictMessageRolerolestrcontentN)__name__
__module____qualname____annotations__     DC:\Users\Administrator\Downloads\Auto-GPT-master\autogpt\llm\base.pyr   r      s%         LLLLLr   r   c                  >    e Zd ZU dZded<   ded<   dZded<   ddZdS )Messagez?OpenAI Message object containing a role and the message contentr   r   r   r   NzMessageType | Nonetypereturnr   c                     | j         | j        dS )Nr   r   r%   selfs    r   rawzMessage.raw   s    	dl;;;r   )r#   r   )r   r   r   __doc__r   r"   r(   r   r   r   r!   r!      sV         IILLL#D####< < < < < <r   r!   c                  2    e Zd ZU dZded<   ded<   ded<   dS )		ModelInfozStruct for model information.

    Would be lovely to eventually get this directly from APIs, but needs to be scraped from
    websites for now.
    r   nameint
max_tokensfloatprompt_token_costNr   r   r   r)   r   r   r   r   r+   r+   "   s<           IIIOOOr   r+   c                      e Zd ZU dZded<   dS )CompletionModelInfoz0Struct for generic completion model information.r/   completion_token_costNr1   r   r   r   r3   r3   /   s$         ::      r   r3   c                      e Zd ZdZdS )ChatModelInfoz"Struct for chat model information.Nr   r   r   r)   r   r   r   r6   r6   6   s        ,,,,r   r6   c                      e Zd ZdZdS )TextModelInfoz-Struct for text completion model information.Nr7   r   r   r   r9   r9   ;   s        7777r   r9   c                      e Zd ZU dZded<   dS )EmbeddingModelInfoz'Struct for embedding model information.r-   embedding_dimensionsNr1   r   r   r   r;   r;   @   s$         11r   r;   c                      e Zd ZU dZded<    ee          Zded<   d d	Zd
 Z	d Z
d!dZd"dZd#dZeg fd$d            Zd%dZed             Zd&dZd'dZdS )(ChatSequencez%Utility container for a chat sequencer6   modeldefault_factoryzlist[Message]messagesir-   c                    | j         |         S NrB   )r'   rC   s     r   __getitem__zChatSequence.__getitem__N   s    }Qr   c                *    t          | j                  S rE   )iterrB   r&   s    r   __iter__zChatSequence.__iter__Q   s    DM"""r   c                *    t          | j                  S rE   )lenrB   r&   s    r   __len__zChatSequence.__len__T   s    4=!!!r   messager!   c                6    | j                             |          S rE   )rB   append)r'   rN   s     r   rP   zChatSequence.appendW   s    }##G,,,r   list[Message] | ChatSequencec                6    | j                             |          S rE   )rB   extend)r'   rB   s     r   rS   zChatSequence.extendZ   s    }##H---r   indexc                `    t          |          D ]}| j                            ||           d S rE   )reversedrB   insert)r'   rT   rB   rN   s       r   rW   zChatSequence.insert]   s>    )) 	1 	1GM  0000	1 	1r   
model_namer   c                    ddl m} ||vrt          d| d          t          ||         t	          |                    S )Nr   )OPEN_AI_CHAT_MODELSzUnknown chat model '')r?   rB   )autogpt.llm.providers.openairZ   
ValueErrorr>   list)clsrX   rB   rZ   s       r   	for_modelzChatSequence.for_modela   sa    DDDDDD000AJAAABBB%j1DNN
 
 
 	
r   message_roler   r   c                V    | j                             t          ||                     d S rE   )rB   rP   r!   )r'   ra   r   s      r   addzChatSequence.addl   s(    W\7;;<<<<<r   c                D    ddl m}  || j        | j        j                  S )Nr   )count_message_tokens)autogpt.llm.utilsre   rB   r?   r,   )r'   re   s     r   token_lengthzChatSequence.token_lengtho   s-    ::::::##DM4:?CCCr   r#   list[MessageDict]c                $    d | j         D             S )Nc                6    g | ]}|                                 S r   )r(   ).0ms     r   
<listcomp>z$ChatSequence.raw.<locals>.<listcomp>v   s     ///A///r   rF   r&   s    r   r(   zChatSequence.rawu   s    //////r   c                    ddfdd                     fd| j        D                       }d| j         dt          | j                   d	| d
S )N*   textr   c                    dz
  t          |           z
  dz  }t          |          dz   d|                                  dt          |          dz   S )N   - )rL   r   upperr   )rp   half_sep_lenSEPARATOR_LENGTHs     r   	separatorz$ChatSequence.dump.<locals>.separator{   s\    ,q03t99<ALL))#-WW

WWtL?Q?QRU?UWWWr   
c                D    g | ]} |j                    d |j         S )ry   r%   )rk   rl   rx   s     r   rm   z%ChatSequence.dump.<locals>.<listcomp>   s5    HHHQ		!&!!00QY00HHHr   z4
============== ChatSequence ==============
Length: z	 tokens; z
 messages
z,
==========================================
)rp   r   )joinrB   rg   rL   )r'   formatted_messagesrw   rx   s     @@r   dumpzChatSequence.dumpx   s    	X 	X 	X 	X 	X 	X "YYHHHH$-HHH
 
		 %(%7%7     	r   N)rC   r-   )rN   r!   )rB   rQ   )rT   r-   rB   r!   )rX   r   rB   rQ   )ra   r   r   r   )r#   rh   )r#   r   )r   r   r   r)   r   r   r^   rB   rG   rJ   rM   rP   rS   rW   classmethodr`   rc   propertyrg   r(   r}   r   r   r   r>   r>   G   s6        //#eD999H9999       # # #" " "- - - -. . . .1 1 1 1 QS 
 
 
 
 [
= = = = D D XD
0 0 0 0     r   r>   c                  :    e Zd ZU dZded<   dZded<   dZded<   dS )	LLMResponse:Standard response struct for a response from an LLM model.r+   
model_infor   r-   prompt_tokens_usedcompletion_tokens_usedN)r   r   r   r)   r   r   r   r   r   r   r   r      sH         DD"#######r   r   c                  <    e Zd ZU dZ ee          Zded<   d ZdS )EmbeddingModelResponsez@Standard response struct for a response from an embedding model.r@   zList[float]	embeddingc                2    | j         rt          d          d S )Nz2Embeddings should not have completion tokens used.)r   r]   r&   s    r   __post_init__z$EmbeddingModelResponse.__post_init__   s)    & 	SQRRR	S 	Sr   N)	r   r   r   r)   r   r^   r   r   r   r   r   r   r   r      sN         JJ"U4888I8888S S S S Sr   r   c                  0    e Zd ZU dZdZded<   dZded<   dS )ChatModelResponser   NzOptional[str]r   zOptional[OpenAIFunctionCall]function_call)r   r   r   r)   r   r   r   r   r   r   r   r      s:         DD!G!!!!26M666666r   r   N) 
__future__r   dataclassesr   r   mathr   r   typingr   r	   r
   r   r   r\   r   r   MessageTyper^   r-   TTextr   r!   r+   r3   r6   r9   r;   r>   r   r   r   r   r   r   <module>r      s   " " " " " " ( ( ( ( ( ( ( (         D D D D D D D D D D D D D D @??????3445S	 -    )   
 < < < < < < < < 	 	 	 	 	 	 	 	 ! ! ! ! !) ! ! ! - - - - -' - - - 8 8 8 8 8' 8 8 8         ? ? ? ? ? ? ? ?D $ $ $ $ $ $ $ $ S S S S S[ S S S 7 7 7 7 7 7 7 7 7 7r   