CoolFace
Apppublic

Dwild/ChuanhuChatGPT

sourceHugging Facegpl-3.0updated 3y agoView on Hugging Face
0likes
openai_func.cpython-39.pyc17 linesDownload Raw Back to __pycache__
1a

2u+,dK	�@sxddlZddlZddlmZmZmZmZmZmZm	Z	ddl3mZddlm
Z
ddlZddlZdd�Zdd	�Zd4d�ZdS)�N)�timeout_all�
USAGE_API_URL�BALANCE_API_URL�standard_error_msg�connection_timeout_prompt�error_retrieve_prompt�read_timeout_prompt�)�shared)�retrieve_proxycCs|dd|��d�}t}t�� tj|||d�}Wd�n1s@0Y|jdkr`|��}|Std|j�d|j����dS)Nzapplication/jsonzBearer )zContent-Type�
Authorization)�headers�timeout��z$API request failed with status code z: )rr�requests�get�status_code�json�	Exception�text)�openai_api_keyZbilling_urlr
r�response�data�r�L/Users/treediagram/Documents/Developer/ChuanhuChatGPT/modules/openai_func.py�get_billing_datas��$5rc	6Cs<z�tj��}t|��d�}|jdd��d�}tjj�d|�d|��}zt||�}Wn<t	y�}z$t7�dt|��dWYd}~WSd}~00d�
|d	d8�}d|��WStjjy�ttt}|YStjj�y�ttt}|YSt	�y6}z&t9�dt|��ttWYd}~Sd}~00dS)Nz%Y-%m-%dr	��dayz?start_date=z10&end_date=u获取API使用情况失败:u**获取API使用情况失败**z{:.5f}Ztotal_usage�du**本月使用金额**   $)�datetime�now�get_last_day_of_month�strftime�replacer11�state�
usage_api_urlrr�logging�error�str�formatr�12exceptions�ConnectTimeoutrrr�ReadTimeoutr)	rZ	curr_timeZlast_day_of_monthZfirst_day_of_monthZ	usage_urlZ13usage_data�eZ
rounded_usage�status_textrrr�	get_usage&s*14r/cCs*|jdd�tjdd�}|tj|jd�S)N�r�)�days)r#r�	timedeltar)Zany_dayZ15next_monthrrrr!=sr!)rr&�modules.presetsrrrrrrr�r16�modules.configr�osrrr/r!rrrr�<module>s$17