core.history_exporter

DataFrame export and persistence for FFAI interaction histories.

DataFrame export and persistence for FFAI interaction histories.

class HistoryExporter(history, clean_history, prompt_attr_history, ordered_history, persist_dir, persist_name=None, auto_persist=False)[source]

Bases: object

DataFrame export and persistence for FFAI interaction histories.

Converts the various history stores into Polars DataFrames and handles persistence to Parquet files.

Parameters:
  • history (list[dict[str, Any]]) – Raw interaction history list.

  • clean_history (list[dict[str, Any]]) – Cleaned interaction history list.

  • prompt_attr_history (list[dict[str, Any]]) – Prompt-attribute-indexed history list.

  • ordered_history (Any) – OrderedPromptHistory instance.

  • persist_dir (str) – Directory for persisted files.

  • persist_name (str | None) – Base name for persisted files.

  • auto_persist (bool) – Whether to auto-persist DataFrames on creation.

history_to_dataframe()[source]

Convert the full interaction history to a polars DataFrame.

Return type:

DataFrame

clean_history_to_dataframe()[source]

Convert the clean interaction history to a polars DataFrame.

Return type:

DataFrame

prompt_attr_history_to_dataframe()[source]

Convert the prompt attribute history to a polars DataFrame.

Return type:

DataFrame

ordered_history_to_dataframe()[source]

Convert the ordered interaction history to a polars DataFrame.

Return type:

DataFrame

search_history(text=None, prompt_name=None, model=None, start_time=None, end_time=None)[source]

Search interaction history with flexible filtering options.

Parameters:
  • text (str | None) – Text to search for in prompts and responses

  • prompt_name (str | None) – Filter by prompt name

  • model (str | None) – Filter by model name

  • start_time (float | None) – Filter by timestamp (start time in epoch seconds)

  • end_time (float | None) – Filter by timestamp (end time in epoch seconds)

Returns:

Filtered dataframe of interactions

Return type:

pl.DataFrame

get_model_stats_df(model_usage_stats)[source]

Get statistics on model usage as a DataFrame.

Parameters:

model_usage_stats (dict[str, int]) – Pre-computed model usage stats dict.

Returns:

DataFrame with model usage statistics

Return type:

pl.DataFrame

get_prompt_name_stats_df(prompt_name_stats)[source]

Get statistics on prompt name usage as a DataFrame.

Parameters:

prompt_name_stats (dict[str, int]) – Pre-computed prompt name stats dict.

Returns:

DataFrame with prompt name usage statistics

Return type:

pl.DataFrame

get_response_length_stats()[source]

Get statistics on response lengths by prompt name.

Returns:

DataFrame with response length statistics by prompt name

Return type:

pl.DataFrame

interaction_counts_by_date()[source]

Get counts of interactions grouped by date.

Returns:

DataFrame with interaction counts by date

Return type:

pl.DataFrame

persist_all_histories()[source]

Persist all histories to Parquet files in the configured directory.

Return type:

bool

Classes

class HistoryExporter(history, clean_history, prompt_attr_history, ordered_history, persist_dir, persist_name=None, auto_persist=False)[source]

Bases: object

DataFrame export and persistence for FFAI interaction histories.

Converts the various history stores into Polars DataFrames and handles persistence to Parquet files.

Parameters:
  • history (list[dict[str, Any]]) – Raw interaction history list.

  • clean_history (list[dict[str, Any]]) – Cleaned interaction history list.

  • prompt_attr_history (list[dict[str, Any]]) – Prompt-attribute-indexed history list.

  • ordered_history (Any) – OrderedPromptHistory instance.

  • persist_dir (str) – Directory for persisted files.

  • persist_name (str | None) – Base name for persisted files.

  • auto_persist (bool) – Whether to auto-persist DataFrames on creation.

history_to_dataframe()[source]

Convert the full interaction history to a polars DataFrame.

Return type:

DataFrame

clean_history_to_dataframe()[source]

Convert the clean interaction history to a polars DataFrame.

Return type:

DataFrame

prompt_attr_history_to_dataframe()[source]

Convert the prompt attribute history to a polars DataFrame.

Return type:

DataFrame

ordered_history_to_dataframe()[source]

Convert the ordered interaction history to a polars DataFrame.

Return type:

DataFrame

search_history(text=None, prompt_name=None, model=None, start_time=None, end_time=None)[source]

Search interaction history with flexible filtering options.

Parameters:
  • text (str | None) – Text to search for in prompts and responses

  • prompt_name (str | None) – Filter by prompt name

  • model (str | None) – Filter by model name

  • start_time (float | None) – Filter by timestamp (start time in epoch seconds)

  • end_time (float | None) – Filter by timestamp (end time in epoch seconds)

Returns:

Filtered dataframe of interactions

Return type:

pl.DataFrame

get_model_stats_df(model_usage_stats)[source]

Get statistics on model usage as a DataFrame.

Parameters:

model_usage_stats (dict[str, int]) – Pre-computed model usage stats dict.

Returns:

DataFrame with model usage statistics

Return type:

pl.DataFrame

get_prompt_name_stats_df(prompt_name_stats)[source]

Get statistics on prompt name usage as a DataFrame.

Parameters:

prompt_name_stats (dict[str, int]) – Pre-computed prompt name stats dict.

Returns:

DataFrame with prompt name usage statistics

Return type:

pl.DataFrame

get_response_length_stats()[source]

Get statistics on response lengths by prompt name.

Returns:

DataFrame with response length statistics by prompt name

Return type:

pl.DataFrame

interaction_counts_by_date()[source]

Get counts of interactions grouped by date.

Returns:

DataFrame with interaction counts by date

Return type:

pl.DataFrame

persist_all_histories()[source]

Persist all histories to Parquet files in the configured directory.

Return type:

bool