taskgen.base#

Functions

chat(system_prompt, user_prompt[, model, ...])

Performs a chat with the host's LLM model with system prompt, user prompt, model, verbose and kwargs Returns the output string res - system_prompt: String. Write in whatever you want the LLM to become. e.g. "You are a <purpose in life>" - user_prompt: String. The user input. Later, when we use it as a function, this is the function input - model: String. The LLM model to use for json generation - verbose: Boolean (default: False). Whether or not to print out the system prompt, user prompt, GPT response - host: String. The provider of the LLM - llm: User-made llm function. - Inputs: - system_prompt: String. Write in whatever you want the LLM to become. e.g. "You are a <purpose in life>" - user_prompt: String. The user input. Later, when we use it as a function, this is the function input - Output: - res: String. The response of the LLM call - **kwargs: Dict. Additional arguments for LLM chat.

check_datatype(field, key, data_type, **kwargs)

Ensures that output field of the key of JSON dictionary is of data_type Currently supports int, float, str, code, enum, lists, nested lists, dict, dict with keys Takes in **kwargs for the LLM model Returns corrected output field that matches the datatype

check_key(field, output_format, ...)

Check whether each key in dict, or elements in list of new_output_format is present in field, and whether they meet the right data type requirements, then convert field to the right data type If needed, calls LLM model with parameters **kwargs to correct the output format for improperly formatted list output_format is user-given output format at each level, new_output_format is with delimiters in keys, and angle brackets surrounding values If output_format is a string, decode escape characters, so that code can run Returns field that is converted to a dictionary if able to. Otherwise, raises Exception errors for missing keys or wrong output format.

convert_to_dict(field, keys, delimiter)

Converts the string field into a dictionary with keys by splitting on '{delimiter}{key}{delimiter}'

convert_to_list(field, **kwargs)

Converts the string field into a list using the LLM (with **kwargs) to list out elements line by line

llm_check(field, llm_check_msg, **kwargs)

Uses the LLM to check if the field adheres to the llm_check_msg.

parse_response_llm_check(res)

remove_unicode_escape(my_datatype)

Removes the unicode escape character from the ending string in my_datatype (can be nested)

strict_json(system_prompt, user_prompt, ...)

Ensures that OpenAI will always adhere to the desired output JSON format defined in output_format.

strict_output(system_prompt, user_prompt, ...)

Ensures that OpenAI will always adhere to the desired output JSON format defined in output_format.

strict_text(system_prompt, user_prompt, ...)

Ensures that OpenAI will always adhere to the desired output JSON format defined in output_format.

type_check_and_convert(field, key, ...)

wrap_with_angle_brackets(d, delimiter, ...)

Changes d to output_d by wrapping delimiters over the keys, and putting angle brackets on the values Also changes all mention of list after type: to array for better processing