CoolFace
Apppublic

SHUBHAMOS/meta-pytorch-hackathon

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes
environment.cpython-313.pyc105 linesDownload Raw Back to __pycache__
12U��ipF��6�%SrSSKJr SSKrSSKJrJr SSKJrJrJ	r	J3r4Jr SSKJ
r
JrJrJrJrJrJrJrJrJr /SQr/S	Q/S5Q/SQ/SQS
.rS\S'/SQ/SQ/SQ/SQS
.rS\S'SSSSS
.rS\S'SSSSS
.rS\S'SS S!.S"S#S$.S%.rS)S&jr"S'S(5rg)*u6SHUBHAMOS: AI Email Operations & Triage Environment7environment.py — EmailTriageEnv OpenEnv-compliant environment class8 9Implements:10  reset(task_config) → Observation11  step(action)       → (Observation, float, bool, dict)12  state()            → State13�)�annotationsN)�datetime�timezone)�Any�Dict�List�Optional�Tuple�)14�Action�15ActionType�Email�
EmailCategory�Observation�ObservationEmail�Priority�	Sentiment�State�StepInfo)16zalice.johnson@acmecorp.comzbob.smith@enterprise.iozsupport@bigclient.netzbilling@financeops.comzceo@urgentco.orgzinfo@spamblaster.bizznoreply@marketing.cloudzjames.t@retailpartner.comzhelpdesk@internal.corpzcarol.w@medicalgroup.org)zYou've won a $500 gift card!zURGENT: Claim your prize nowuFree iPhone — limited offeru#Make money from home — guaranteedzYour account has been selected!)zQuestion about your serviceszRequest for product informationzPartnership inquiryz$Media inquiry regarding your companyzHow do I get started?z(Can you help me understand your pricing?)u%Invoice discrepancy — please reviewzDouble charged on my accountzRefund request for order #44821u Payment failed — what do I do?zBilling error on last statementzI was overcharged this month)z,URGENT: Service outage affecting my businessu/Complete system failure — need immediate helpzCritical bug causing data lossu-Unacceptable service — legal action pendingu&Production down — customers impacted��spam�general_inquiry�
billing_issue�urgent_complaintzDict[EmailCategory, List[str]]�_SUBJECTS_BY_CATEGORY)z�Congratulations! You have been selected to receive a $500 gift card. Click here to claim your reward before it expires in 24 hours. No purchase necessary. Act now!z�We have a special offer just for you! Make $5000/week from the comfort of your home. No experience needed. Join thousands of successful members. Click to get started today!z�LIMITED TIME OFFER: You have been pre-approved for a FREE iPhone 15 Pro. Simply complete a short survey and the device will be shipped to your door. Claim now!z�Your email was randomly selected for our VIP program. As a VIP member you get access to exclusive deals, cash prizes, and luxury vacations. Join for free today!)aHello, I came across your company online and I'm interested in learning more about your product offerings. Could you please send me a product catalog and pricing information? I'm particularly interested in your enterprise solutions. Thank you for your time.z�Hi there, I'm evaluating potential vendors for our upcoming project and your company came highly recommended. I'd love to schedule a 30-minute call to discuss how you might be able to help us. What's your availability this week?z�I'm a journalist writing an article about innovation in your industry. I would love to get a quote from your team about recent developments. Could you connect me with your PR contact? Deadline is Friday.z�We are a small business looking to expand our operations and are interested in your services. Before we proceed, I have a few questions about your support model and SLA commitments. Can someone from your sales team reach out?z�Hello, I recently attended your webinar on digital transformation and had a few follow-up questions. Could you share the recording and slide deck? Also, I'd love to speak with a product specialist about implementation timelines.)z�I received my invoice for last month and I believe there is an error. I was charged $1,200 but my contract clearly states the monthly fee is $950. Can you please review and send a corrected invoice as soon as possible? Invoice #INV-2024-0892.z�I was double charged on March 15th. My bank statement shows two transactions of $299 from your company. Please refund one of these charges immediately. I can provide bank statement screenshots if needed. This needs to be resolved urgently.z�I would like to request a refund for my recent purchase (Order #44821). I was charged for a premium plan but I never actually used the service. Per your refund policy, I should be eligible for a full refund within 30 days. Please process this ASAP.z�My credit card payment failed but I was still charged. I now see a pending charge of $450 on my card but I never received a confirmation. Can you check your system and either confirm the payment was received or release the hold?z�There is a discrepancy on my account statement. I was on the $99/month plan but was charged $149 this cycle. I did not authorize any plan upgrade. Please revert this change and refund the difference of $50.)usOur production environment has been down for the past 2 hours and your support team has been completely unresponsive. This is causing significant financial losses for our company — approximately $10,000 per hour. We have 500+ customers impacted and I need an immediate response. If this isn't resolved in the next hour we will be forced to seek an emergency injunction.aAI am writing to formally complain about the catastrophic failure of your service last night. Our entire database was corrupted due to what appears to be a bug in your latest update. We lost 3 days worth of data that cannot be recovered. Our legal team is reviewing our options. I expect a formal response within 24 hours.aMCRITICAL: Your system has been sending duplicate notifications to all our users for the last 4 hours. Our customers are furious and several have already cancelled their subscriptions. I have escalated this internally to our CEO. Your on-call team needs to fix this immediately. I am requesting a full incident report within 48 hours.a0I have been waiting 3 weeks for my issue to be resolved and I am at the end of my patience. Every time I contact support I get a different answer. This is completely unacceptable for an enterprise customer paying $50,000/year. I am now involving our procurement department to review the contract renewal.�_BODIES_BY_CATEGORY�neutral�positive�negativezDict[EmailCategory, Sentiment]�_SENTIMENT_BY_CATEGORY�low�medium�highzDict[EmailCategory, Priority]�_PRIORITY_BY_CATEGORY�333333�?gffffff�?)r#r"皙�����?g�������?)r!r")rrc��[R"U5n/SQn/SQn/n[SSSSSS[RS9n[U5GH3nUR
X4SS	9SnUR[U5n	UR[U5n17UR[5nURSS185nURURUS--URUS-S--S
9n
U[;aP[Un[!UR#55n[!UR%55nUR
UUSS	9SnO	[&Un[(UnUR+[-SUS-S3U	U19UU
UUUS95 GM6 U$)zGGenerate a deterministic list of realistic emails using the given seed.r)r&gffffff�?r%g333333�?i��r�	r)�tzinfo)�weights�ki`	�<�)�minute�hour�email_�03d)�id�subject�body�sender�	timestamp�gt_category�gt_priority�	sentiment)�random�Randomrr�utc�range�choices�choicerr�_SENDERS�randint�replacer/r0�_PRIORITY_OVERRIDES�list�keys�valuesr$r �appendr)�count�seed�rng�20categoriesr+�emails�base_ts�i�categoryr4r5r6�offset_minutes�ts�opts�priority_labels�priority_weightsr9r:s                   �server/environment.py�_generate_emailsrWs���21�-�-��22�C�'g�J�$�G��F��t�Q��1�a��8�<�<�@�G�
�5�\��"%�+�+�j�Q�+�"O�PQ�"R���*�*�2�8�<�=���z�z�-�h�7�8�����H�%�����Q�23�3��
�_�_��>�>�N�R�$7�7�����2�!5�� :�:��24���*�*�&�x�0�D�"�4�9�9�;�/�O�#�D�K�K�M�2��$'�K�K��IY�]^�K�$_�`a�$b�K�/��9�K�5�h�?�	��
�
�e���!��C�y�!����� �#��	25�		�5�J�M�c�r�\rSrSrSrSSjrSSjrSSjrSSjrSSjr	SSjr26SS	jrSS27jrSSjr
Srg
)�EmailTriageEnv�a228SHUBHAMOS OpenEnv-compliant environment for email triage.29 30Usage:31    env = EmailTriageEnv()32    obs = env.reset(task_config)33    for _ in range(max_steps):34        action = agent.act(obs)35        obs, reward, done, info = env.step(action)36        if done:37            break38    final_state = env.state()39c��/UlSUlSUlSUlSUl/UlSUlSUlSUlSUl	g)NrF��)40�_emails�_step_count�41_max_steps�_done�
_total_reward�_action_history�_seed�_task_id�_initialized�_reward_engine��selfs rV�__init__�EmailTriageEnv.__init__�sO��$&��� !��� ��� ��42�$'���57�����43���
�"'���#��rXc���[URSS55Ul[URSS55n[URSS55Ul[	URSS55Ul[R"UR5 [X R5Ul	S	Ul44S45UlSUl/Ul
SUlUR5$)
ad46Reset the environment for a new episode.47 48Args:49    task_config: Dict with keys:50        - seed (int): random seed for reproducibility51        - email_count (int): number of emails to generate52        - max_steps (int): episode step limit53        - task_id (str, optional): "easy"/"medium"/"hard"54 55Returns:56    Observation: initial state visible to agent57rJ�*�email_countr.�	max_steps�2�task_id�easyrFr]T)�int�getrera�strrfr;rJrWr_r`rbrcrdrg�_build_observation)rj�task_configros   rV�reset�EmailTriageEnv.reset�s���������4�5��58��+�/�/�-��;�<���k�o�o�k�2�>�?����K�O�O�I�v�>�?��
�	���D�J�J��(��Z�Z�@��������59� ���!��� ����&�&�(�(rXc	�F�UR(d[S5eUR(a[S5eURU5up#SnU(aFUR	U5 UR60b&UR61R
XR5nOSnU=RS-
slU=RU-
sl	URRURURURUUUS.5 [SUR55nURUR:�nU=(d UUlUR!5n[#URURUUUURS9R%5nXtURU4$)	z�62Apply an action to the environment.63 64Args:65    action: Action object with action_type and email_id (+ optional payload)66 67Returns:68    (observation, reward, done, info)69zCall reset() before step()z5Episode is done. Call reset() to start a new episode.r]g{�G�z��r)�step�action_type�email_id�valid�error�rewardc3�@# �UHoR5v� M g7f)N)�is_processed��.0�es  rV�	<genexpr>�&EmailTriageEnv.step.<locals>.<genexpr>s���C�l��N�N�,�,�l�s�)r}r~rr��step_reward�done)rg�RuntimeErrorrb�_validate_action�_dispatch_actionrh�score_actionr_r`rcrdrHr}r~�allrarwr�70model_dump)	rj�actionr�	error_msgr��
all_processed�step_limit_reached�obs�infos	         rVr|�EmailTriageEnv.step�sv��� � ��;�<�<��:�:��V�W�W� �0�0��8�������!�!�&�)��"�"�.�"�1�1�>�>�v�|�|�T��$��	
���A������k�)��	
���#�#��$�$�!�-�-������!�
%71�	��C�d�l�l�C�C�
�!�-�-����@��"�8�&8��72��%�%�'����*�*��_�_���#����
73��*�,�	
�����T�1�1rXc���[[UR5[UR5URUR74URURURURS9$)u�75Return the complete internal state including ground truth labels.76Used by graders — never expose this to the agent during evaluation.77)rM�action_history�78step_countrpr��total_rewardrJrr)79rrEr_rdr`rarbrcrerfris rV�state�EmailTriageEnv.state.sY��80�����%��� 4� 4�5��'�'��o�o�����+�+�����M�M�	8182rXc��URUR5nUcSSURS34$UR5(aSSURS34$URS:XaURcgURS:XaUR83cgURS	:Xa-URbURR5(dg84g)z3Validate action target and required payload fields.FzEmail 'z' not found in inboxz3' is already processed (resolved/escalated/ignored)�classify_email)Fz(classify_email requires 'category' field�set_priority)Fz#set_priority requires 'level' field�draft_reply)Fz+draft_reply requires non-empty 'text' field)TN)�_find_emailr~r�r}rP�level�text�strip�rjr��emails   rVr��EmailTriageEnv._validate_action@s���� � ����1���=��G�F�O�O�#4�4H�I�I�I�������G�F�O�O�#4�4g�h�h�h����!1�1�f�o�o�6M�D�����/�F�L�L�4H�?�����.�F�K�K�4G�v�{�{�O`�O`�Ob�Ob�G�rXc��URUR5nUcgURS:XaURUlgURS:XaURUlgURS:XaSUlURUlgURS:XaSUl	gURS:XaSUl85gURS:XaSUlgg)	z(Mutate email state based on action type.Nr�r�r�T�
mark_resolved�escalate_email�ignore_email)r�r~r}rPr��priority�
reply_draftedr��86reply_text�resolved�	escalated�ignoredr�s   rVr��EmailTriageEnv._dispatch_actionUs���� � ����1���=�����!1�1�#�_�_�E�N�
�
�
�>�
1�#�\�\�E�N�
�
�
�=�
0�"&�E��%�{�{�E��
�
�
�?�
2�!�E�N�
�
�
�#3�
3�"�E�O�
�
�
�>�
1� �E�M�2rXc�R�URHnURU:XdMUs $ g)z#Find an email by ID or return None.N)r_r3)rjr~r�s   rVr��EmailTriageEnv._find_emailns&�����A��t�t�x�����rXc��/nURH�nUR[URURUR87URURURSSURURURURURURS95 M� [SUR55n[SUR55n[SUR55n[!UR5U-88U-89U-90nUR"S:�aUR$UR"-OSn['U[!UR5UUUUUR$UR"US	9	$)91z?Build the agent-facing Observation from current internal state.N��)r3r4r6r7r:�body_previewrPr�r�r�r�r�c3�J# �UHoR(dMSv� M g7f�rN)r�r�s  rVr��4EmailTriageEnv._build_observation.<locals>.<genexpr>�s���C��1�9293�Q�Q����#�	#c3�J# �UHoR(dMSv� M g7fr�)r�r�s  rVr�r��s���E��A���a�a��r�c3�J# �UHoR(dMSv� M g7fr�)r�r�s  rVr�r��s���A�|�!�y�y�A�A�|�r�rr])	rM�total_emails�
pending_count�resolved_count�escalated_count�
ignored_countr�rp�
elapsed_ratio)r_rHrr3r4r6r7r:r5rPr�r�r�r�r��sum�lenrar`r)rj�94obs_emailsr�r�r�r�r�r�s        rVrw�!EmailTriageEnv._build_observationusC���95����A����.��4�4��	�	��x�x��+�+��+�+��V�V�D�S�\�����������+�+��	�	��o�o�
�

