opto.trace.utils¶
global_functions_list
module-attribute
¶
parse_eqs_to_dict ¶
Parse the text of equations into a dictionary
Example:
x0 = 1
x1=2
x2=2
x3= def fun():\n print('hello')\n
abc_test1=test
would be parsed into
{'x0': '1', 'x1': '2', 'x2': '2', 'x3': "def fun():\nprint('hello')", 'abc_test1': 'test'}
render_opt_step ¶
escape_json_nested_quotes ¶
Escapes double quotation marks inside JSON string values for a specific format: {"name": "string value", "value": "string value"} Does not escape quotes around keys or structural quotes.
Warning: Here are what this function does not do: 1. Cannot handle "\n" or "\t" type of strings 2. Does not check if "\n", "\t", or other control characters are properly escaped. Please use json_str.replace("\n", "\n") to escape control characters outside of this function.
Example usage can be found in optimizers/textgrad.py.
Args: json_str (str): A string representation of JSON with exactly two keys: name and value.
Returns: str: JSON string with properly escaped quotes in values.
dedent ¶
A better dedent than dedent from textwrap module. Remove leading and trailing whitespace for each line For example:
The output will be : This allows writing cleaner multiline prompts in the code.