agent_studio.utils.json_utils#

Module Contents#

Functions#

read_jsonl(→ list)

Reads lines from a .jsonl file between start_idx and end_idx.

add_jsonl(data, file_path[, mode])

Adds a list of dictionaries to a .jsonl file.

read_json(→ dict)

Reads a dictionary from a .json file.

format_json(data[, indent, sort_keys])

Prints a dictionary in a formatted way.

export_trajectories(→ None)

Exports the trajectory data to a .jsonl file.

save_image_or_array(→ str)

parse_and_save_objects(→ Any)

agent_studio.utils.json_utils.read_jsonl(file_path: str, start_idx: int = 0, end_idx: int | None = None) list[source]#

Reads lines from a .jsonl file between start_idx and end_idx.

Parameters:
  • file_path (str) – Path to the .jsonl file

  • start_idx (int, optional) – The starting index of lines to read

  • end_idx (int | None, optional) – The ending index of lines to read

Returns:

A list of dictionaries, each dictionary is a line from

the .jsonl file

Return type:

list[dict]

agent_studio.utils.json_utils.add_jsonl(data: list, file_path: str, mode='a')[source]#

Adds a list of dictionaries to a .jsonl file.

Parameters:
  • data (list[dict]) – A list of json objects to add to the file

  • file_path (str) – Path to the .jsonl file

agent_studio.utils.json_utils.read_json(file_path: str) dict[source]#

Reads a dictionary from a .json file.

Parameters:

file_path (str) – Path to the .json file

Returns:

The dictionary read from the file

Return type:

dict

agent_studio.utils.json_utils.format_json(data: dict, indent=4, sort_keys=False)[source]#

Prints a dictionary in a formatted way.

Parameters:

data (dict) – The dictionary to print

agent_studio.utils.json_utils.export_trajectories(self_eval_results: dict | None, task_config: dict, trajectory: list, record_path: str, score: float | None, feedback: str | None, token_count: int | None, video_meta: dict | None = None, jsonl_name: str = 'results.jsonl') None[source]#

Exports the trajectory data to a .jsonl file.

agent_studio.utils.json_utils.save_image_or_array(obj: Any, folder_path: str) str[source]#
agent_studio.utils.json_utils.parse_and_save_objects(obj: Any, folder_path: str) Any[source]#