def create_html_log(
    *,
    model: language_model.LanguageModel,
    primary_environment: game_master.GameMaster,
    secondary_environments: Sequence[game_master.GameMaster],
    summarize_entire_episode: bool = True,
) -> str:
  """Create an HTML log of the simulation.

  Args:
    model: The language model to use.
    primary_environment: The main game master.
    secondary_environments: Sequence of secondary game masters.
    summarize_entire_episode: Optionally, summarize the entire episode. This may
      load a lot of tokens into a language model all at once and in some cases
      exceed the model's context window and cause it to crash.

  Returns:
    An HTML string log of the simulation.
  """
  primary_gm_memories = primary_environment.get_memory().retrieve_recent(
      k=10000, add_time=True
  )

  if summarize_entire_episode:
    detailed_story = '\n'.join(primary_gm_memories)
    episode_summary = model.sample_text(
        f'Sequence of events:\n{detailed_story}'
        + '\nNarratively summarize the above temporally ordered '
        + 'sequence of events. Write it as a news report. Summary:\n',
        max_tokens=3500,
        terminators=(),
    )
  else:
    episode_summary = ''

  history_sources = [primary_environment] + list(secondary_environments)

  joint_histories = []
  for history in history_sources:
    joint_histories.extend(history.get_history())

  sorted_joint_history = sorted(
      joint_histories, key=operator.itemgetter('date')
  )

  histories_html = [
      html_lib.PythonObjectToHTMLConverter(sorted_joint_history).convert()
  ] + [
      html_lib.PythonObjectToHTMLConverter(history.get_history()).convert()
      for history in history_sources
  ]

  histories_names = ['Joint log'] + [
      history.name for history in history_sources
  ]

  gm_mem_html = html_lib.PythonObjectToHTMLConverter(
      primary_gm_memories
  ).convert()
  tabbed_html = html_lib.combine_html_pages(
      histories_html + [gm_mem_html],
      histories_names + ['GM'],
      summary=episode_summary,
      title='Simulation Log',
  )
  tabbed_html = html_lib.finalise_html(tabbed_html)
  return tabbed_html
Create an HTML log of the simulation.

  Args:
    model: The language model to use.
    primary_environment: The main game master.
    secondary_environments: Sequence of secondary game masters.
    summarize_entire_episode: Optionally, summarize the entire episode. This may
      load a lot of tokens into a language model all at once and in some cases
      exceed the model's context window and cause it to crash.

  Returns:
    An HTML string log of the simulation.
  
concordia/deprecated/factory/environment/basic_game_master.py