o
    iZ                     @  s   d dl mZ d dlZd dlZd dlmZ d dlmZ d dlZddl	m
Z
mZmZmZ dd	d
ZddddZdddZdddZdS )    )annotationsN)Sequence)datetime   )Usage__version__
calc_priceupdate_pricesreturnintc                   C  s   t t  dS )zRun the CLI.N)sysexit	cli_logic r   r   W/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/genai_prices/_cli.pycli   s   r   	args_listSequence[str] | Nonec                 C  sV  t jddt dt jd}|jdddd |jd	d
}|jdddd}|jdddd |jdddd |jddd |jdtdd |jdtdd |jdtdd |jdtdd |jd td!d |jd"td#d |jd$td%d |jd&d'd'd}|jd(d)d*d || }|j	rt
d+t  d,S |jdkrt|S |jd&krt|S |  d-S ).Nzgenai-priceszgenai-prices CLI vz3

Calculate prices for calling LLM inference APIs.
)progdescriptionformatter_classz	--version
store_truezShow version and exit)actionhelpcommand)destcalczCalculate prices.)r   r   model+zModel and optionally provider used: either just the model ID, e.g. "gpt-4o" or in format "<provider>:<model>" e.g. "openai:gpt-4o".)nargsr   z--update-pricesz/Whether to update the model prices from GitHub.z--timestampz]Timestamp of the request, in RFC 3339 format, if not provided, the current time will be used.)r   z--input-tokensz*Usage: Number of text input/prompt tokens.)typer   z--cache-write-tokensz-Usage: Number of tokens written to the cache.z--cache-read-tokensz,Usage: Number of tokens read from the cache.z--output-tokensz/Usage: Number of text output/completion tokens.z--input-audio-tokensz$Usage: Number of audio input tokens.z--cache-audio-read-tokensz2Usage: Number of audio tokens read from the cache.z--output-audio-tokensz%Usage: Number of output audio tokens.listzList providers and models.provider?z"Only list models for the provider.zgenai-prices r   r   )argparseArgumentParserr   RawTextHelpFormatteradd_argumentadd_subparsers
add_parserr   
parse_argsversionprintr   calc_priceslist_models
print_help)r   parser
subparserscalc_parserlist_parserargsr   r   r   r      sV   



r   r4   argparse.Namespacec              
   C  s<  t | j| j| j| j| j| j| jd}| jD ]}d }d|v r%|	dd\}}d }| j
r3tt| j
}| jr@t }|jdd t||||d}|jj}d|jjfd|jjpY|jjfd	t|jfd
|d uri|dnd fdd|j fdd|j fdd|j fg}|D ]\}	}
|
d urt|	dd|
  qtd qdS )N)input_tokenscache_write_tokenscache_read_tokensoutput_tokensinput_audio_tokenscache_audio_read_tokensoutput_audio_tokens:r   T)wait)	model_refprovider_idgenai_request_timestampProviderModelzModel PriceszContext Windowz,dzInput Price$zOutput PricezTotal Pricez>14:  r   )r   r6   r7   r8   r9   r:   r;   r<   r   split	timestamppydanticTypeAdapterr   validate_pythonr	   UpdatePricesstartr   context_windowr"   nameidstrmodel_priceinput_priceoutput_pricetotal_pricer,   )r4   usager   r@   rA   price_update
price_calcwoutputkeyvaluer   r   r   r-   F   sP   
	
	
r-   c                 C  s   ddl m} | jr'dd |D }| j|vr'td| jdt| tjd dS |D ]>}| jr5|j| jkr5q)t|j dt	|j
 d	 |j
D ] }td
|j d|j dd |jrbtd|j  qFtd qFq)dS )Nr   )	providersc                 S  s   h | ]}|j qS r   )rP   ).0pr   r   r   	<setcomp>w   s    zlist_models.<locals>.<setcomp>zError: provider z not found in )filez: (z models)z  r=   rF   )endrE   r   )datar]   r"   r,   sortedr   stderrrP   rO   lenmodels)r4   r]   provider_idsr"   r   r   r   r   r.   s   s"   
 

r.   )r
   r   )N)r   r   r
   r   )r4   r5   r
   r   )
__future__r   _annotationsr$   r   collections.abcr   r   rI   rF   r   r   r   r	   r   r   r-   r.   r   r   r   r   <module>   s    

4-