�� �C����C�C���E����E�E���A�t�|�|�A�A�
��D�L�L�)�N�:�_�L�}�\�
�37�/�/�A�2E�D���t���.�3�	����T�\�\�*�'�)�+�'��'�'��o�o�'�969798	99rXc��Xlg)zQAttach a reward engine (called by Phase 2). engine must implement score_action().N)rh)rj�engines  rV�attach_reward_engine�#EmailTriageEnv.attach_reward_engine�s��$�rX)100rdrbr_rgrarhrer`rfrcN)�return�None)rxzDict[str, Any]r�r)r�rr�z/Tuple[Observation, float, bool, Dict[str, Any]])r�r)r�rr�zTuple[bool, Optional[str]])r�rr�r�)r~rvr�zOptional[Email])r�r)r�rr�r�)�__name__�101__module__�__qualname__�__firstlineno__�__doc__rkryr|r�r�r�r�rwr��__static_attributes__�rXrVrZrZ�s7���#� )�@;2�z102�$�*!�2�&103�P%rXrZ)rIrtrJrtr�zList[Email]) r��104__future__rr;rr�typingrrrr	r105�modelsrr
rrrrrrrrrAr�__annotations__rr r$rDrWrZr�rXrV�<module>r�s����#�
�'�3�3������
����19��5��D
����+7��3��<
�!��"�	:��6��
����	8��4��"�S�1�"�c�2���0�fm%�m%rX