plexus.scores.CompositeScore module
- class plexus.scores.CompositeScore.CompositeScore(**parameters)
Bases:
Score
A composite score is a score that is composed of multiple elements, each of which is a score. This class handles the work of computing the values of each individual element and then combining them into a single composite score. It also handles the work of computing the costs of the individual elements and the composite score.
Initializes a new instance of the CompositeScore class.
This constructor sets up the initial state of the CompositeScore object, including initializing token accumulators for tracking API usage costs and preparing the list to store individual element results.
- __init__(**parameters)
Initializes a new instance of the CompositeScore class.
This constructor sets up the initial state of the CompositeScore object, including initializing token accumulators for tracking API usage costs and preparing the list to store individual element results.
- break_text_into_chunks(text, max_chunk_size=2000)
- compute_element(*, name, text=None)
Compute the result for a single element of the composite score by processing the filtered text in chunks and aggregating the results.
- Args:
name (str): The name of the element to compute the score for. text (str, optional): The text text to use for computing the score.
- Returns:
A boolean value that indicates whether the score result was “Yes” or not.
- abstract compute_element_for_chunk(*, name, element_type, previous_messages=None, prompt, chunk)
The orchestration framework in CompositeScore calls this function to do the work specific to a composite score element.
This method must be implemented by subclasses.
- compute_explanation_and_relevant_quote()
- compute_result(*, tree=None)
- concatenate_chat_history(selected_results)
- abstract construct_system_prompt(*, text)
Defines the system prompt used at the start of the chat history. This system prompt includes minimal, basic instructions, and the text.
- classmethod create_from_markdown(*, scorecard, score_name, markdown_file_path)
- classmethod extract_yaml_section(markdown_content, section_name)
- filtered_text_is_empty()
A common decision used at the start of decision trees. If the filtered text is blank then it means that nothing in the text was judged to be relevant to the classification, and we can skip any further processing for that chunk.
- get_accumulated_costs()
Get the expenses that have been accumulated over all the computed elements.
- Returns:
- dict: A dictionary containing the accumulated expenses:
‘llm_request_count’, ‘prompt_tokens’, ‘completion_tokens’, ‘input_cost’, ‘output_cost’, ‘total_cost’
- get_element_by_name(*, name)
Get the element by name from the list of elements or a function pointer if the name matches a whitelist of allowed function names. If the name does not match an element or an allowed function name, return None.
- Args:
name (str): The name of the element to retrieve from the composite score’s elements or the name of the function.
- Returns:
dict or function or None: The element dictionary if an element with the given name exists, a function pointer if a valid function name is specified and found, or None if no match is found.
- get_total_token_count(chat_history)
- group_element_results_by_name()
- classmethod load_results_from_json(session_id, input_directory_path)
- multiple(ordered_results)
- na()
A shorthand function for returning a ‘NA’ score result, with the element results for the individual elements of the composite score. This helps keep the code minimal in the concrete implementations.
- no()
A shorthand function for returning a ‘No’ score result, with the element results for the individual elements of the composite score. This helps keep the code minimal in the concrete implementations.
- static normalize_element_name(name)
- return_result_with_context(*, value, result_index=0, **kwargs)
- save_results_to_json(session_id, output_directory_path)
- select_element_results_to_include(grouped_results)
- to_dict()
- yes()
A shorthand function for returning a ‘Yes’ score result, with the element results for the individual elements of the composite score. This helps keep the code minimal in the concrete implementations.