CoolFace
Apppublic

cathub/LocalChatGPT

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

2/�d�	�@sXddlZddlZddlmZmZmZmZmZmZddl	m3Z4ddlZdd�Zdd�Z
dS)�N)�timeout_all�BALANCE_API_URL�standard_error_msg�connection_timeout_prompt�error_retrieve_prompt�read_timeout_prompt)�sharedcCs�dd|��d�}t}tj�d�p*tj�d�}tj�d�pBtj�d�}i}|rdt�d|���||d	<|r�t�d5|���||d<|r�tjt|||d�}ntjt||d
�}|S)Nzapplication/jsonzBearer )zContent-Type�
Authorization�6HTTP_PROXY�7http_proxy�HTTPS_PROXY�https_proxyu使用 HTTP 代理: �httpu使用 HTTPS 代理: �https)�headers�timeout�proxies)rr)r�os�environ�get�logging�info�requestsr)�openai_api_keyrrrr
r�response�r�L/Users/treediagram/Documents/Developer/ChuanhuChatGPT/modules/openai_func.py�get_usage_responses<��8���rc9Csz�t|d�}t�|���zD|���d�r8|���d�nd}|���d�rX|���d�nd}Wn>ty�}z&t�dt|��d}d}WYd}~n10d}~00d|�d|�d�WStj	j11y�ttt
}|YStj	j�y�ttt
}|YS0dS)	N)rZtotal_availabler�12total_useduAPI使用情况解析失败:u)**API使用情况**(已用/余额) z$ / �$)rr�debug�jsonr�	Exception�error�strr�13exceptions�ConnectTimeoutrrr�ReadTimeoutr)rrZbalancer�e�status_textrrr�	get_usage3s214����r*)rr�modules.presetsrrrrrr�modulesrrrr*rrrr�<module>s +