
    dh"                         S SK Jr  S SKJrJrJrJrJrJrJ	r	  S SK
r
S SKJr  S SKJrJrJr   " S S\\5      r " S S	\\5      r " S
 S\5      r " S S\5      r " S S\5      r " S S5      r " S S5      rg)    )Enum)AnyDictListLiteralMappingOptionalUnionN)Document)	BaseModel	SecretStrmodel_validatorc                   $    \ rS rSrSrSrSrSrSrg)
ArceeRoute   z1Routes available for the Arcee API as enumerator.zmodels/generatezmodels/retrievezmodels/status/{id_or_name} N)	__name__
__module____qualname____firstlineno____doc__generateretrievemodel_training_status__static_attributes__r       [/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/utilities/arcee.pyr   r      s    ; H H8r   r   c                        \ rS rSrSrSrSrSrg)DALMFilterType   z:Filter types available for a DALM retrieval as enumerator.fuzzy_searchstrict_searchr   N)r   r   r   r   r   r!   r"   r   r   r   r   r   r      s    D!L#Mr   r   c                   t    \ rS rSr% Sr\\S'   \\S'   \\S'   Sr\	\S'   \
" SS	9\S
\S\4S j5       5       rSrg)
DALMFilter   a  Filters available for a DALM retrieval and generation.

Arguments:
    field_name: The field to filter on. Can be 'document' or 'name' to filter
        on your document's raw text or title. Any other field will be presumed
        to be a metadata field you included when uploading your context data
    filter_type: Currently 'fuzzy_search' and 'strict_search' are supported.
        'fuzzy_search' means a fuzzy search on the provided field is performed.
        The exact strict doesn't need to exist in the document
        for this to find a match.
        Very useful for scanning a document for some keyword terms.
        'strict_search' means that the exact string must appear
        in the provided field.
        This is NOT an exact eq filter. ie a document with content
        "the happy dog crossed the street" will match on a strict_search of
        "dog" but won't match on "the dog".
        Python equivalent of `return search_string in full_string`.
    value: The actual value to search for in the context data/metadata

