MCPcopy Create free account
hub / github.com/OpenSparseLLMs/MoM / serialize_function

Method serialize_function

lm-eval-harness/lm_eval/api/task.py:148–162  ·  view source on GitHub ↗

Serializes a given function or string. If 'keep_callable' is True, the original callable is returned. Otherwise, attempts to return the source code of the callable using 'getsource'.

(
        self, value: Union[Callable, str], keep_callable=False
    )

Source from the content-addressed store, hash-verified

146 return cfg_dict
147
148 def serialize_function(
149 self, value: Union[Callable, str], keep_callable=False
150 ) -> Union[Callable, str]:
151 """Serializes a given function or string.
152
153 If 'keep_callable' is True, the original callable is returned.
154 Otherwise, attempts to return the source code of the callable using 'getsource'.
155 """
156 if keep_callable:
157 return value
158 else:
159 try:
160 return getsource(value)
161 except (TypeError, OSError):
162 return str(value)
163
164
165class Task(abc.ABC):

Callers 1

to_dictMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected