CoolFace
Apppublic

yuviertdh/promptshieldenv

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
main.cpython-314.pyc28 linesDownload Raw Back to __pycache__
1+
2�2�i���|�Rt^RIHtHt^RIt^RIHt^RIHtH	t	]!RR7t3]!4t]4PR]R7R	4t
]5PR64RRl4t]7PR
4R4t]8PR4R4t]9PR4R4t]10PR4R4tR#)z*11FastAPI application for PromptShieldEnv.12)�FastAPI�
HTTPExceptionN)�PromptShieldEnvironment)�Observation�ActionzPromptShieldEnv API)�titlez/reset)�response_modelc��6"�\P4pV#5i)z7Starts a new episode and returns the first observation.)�env�reset)�obss �,E:\New folder\AI 2.0\promptshieldenv\main.py�	reset_envr
s����)�)�+�C��J�s�z/stepc�$�V^8�dQhR\/#)��action)r)�formats"r
�__annotate__rs����6��c��j"�\PVP44wrr4RVRVRVRV/#5i)zNTakes an action and returns the next observation, reward, done flag, and info.�observation�reward�done�info)r13�step�14model_dump)rrrrrs&    r
�step_envrsA���"�h�h�v�'8�'8�':�;��C���s��&�����	��s�13z/statec��2"�\P4#5i)z"Returns current environment state.)r15�state�rr
�	get_stater s����9�9�;��s�z/tasksc��Z"�RRRRR/RRRR/RRRR	/.R16\P!4/#5i)z(Returns list of tasks and action schema.�tasks�name�direct_injection_detection�17difficulty�easy�indirect_and_hidden_attacks�medium�jailbreak_and_adversarial�hard�
action_schema)r�model_json_schemarrr
�	get_tasksr-#sP���	�
�1�<��H�
�2�L�(�K�
�0�,��G�18�19	��1�1�3�
��s�)+z/graderc��"�\P4pVR,'g\RRR7h\P4pV#5i)z-Returns grader scores after the episode ends.�is_donei�z Episode not finished completely.��status_code�detail)r20rr�evaluate_grader)r�scoress  r
�21get_graderr5/s>���
�I�I�K�E�������4V�W�W�
�
 �
 �
"�F��M�s�AA	z	/baselinec���"�^RIpRpVPV4GRjx�L22pRVP/#L \Pd p\RRTP2R7hRp?ii;i5i)zTRuns the baseline agent and returns the scores by shelling out in a separate thread.Nc�:�\P!RR.RRRR7#)z2C:\Users\Admin\AppData\Local\Python\bin\python.exezinference.pyT)�capture_output�text�check)�23subprocess�runrrr
�
run_inference�,run_baseline_endpoint.<locals>.run_inference=s$���~�~�
B�N�S����	24�	25r�outputi�zBaseline failed: r0)�asyncio�	to_thread�stdoutr;�CalledProcessErrorr�stderr)r@r=�result�es    r
�run_baseline_endpointrG8sl����26�T��(�(��7�7���&�-�-�(�(�8���(�(�T���6G����z�4R�S�S��T�s1�A+�4�2�4�A+�4�A(�	A#�#A(�(A+)�__doc__�fastapirrr;�environmentr�modelsrr�appr27�postrr�getr r-r5rGrrr
�<module>rOs����+��/�&�
�)�*��������(�;��/��0��28���'������������������	��	����)��������+��T��Tr