field_namefilter_typevalueF_is_metadatabefore)modevaluesreturnc                 4    UR                  S5      S;  US'   U$ )zDdocument and name are reserved arcee keys. Anything else is metadatar&   )documentname_is_meta)get)clsr,   s     r   set_metaDALMFilter.set_meta6   s"     $ZZ5=QQzr   r   N)r   r   r   r   r   str__annotations__r   r)   boolr   classmethodr   r   r4   r   r   r   r   r$   r$      sP    ( OJL$(#d s   $r   r$   c                   8    \ rS rSr% Sr\\S'   \\S'   \\S'   Srg)ArceeDocumentSource>   zSource of an Arcee document.r/   r0   idr   N)r   r   r   r   r   r6   r7   r   r   r   r   r;   r;   >   s    &M
IGr   r;   c                   B    \ rS rSr% Sr\\S'   \\S'   \\S'   \\S'   Sr	g)	ArceeDocumentF   zArcee document.indexr=   scoresourcer   N)
r   r   r   r   r   r6   r7   floatr;   r   r   r   r   r?   r?   F   s    JGLr   r?   c                   4    \ rS rSrSr\S\S\4S j5       rSr	g)ArceeDocumentAdapterO   zAdapter for Arcee documentsarcee_documentr-   c           	          [        UR                  R                  UR                  R                  UR                  R                  UR
                  UR                  UR                  S.S9$ )z=Adapts an `ArceeDocument` to a langchain's `Document` object.)r0   	source_idrA   r=   rB   )page_contentmetadata)r   rC   r/   r0   r=   rA   rB   )r3   rH   s     r   adaptArceeDocumentAdapter.adaptR   s`     '..77 '--22+2255'--$'''--
 	
r   r   N)
r   r   r   r   r   r9   r?   r   rM   r   r   r   r   rF   rF   O   s%    %
= 
X 
 
r   rF   c                   F   \ rS rSrSrS\\\4   S\S\S\\	\\
4      S\4
S jrSS jr   SS\S   S\\\4   S\\\\
4      S\\   S\\   S	\4S jjrSS\\	   S	\	4S jjrS\\\4   S	\4S jrS\S\\\
4   S	\\\
4   4S jrS\S\
S	\4S jrS\S\
S	\\   4S jrSrg
)ArceeWrapperc   zEWrapper for Arcee API.

For more details, see: https://www.arcee.ai/
arcee_api_keyarcee_api_urlarcee_api_versionmodel_kwargs
model_namec                    [        U[        5      (       a  [        U5      nOUnX`l        X@l        X l        X0l         [        R                  R                  R                  US9nU R                  SU5      nUR                  S5      U l        UR                  S5      U l        g! [         a  n	[        SU SU	 35      U	eSn	A	ff = f)zInitialize ArceeWrapper.

Arguments:
    arcee_api_key: API key for Arcee API.
    arcee_api_url: URL for Arcee API.
    arcee_api_version: Version of Arcee API.
    model_kwargs: Keyword arguments for Arcee API.
    model_name: Name of an Arcee model.
)
id_or_namer2   model_idstatusz2Error while validating model training status for 'z': N)
isinstancer6   r   rR   rU   rS   rT   r   r   r(   format_make_requestr2   rY   	Exception
ValueError)
selfrR   rS   rT   rU   rV   arcee_api_key_routeresponsees
             r   __init__ArceeWrapper.__init__i   s    " mS))&}5N*N(6(*!2	44::AAZAXE))%7H$LL4DM)1h)?D& 	DZLPSTUSVW	s   A%B# #
C-B??Cr-   Nc                 V    U R                   S:w  a  [        SU R                   S35      eg )Ntraining_completezModel z4 is not ready. Please wait for training to complete.)r   r^   rY   )r`   s    r   validate_model_training_status+ArceeWrapper.validate_model_training_status   s8    %%)<< (8 8  =r   method)postr2   rb   bodyparamsheadersc                     U R                  US9nU R                  US9n[        [        U5      nU" XcXES9nUR                  S;  a  [        SUR                   35      eUR                  5       $ )zMake a request to the Arcee API
Args:
    method: The HTTP method to use
    route: The route to call
    body: The body of the request
    params: The query params of the request
    headers: The headers of the request
)ro   )rb   )jsonrn   ro   )      z"Failed to make request. Response: )_make_request_headers_make_request_urlgetattrrequestsstatus_coder^   textrq   )	r`   rk   rb   rm   rn   ro   urlreq_typerc   s	            r   r]   ArceeWrapper._make_request   ss      ,,W,=$$5$18V,C6Kz1@PQQ}}r   c                     U=(       d    0 n[        U R                  [        5      (       d!  [        S[	        U R                  5       35      eU R                  R                  5       nUSS.nUR                  U5        U$ )Nz'arcee_api_key must be a SecretStr. Got zapplication/json)zX-TokenzContent-Type)r[   rR   r   	TypeErrortypeget_secret_valueupdate)r`   ro   api_keyinternal_headerss       r   rt   "ArceeWrapper._make_request_headers   sy    -R$,,i889$t?Q?Q:R9ST  $$557.
 	'(r   c                 >    U R                    SU R                   SU 3$ )N/)rS   rT   )r`   rb   s     r   ru   ArceeWrapper._make_request_url   s'    $$%Qt'='=&>awGGr   promptkwargsc                     U R                   =(       d    0 n0 UEUEnUR                  S/ 5       Vs/ sH  n[        S0 UD6PM     nn[        U R                  UUR                  SS5      UU R                  S9$ s  snf )z;Make the request body for generate/retrieve models endpointfilterssize   )rY   queryr   r   r=   r   )rU   r2   r$   dictrY   )r`   r   r   _model_kwargs_paramsfr   s          r   _make_request_body_for_models*ArceeWrapper._make_request_body_for_models   s     ))/R-]-f-,3KK	2,FG,Fq:??,FG]]VQ'}}
 	
 Hs   A7c           	          U R                  S[        R                  R                  U R                  " SSU0UD6S9nUS   $ )zGenerate text from Arcee DALM.

Args:
    prompt: Prompt to generate text from.
    size: The max number of context results to retrieve. Defaults to 3.
      (Can be less if filters are provided).
    filters: Filters to apply to the context dataset.
rl   r   rk   rb   rm   ry   r   )r]   r   r   r(   r   )r`   r   r   rc   s       r   r   ArceeWrapper.generate   sV     %%%%++33  & 
 r   r   c           
          U R                  S[        R                  R                  U R                  " SSU0UD6S9nUS    Vs/ sH!  n[
        R                  [        S0 UD65      PM#     sn$ s  snf )a  Retrieve {size} contexts with your retriever for a given query

Args:
    query: Query to submit to the model
    size: The max number of context results to retrieve. Defaults to 3.
      (Can be less if filters are provided).
    filters: Filters to apply to the context dataset.
rl   r   r   resultsr   )r]   r   r   r(   r   rF   rM   r?   )r`   r   r   rc   docs        r   r   ArceeWrapper.retrieve   s     %%%%++33  & 
  	*
* !&&}';s';<*
 	
 
s   'A-)rR   rS   rT   rY   rU   r   )r-   N)NNN)N)r   r   r   r   r   r
   r6   r   r	   r   r   re   ri   r   r   r   r   r]   rt   ru   r   r   r   r   r   r   r   r   r   rP   rP   c   sq   
"S)^," " 	"
 tCH~." "H -1!%"&& Z_% wsCx()	
  $ 
4Xd^ t HuZ_'= H# H

%,S#X%6
	c	
      
	 0

 
 
h	
r   rP   )enumr   typingr   r   r   r   r   r	   r
   rw   langchain_core.retrieversr   pydanticr   r   r   r6   r   r   r$   r;   r?   rF   rP   r   r   r   <module>r      sv   
  E E E  . : :9d 9$S$ $ D)  I  
 
(]
 ]
r   