Team Ai
Apppublic

openenv/coding_env

sourceHugging Faceupdated 3mo agoView on Hugging Face
21likes
interfaces.cpython-313.pyc61 linesDownload Raw Back to __pycache__
1�

2���h����SSKJrJr SSKJrJrJr SSKJrJ	r	J3r4 "SS\5r"SS\5r"S	S5\5r
"SS\5rg
)�)�ABC�abstractmethod)�Any�Protocol�	TypedDict�)�Action�Observation�Statec�.�\rSrSr%Sr\\S'\\S'Srg)�Message�
zPA message in a conversation.6 7Compatible with Huggingface chat template format.8�role�content�N)�__name__�9__module__�__qualname__�__firstlineno__�__doc__�str�__annotations__�__static_attributes__r��C/Users/zwentz/Development/OpenEnv/src/core/env_server/interfaces.pyr
r

s���10�I�
�Lrr
c�j�\rSrSrSrSS\\S\S\S-S\	S\	411S	jjr12SS13\	S\S\	S\4SjjrS
rg)�ModelTokenizer�z�Protocol for tokenizers that support chat templates.14 15This protocol defines the interface that tokenizers must implement16to work with chat-based environments. It's compatible with17Huggingface transformers tokenizers.18N�conversation�tokenize�return_tensors�kwargs�returnc��g)aiApply a chat template to format and optionally tokenize a conversation.19 20Args:21    conversation: List of message dictionaries with 'role' and 'content'22    tokenize: Whether to tokenize the output23    return_tensors: Format for returned tensors ('pt' for PyTorch)24    **kwargs: Additional arguments25 26Returns:27    Formatted and optionally tokenized conversation28Nr)�selfrr r!r"s     r�apply_chat_template�"ModelTokenizer.apply_chat_templates��$	r�	token_ids�skip_special_tokensc��g)z�Decode token IDs back to text.29 30Args:31    token_ids: Token IDs to decode32    skip_special_tokens: Whether to skip special tokens in output33    **kwargs: Additional arguments34 35Returns:36    Decoded text string37Nr)r%r(r)r"s    r�decode�ModelTokenizer.decode3s��	rr)TN)F)
rrrrr�listr
�boolrrr&r+rrrrrrs|����%)�	��7�m�����d�38�	�39��40
�
�*;@�
��
�37�
�KN�
�	�
�
rrc�4�\rSrSrSr\S\S\4Sj5rSrg)�	Transform�Ca	Transform observations to add rewards, metrics, or other modifications.41 42Transforms follow the TorchRL pattern where they take an observation43and return a (potentially modified) observation. This allows for44flexible reward computation and observation augmentation.45�observationr#c��g)zrTransform an observation.46 47Args:48    observation: The input observation49 50Returns:51    The transformed observation52Nr�r%r2s  r�__call__�Transform.__call__Ks��	
rrN)	rrrrrrr53r5rrrrr0r0Cs)����	
�K�	
�K�	
��	
rr0c��\rSrSrSrSS\S-4Sjjr\S\4Sj5r	\S\54S\4S	j5r\\S\
4S55j55rS\S\4SjrS
rg)�Environment�Xz�Base class for all environment servers following Gym/Gymnasium API.56 57Args:58    transform: Optional transform to apply to observations59N�	transformc��Xlg�N�r:)r%r:s  r�__init__�Environment.__init___s��"�rr#c��g)z5Reset the environment and return initial observation.Nr�r%s r�reset�Environment.resetb���	
r�actionc��g)zTake a step in the environment.Nr)r%rEs  r�step�Environment.stepgrDrc��g)z"Get the current environment state.NrrAs r�state�Environment.statels��	
rr2c�B�URbURU5$U$)z#Apply transform if one is provided.r=r4s  r�_apply_transform�Environment._apply_transformrs!���>�>�%��>�>�+�.�.��rr=r<)rrrrrr0r>rr60rBr	rG�propertyrrJrMrrrrr8r8Xs����#�)�d�"2�#��
�{�
��
��
�6�
�k�
��
���
�u�
���
��K��K�rr8N)�abcrr�typingrrr�typesr	r61rr
rr0r8rrr�<module>rSsG��$�+�+�-�-��i��)�X�)�X
��
�*�#�r