
    Rmj                    f   d Z ddlmZ ddlmZmZmZmZ ddlm	Z	m
Z
mZmZ ddlmZmZ ddlmZ  G d de          Z G d	 d
ed          Z G d de          Z G d de
          Zd4dZd5dZ ed           G d d                      Z ed           G d d                      Z ed           G d d                      Z ed           G d  d!                      Z ed           G d" d#                      Z ed           G d$ d%                      Z ed           G d& d'                      Z ed           G d( d)                      Z ed           G d* d+                      Z d,Z! ed           G d- d.                      Z"d6d1Z#g d2Z$d3S )7z+Model pricing plugin configuration helpers.    )annotations)	dataclassfieldfieldsis_dataclass)LiteralProtocol	TypedDictcast)Json
JsonObject)pluginc                  .    e Zd ZU ded<   ded<   ded<   dS )_ConfigDiagnosticRequiredzLiteral['warning', 'error']levelstrcodemessageN)__name__
__module____qualname____annotations__     `/home/thesage/.hermes/hermes-agent/venv/lib/python3.11/site-packages/nemo_relay/model_pricing.pyr   r      s.         &&&&IIILLLLLr   r   c                  (    e Zd ZU dZded<   ded<   dS )ConfigDiagnosticz(One model pricing validation diagnostic.r   	componentr   Nr   r   r   __doc__r   r   r   r   r   r      s(         22NNNJJJJJr   r   F)totalc                      e Zd ZU dZded<   dS )ConfigReportz2Validation report for model pricing configuration.zlist[ConfigDiagnostic]diagnosticsNr   r   r   r   r#   r#      s$         <<''''''r   r#   c                      e Zd ZddZdS )_SupportsToDictreturnr   c                    d S Nr   selfs    r   to_dictz_SupportsToDict.to_dict#   s      r   Nr'   r   )r   r   r   r,   r   r   r   r&   r&   "   s        ((((((r   r&   valueobjectr'   r   c                    t           d          r't          t                                                     S t	                     r1t           t                    s fdt                     D             S t           t                    rd  D             S t           t                    rd  
                                D             S t          t                     S )Nr,   c                h    i | ].}t          |j                  x|j        t                    /S r)   )getattrname
_normalize).0
field_infofield_valuer.   s     r   
<dictcomp>z_normalize.<locals>.<dictcomp>*   sF     
 
 
&ujo>>>K OZ44KKKr   c                ,    g | ]}t          |          S r   )r4   )r5   items     r   
<listcomp>z_normalize.<locals>.<listcomp>0   s     333T
4  333r   c                ^    i | ]*\  }}|t          t          |          t          |          +S r)   )r   r   r4   )r5   keyvals      r   r8   z_normalize.<locals>.<dictcomp>2   s2    aaaHCQTQ`S#
3Q`Q`Q`r   )hasattrr   r&   r,   r   
isinstancetyper   listdictitemsr   )r.   r7   s   `@r   r4   r4   &   s    ui   6OU++33555E 
:eT#:#: 

 
 
 
 
$Umm
 
 
 	

 % 433U3333% baaaaaaer   r   c                F    t          t          t          |                     S r)   )r   r   r4   )r.   s    r   _normalize_objectrF   6   s    
Ju--...r   T)slotsc                  L    e Zd ZU dZded<   ded<   dZded<   dZded<   ddZdS )TokenPricingRatesz7Per-token model rates expressed per one million tokens.floatinput_per_millionoutput_per_millionNzfloat | Nonecache_read_per_millioncache_write_per_millionr'   r   c                R    t          | j        | j        | j        | j        d          S )z9Serialize these rates to the canonical JSON object shape.)rK   rL   rM   rN   )rF   rK   rL   rM   rN   r*   s    r   r,   zTokenPricingRates.to_dictC   s6     %)%;&*&=*.*E+/+G	 
 
 	
r   r-   )r   r   r   r    r   rM   rN   r,   r   r   r   rI   rI   :   sl         AA+/////,00000	
 	
 	
 	
 	
 	
