Team Ai
Apppublic

Yash030/claude-code-proxy

sourceHugging Faceupdated 5mo agoView on Hugging Face
2likes
detection.cpython-314.pyc63 linesDownload Raw Back to __pycache__
1+
2b�j���j�Rt^RIHt^RIHtRRltRRltRRltR	R3ltRRlt	R
Rlt4R#)z�Request detection utilities for API optimizations.5 6Detects quota checks, title generation, prefix detection, suggestion mode,7and filepath extraction requests to enable fast-path responses.8)�extract_text_from_content)�MessagesRequestc�R�V^8�dQhR\R\\\3,/#���request_data�return�r�tuple�bool�str)�formats"�8C:\Users\yashw\.claude\claude-code-free\api\detection.py�__annotate__rs#����/��e�D�#�I�>N��c��a�VP^8wdR#\VP4^8wdR#VP^,pVPR8wdR#\	VP94pVP
4P4o\S4^28dQSR9dRRV23#\;QJdV3RlR4F'gKRM	RM!V3RlR44'dR	#R#)10z�Detect trivial requests that can be fast-pathed.11 12Returns (is_trivial, text_content) for trivial requests that only need13a simple acknowledgment or echo response.14F�userTzOK. c3�,<"�TF	qS9x�K	R#5i)N�)�.0�kw�15text_lowers& �r�	<genexpr>�*is_trivial_text_request.<locals>.<genexpr>%s����R�*Q�B�Z��*Q�s��F�)�hi�hello�ok�thanksz	thank you�yes�no�okay)�status�health�pingzare you)Tz16I'm ready.)	�17max_tokens�len�messages�roler�content�lower�strip�any)r�msg�textrs&  @r�is_trivial_text_requestr0s�������!�#���18�<� � �!�Q�&���19�20�21��22"�C�23�x�x�6����$�S�[�[�1�D�����#�#�%�J��:�����Z�Z��4��v��&�&��3�R�*Q�R�3�3�3�R�*Q�R�R�R�%�%��rc�0�V^8�dQhR\R\/#r�rr)r
s"rrr+s������T�rc��VP^8Xdz\VP4^8Xd`VP^,PR8Xd>\	VP^,P244pRVP
49dR#R#)z�Check if this is a quota probe request.25 26Quota checks are typically simple requests with max_tokens=127and a single message containing the word "quota".28r�quotaTF)r&r'r(r)rr*r+)rr/s& r�is_quota_check_requestr5+sm��	���1�$���%�%�&�!�+��!�!�!�$�)�)�V�3�(��)>�)>�q�)A�)I�)I�J���d�j�j�l�"��rc�0�V^8�dQhR\R\/#rr2)r
s"rrr<s����o��$�rc��VP'dVP'dR#\VP4P4pRV9dR#RV9;'g-RV9;'d RV9;'dRV9;'gRV9#)a Check if this is a conversation title generation request.29 30Title generation requests are detected by a system prompt containing31title extraction instructions, no tools, and a single user message.32 33Matches Claude Code session title prompts (sentence-case title, JSON34"title" field, etc.).35F�titlezsentence-case titlezreturn json�fieldzcoding sessionzthis session)�system�toolsrr+)r�system_texts& r�is_title_generation_requestr=<s�������,�"4�"4�"4��+�L�,?�,?�@�F�F�H�K��k�!�� �K�/�����$�	O�	O��{�"�	O�	O�
��
,�
M�
M��+�0M�rc�R�V^8�dQhR\R\\\3,/#rr	)r
s"rrrQs#����o��%��c�	�BR�rc�|�\VP4^8wg#VP^,PR8wdR#\VP^,P4pRV9d>RV9d7VPR4\R4,pRWRP
43#R# \dRu#i;i)z�Check if this is a fast prefix detection request.36 37Prefix detection requests contain a policy_spec block and38a Command: section for extracting shell command prefixes.39 40Returns:41    Tuple of (is_prefix_request, command_string)42rz
<policy_spec>�Command:TNr)r'r(r)rr*�rfindr,�	TypeError)rr*�	cmd_starts&  r�is_prefix_detection_requestrDQs����<� � �!�Q�&�,�*?�*?��*B�*G�*G�6�*Q���'��(=�(=�a�(@�(H�(H�I�G��'�!�j�G�&;�	��
�
�j�1�C�43�O�C�I����,�2�2�4�4�4�����	���	�s�44B+�+
B;�:B;c�0�V^8�dQhR\R\/#rr2)r
s"rrris����_���rc��VPF5pVPR8XgK\VP4pRV9gK4R#	R#)z�Check if this is a suggestion mode request.44 45Suggestion mode requests contain "[SUGGESTION MODE:" in the user's message,46used for auto-suggesting what the user might type next.47rz[SUGGESTION MODE:TF)r(r)rr*)rr.r/s&  r�is_suggestion_mode_requestrGis>���$�$���8�8�v��,�S�[�[�9�D�"�d�*��	%�48rc�\�V^8�dQhR\R\\\\3,/#rr	)r
s"rrrws'��0!�0!�!�0!�49�4��c�>��0!rc��\VP4^8wg#VP^,PR8wdR#VP'dR#\	VP^,P504pRV9gRV9dR#RVP
49;'gRVP
49pVP'd\	VP4MRpRVP
49;'gRVP
49pV'gV'gR#VPR4\R4,pVPRV4pVR8XdR#WVP4pW\R4,R	P4pR
F1p	W�9gKVPV	4^,P4pK3	R51Wx3#)aCheck if this is a filepath extraction request.52 53Filepath extraction requests have a single user message with54"Command:" and "Output:" sections, asking to extract file paths55from command output.56 57Returns:58    Tuple of (is_filepath_request, command, output)59rrr@zOutput:�	filepathsz<filepaths>zextract any file pathszfile paths that this commandNT)Frr�����)�<z60 61)r'r(r)r;rr*r+r:�findr,�split)62rr*�user_has_filepathsr<�system_has_extractrC�
output_marker�command�output�markers63&         r�is_filepath_extraction_requestrUws����<� � �!�Q�&�,�*?�*?��*B�*G�*G�6�*Q���������'��(=�(=�a�(@�(H�(H�I�G��� �I�W�$<���	�w�}�}��&�J�J�-�7�=�=�?�*J��;G�:M�:M�:M�!�,�"5�"5�6�SU��	!�K�$5�$5�$7�7�	A�	A�)�[�->�->�-@�@���&8������Z�(�3�z�?�:�I��L�L��I�6�M�������
�.�4�4�6�G�
�S��^�3�5�
6�
<�
<�
>�F������\�\�&�)�!�,�2�2�4�F� ��� � rN)�__doc__�core.anthropicr�models.anthropicrr0r5r=rDrGrUrrr�<module>rYs0���5�-��>�"�*�0�0!r