MCPcopy
hub / github.com/openai/evals / try_cast_from_str

Function try_cast_from_str

evals/elsuite/bugged_tools/utils.py:64–82  ·  view source on GitHub ↗

Given string n, cast to specified type and return. Warns and returns None if this fails

(n: str, cast_type: type)

Source from the content-addressed store, hash-verified

62
63
64def try_cast_from_str(n: str, cast_type: type):
65 """
66 Given string n, cast to specified type and return. Warns and returns None
67 if this fails
68 """
69 if cast_type not in (str, int, float, list):
70 return None
71
72 try:
73 if cast_type == str:
74 return str(n)
75 elif cast_type == int:
76 return int(n)
77 elif cast_type == float:
78 return float(n)
79 elif cast_type == list:
80 return ast.literal_eval(n)
81 except (ValueError, SyntaxError, TypeError, MemoryError, RecursionError):
82 return None

Callers 15

strip_and_castMethod · 0.90
__call__Method · 0.90
__call__Method · 0.90
__call__Method · 0.90
__call__Method · 0.90
__call__Method · 0.90
__call__Method · 0.90
__call__Method · 0.90
__call__Method · 0.90
__call__Method · 0.90
__call__Method · 0.90
__call__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…