r   rI   c                  *    e Zd ZU dZdZded<   d	dZdS )
PromptCachePricingz;Prompt-cache accounting settings for a model pricing entry.included_in_prompt_tokensz0Literal['included_in_prompt_tokens', 'separate']read_accountingr'   r   c                    d| j         iS )zFSerialize this prompt-cache config to the canonical JSON object shape.rS   )rS   r*   s    r   r,   zPromptCachePricing.to_dictU   s    !4#788r   Nr-   )r   r   r   r    rS   r   r,   r   r   r   rQ   rQ   O   sA         EEHcOcccc9 9 9 9 9 9r   rQ   c                  B    e Zd ZU dZded<   dZded<   dZded<   dd
ZdS )TokenRateTierz,One threshold tier in a token rate schedule.zTokenPricingRates | JsonObjectratesNz
int | Nonemin_prompt_tokensmax_prompt_tokensr'   r   c                F    t          | j        | j        | j        d          S )z<Serialize this rate tier to the canonical JSON object shape.)rX   rY   rW   )rF   rX   rY   rW   r*   s    r   r,   zTokenRateTier.to_dictb   s/     %)%;%)%; 
 
 	
r   r-   )r   r   r   r    r   rX   rY   r,   r   r   r   rV   rV   Z   s`         66))))$((((($(((((
 
 
 
 
 
r   rV   c                  L    e Zd ZU dZ ee          Zded<   dZded<   dd
Z	dS ) PromptTokenThresholdRateSchedulez?Rate schedule selected by full-request prompt token thresholds.default_factoryz list[TokenRateTier | JsonObject]tiersfull_requestzLiteral['full_request']
applies_tor'   r   c                <    t          d| j        | j        d          S )z@Serialize this rate schedule to the canonical JSON object shape.prompt_token_threshold)rA   ra   r_   )rF   ra   r_   r*   s    r   r,   z(PromptTokenThresholdRateSchedule.to_dictt   s+     0"o 
 
 	
r   Nr-   )
r   r   r   r    r   rB   r_   r   ra   r,   r   r   r   r\   r\   m   s_         II.3eD.I.I.IEIIII*8J8888
 
 
 
 
 
r   r\   c                      e Zd ZU dZded<   ded<   ded<   ded<    ee          Zded	<   d
Zded<   dZ	ded<   dZ
ded<   dZded<    ee          Zded<   ddZdS )ModelPricingz One model pricing catalog entry.r   providermodel_idpricing_as_ofpricing_sourcer]   z	list[str]aliasesUSDcurrency	per_tokenz=Literal['per_token', 'per_request', 'per_second', 'gpu_hour']unitNz%TokenPricingRates | JsonObject | NonerW   z4PromptTokenThresholdRateSchedule | JsonObject | Nonerate_schedulezPromptCachePricing | JsonObjectprompt_cacher'   r   c                    t          | j        | j        | j        | j        | j        | j        | j        | j        | j	        | j
        d
          S )z@Serialize this catalog entry to the canonical JSON object shape.)
rf   rg   rj   rl   rn   rW   ro   rp   rh   ri   )rF   rf   rg   rj   rl   rn   rW   ro   rp   rh   ri   r*   s    r   r,   zModelPricing.to_dict   sT      M M< M	!%!3 $ 1!%!3"&"5 
 
 	
r   r-   )r   r   r   r    r   r   rB   rj   rl   rn   rW   ro   rQ   rp   r,   r   r   r   re   re      s         **MMMMMMt444G4444HJUDUUUU37E7777JNMNNNN49EJ\4]4]4]L]]]]
 
 
 
 
 
r   re   c                  L    e Zd ZU dZ ee          Zded<   dZded<   dd
Z	dS )PricingCatalogz%Inline model pricing catalog payload.r]   zlist[ModelPricing | JsonObject]entries   intversionr'   r   c                :    t          | j        | j        d          S )z:Serialize this catalog to the canonical JSON object shape.)rw   rt   )rF   rw   rt   r*   s    r   r,   zPricingCatalog.to_dict   s(     << 
 
 	
r   Nr-   )
r   r   r   r    r   rB   rt   r   rw   r,   r   r   r   rs   rs      s_         ///4uT/J/J/JGJJJJG
 
 
 
 
 
r   rs   c                  &    e Zd ZU dZded<   ddZdS )	InlineSourcez+Pricing source backed by an inline catalog.zPricingCatalog | JsonObjectcatalogr'   r   c                0    t          d| j        d          S )9Serialize this source to the canonical JSON object shape.inline)rA   r{   )rF   r{   r*   s    r   r,   zInlineSource.to_dict   s&      < 
 
 	
r   Nr-   r   r   r   r    r   r,   r   r   r   rz   rz      s<         55((((
 
 
 
 
 
r   rz   c                  &    e Zd ZU dZded<   ddZdS )	
FileSourcez-Pricing source backed by a JSON catalog file.r   pathr'   r   c                    d| j         dS )r}   file)rA   r   )r   r*   s    r   r,   zFileSource.to_dict   s     I
 
 	
r   Nr-   r   r   r   r   r   r      s9         77III
 
 
 
 
 
r   r   c                  >    e Zd ZU dZ ee          Zded<   d	dZdS )
PricingConfigzDCanonical config document for the top-level model pricing component.r]   z,list[InlineSource | FileSource | JsonObject]sourcesr'   r   c                .    t          d| j        i          S )zGSerialize this model pricing config to the canonical JSON object shape.r   )rF   r   r*   s    r   r,   zPricingConfig.to_dict   s     )T\!:;;;r   Nr-   )	r   r   r   r    r   rB   r   r   r,   r   r   r   r   r      sO         NN<AERV<W<W<WGWWWW< < < < < <r   r   pricingc                  4    e Zd ZU dZded<   dZded<   dd	Zd
S )ComponentSpecz*Top-level model pricing component wrapper.PricingConfig | JsonObjectconfigTboolenabledr'   r   c                F    t           | j        t          | j                  dS )z7Serialize this component to the canonical plugin shape.)kindr   r   )PRICING_PLUGIN_KINDr   rF   r   r*   s    r   r,   zComponentSpec.to_dict   s(     (|'44
 
 	
r   Nr-   )r   r   r   r    r   r   r,   r   r   r   r   r      sM         44&&&&G
 
 
 
 
 
r   r   r   r   c                    t          j        t          j        t          |           g                    }t	          t
          |          S )z?Validate a model pricing config document without activating it.)
components)plugin_modulevalidatePluginConfigr   r   r#   )r   reports     r   validate_configr      sI    #"%f--.	
 	
 	
 F
 f%%%r   )r   r   r#   r   rz   re   r   rQ   r\   rs   r   rI   rV   r   N)r.   r/   r'   r   )r.   r/   r'   r   )r   r   r'   r#   )%r    
__future__r   dataclassesr   r   r   r   typingr   r	   r
   r   
nemo_relayr   r   r   r   r   r   r#   r&   r4   rF   rI   rQ   rV   r\   re   rs   rz   r   r   r   r   r   __all__r   r   r   <module>r      s/   2 1 " " " " " " > > > > > > > > > > > > 5 5 5 5 5 5 5 5 5 5 5 5 ' ' ' ' ' ' ' ' . . . . . .    	       0    ( ( ( ( (9 ( ( () ) ) ) )h ) ) )    / / / / 
 
 
 
 
 
 
 
( 9 9 9 9 9 9 9 9 
 
 
 
 
 
 
 
$ 
 
 
 
 
 
 
 
" 
 
 
 
 
 
 
 
@ 
 
 
 
 
 
 
 
  
 
 
 
 
 
 
 
 

 

 

 

 

 

 

 

 < < < < < < < <    
 
 
 
 
 
 
 
& & & &  r   