diff --git a/examples/village/riverbend_elections.ipynb b/examples/village/riverbend_elections.ipynb index 38ba55a8..010561ca 100644 --- a/examples/village/riverbend_elections.ipynb +++ b/examples/village/riverbend_elections.ipynb @@ -3,7 +3,7 @@ { "cell_type": "markdown", "metadata": { - "id": "sec0h5LfLh-Z" + "id": "TaB0jiCrs71r" }, "source": [ "```\n", @@ -47,7 +47,6 @@ "cell_type": "code", "execution_count": null, "metadata": { - "cellView": "form", "id": "-qLG5ExLqpWa" }, "outputs": [], @@ -101,7 +100,6 @@ "cell_type": "code", "execution_count": null, "metadata": { - "cellView": "form", "id": "cugwvFIKv5AS" }, "outputs": [], @@ -113,7 +111,10 @@ "DEFAULT_MAX_TOKENS = 300 # @param {type: 'integer'}\n", "DEFAULT_TIMEOUT_SECONDS = 60 # @param {type: 'number'}\n", "\n", - "model = sax_model.SAXLanguageModel(SAX_PATH)" + "model = sax_model.SAXLanguageModel(\n", + " SAX_PATH,\n", + " deterministic_multiple_choice=True,\n", + ")" ] }, { @@ -241,22 +242,33 @@ "\n", " time = components.report_state.ReportState(\n", " name='Current time',\n", - " get_state=clock.current_time_interval_str)\n", - "\n", + " get_state=clock.current_time_interval_str,\n", + " )\n", " somatic_state = components.somatic_state.SomaticState(\n", - " model, mem, agent_config.name, clock.now\n", + " model=model,\n", + " memory=mem,\n", + " agent_name=agent_config.name,\n", + " clock_now=clock.now,\n", + " )\n", + " identity = components.identity.SimIdentity(\n", + " model=model,\n", + " memory=mem,\n", + " agent_name=agent_config.name,\n", + " )\n", + " goal_component = components.constant.ConstantConstruct(\n", + " state=agent_config.goal,\n", " )\n", - " identity = components.identity.SimIdentity(model, mem, agent_config.name)\n", - " goal_component = components.constant.ConstantConstruct(state=agent_config.goal)\n", " plan = components.plan.SimPlan(\n", - " model,\n", - " mem,\n", - " agent_config.name,\n", + " model=model,\n", + " memory=mem,\n", + " agent_name=agent_config.name,\n", " components=[identity],\n", " goal=goal_component,\n", " verbose=False,\n", " )\n", - " current_obs = components.observation.Observation(agent_config.name, mem)\n", + " current_obs = components.observation.Observation(\n", + " agent_name=agent_config.name,\n", + " memory=mem)\n", " summary_obs = components.observation.ObservationSummary(\n", " model=model,\n", " agent_name=agent_config.name,\n", @@ -282,13 +294,21 @@ " channel='common_sense_morality',\n", " )\n", " agent = basic_agent.BasicAgent(\n", - " model,\n", - " mem,\n", + " model=model,\n", + " memory=mem,\n", " agent_name=agent_config.name,\n", " clock=clock,\n", " verbose=True,\n", - " components=[identity, plan, somatic_state, summary_obs, current_obs,time,\n", - " goal_metric, morality_metric],\n", + " components=[\n", + " identity,\n", + " plan,\n", + " somatic_state,\n", + " summary_obs,\n", + " current_obs,\n", + " time,\n", + " goal_metric,\n", + " morality_metric,\n", + " ],\n", " )\n", " reputation_metric = opinion_of_others.OpinionOfOthersMetric(\n", " model=model,\n", @@ -376,7 +396,6 @@ }, "outputs": [], "source": [ - "NUM_PLAYERS = 5\n", "victim = 'Alice'\n", "\n", "def make_random_big_five()-\u003estr:\n", @@ -394,22 +413,25 @@ " gender='female',\n", " goal='Win the election and become the mayor of Riverbend',\n", " context=context_from_role('Alice', {'candidate', 'conservative'}),\n", - " traits = make_random_big_five()\n", - " ),\n", + " traits = make_random_big_five(),\n", + " formative_ages = sorted(random.sample(range(5, 40), 5)),\n", + " ),\n", " formative_memories.AgentConfig(\n", " name='Bob',\n", " gender='male',\n", " goal='Win the election and become the mayor of Riverbend.',\n", " context=context_from_role('Bob', {'candidate', 'progressive'}),\n", - " traits = make_random_big_five()\n", - " ),\n", + " traits = make_random_big_five(),\n", + " formative_ages = sorted(random.sample(range(5, 40), 5)),\n", + " ),\n", " formative_memories.AgentConfig(\n", " name='Charlie',\n", " gender='male',\n", " goal=f\"Ruin {victim}'s reputation\",\n", " context=context_from_role('Charlie', {'corrupt'}, victim),\n", - " traits = make_random_big_five()\n", - " ),\n", + " traits = make_random_big_five(),\n", + " formative_ages = sorted(random.sample(range(5, 40), 5)),\n", + " ),\n", " formative_memories.AgentConfig(\n", " name='Dorothy',\n", " gender='female',\n", @@ -417,8 +439,9 @@ " context=context_from_role(\n", " 'Dorothy', {'active_voter', 'progressive'}\n", " ),\n", - " traits = make_random_big_five()\n", - " ),\n", + " traits = make_random_big_five(),\n", + " formative_ages = sorted(random.sample(range(5, 40), 5)),\n", + " ),\n", " formative_memories.AgentConfig(\n", " name='Ellen',\n", " gender='female',\n", @@ -426,7 +449,8 @@ " 'Have a good day and vote in the election.'\n", " ),\n", " context=context_from_role('Ellen', {'active_voter', 'conservative'}),\n", - " traits = make_random_big_five()\n", + " traits = make_random_big_five(),\n", + " formative_ages = sorted(random.sample(range(5, 40), 5)),\n", " ),\n", "]" ] @@ -442,7 +466,8 @@ "NUM_PLAYERS = 5\n", "\n", "player_configs = player_configs[:NUM_PLAYERS]\n", - "player_goals = {player_config.name: player_config.goal for player_config in player_configs}\n", + "player_goals = {\n", + " player_config.name: player_config.goal for player_config in player_configs}\n", "players = []\n", "measurements = measurements_lib.Measurements()\n", "\n", @@ -519,20 +544,22 @@ "cell_type": "code", "execution_count": null, "metadata": { - "cellView": "form", "id": "-cxivChc633z" }, "outputs": [], "source": [ "# @title Create components and externalities\n", - "citizen_names = [player.name for player in players]\n", "player_names = [player.name for player in players]\n", "\n", - "instructions_construct = components.constant.ConstantConstruct(game_master_instructions, 'Instructions')\n", - "facts_on_village = components.constant.ConstantConstruct(' '.join(shared_memories), 'General knowledge of Riverbend')\n", - "player_status = gm_components.player_status.PlayerStatus(clock.now, model, game_master_memory, player_names)\n", + "instructions_construct = components.constant.ConstantConstruct(\n", + " game_master_instructions, 'Instructions')\n", + "facts_on_village = components.constant.ConstantConstruct(\n", + " ' '.join(shared_memories), 'General knowledge of Riverbend')\n", + "player_status = gm_components.player_status.PlayerStatus(\n", + " clock.now, model, game_master_memory, player_names)\n", "\n", - "relevant_events = gm_components.relevant_events.RelevantEvents(clock.now, model, game_master_memory)\n", + "relevant_events = gm_components.relevant_events.RelevantEvents(\n", + " clock.now, model, game_master_memory)\n", "time_display = gm_components.time_display.TimeDisplay(clock)\n", "\n", "election_externality = elections.Elections(\n", @@ -553,8 +580,8 @@ ")\n", "\n", "convo_externality = gm_components.conversation.Conversation(\n", - " players,\n", - " model,\n", + " players=players,\n", + " model=model,\n", " memory=game_master_memory,\n", " clock=clock,\n", " burner_memory_factory=mem_factory,\n", @@ -603,14 +630,14 @@ " trigger=election_externality.declare_winner)\n", "}\n", "\n", - "schedule_construct = gm_components.schedule.Schedule(clock_now=clock.now, schedule=schedule)\n" + "schedule_construct = gm_components.schedule.Schedule(\n", + " clock_now=clock.now, schedule=schedule)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "cellView": "form", "id": "d_R2BVNOsAwa" }, "outputs": [], @@ -668,8 +695,9 @@ "source": [ "for player in players:\n", " player.observe(\n", - " f'{player.name} is at home, they have just woken up. Mayoral elections are going to be'\n", - " f' held today. Polls will open at {TIME_POLLS_OPEN} and close at {TIME_POLLS_CLOSE}.'\n", + " f'{player.name} is at home, they have just woken up. Mayoral elections '\n", + " f'are going to be held today. Polls will open at {TIME_POLLS_OPEN} and '\n", + " f'close at {TIME_POLLS_CLOSE}.'\n", " )\n", "with concurrent.futures.ThreadPoolExecutor(max_workers=NUM_PLAYERS) as pool:\n", " for player in players:\n", @@ -680,7 +708,6 @@ "cell_type": "code", "execution_count": null, "metadata": { - "cellView": "form", "id": "2Bt87stq76gF" }, "outputs": [], @@ -728,7 +755,6 @@ "cell_type": "code", "execution_count": null, "metadata": { - "cellView": "form", "id": "O4jp0xGXvOAJ" }, "outputs": [], @@ -752,7 +778,6 @@ "cell_type": "code", "execution_count": null, "metadata": { - "cellView": "form", "id": "ALG987t-6j-V" }, "outputs": [], @@ -762,7 +787,8 @@ "player_log_names = []\n", "for player in players:\n", " name = player.name\n", - " detailed_story = '\\n'.join(player._memory.retrieve_recent(k=1000, add_time=True))\n", + " detailed_story = '\\n'.join(player._memory.retrieve_recent(k=1000,\n", + " add_time=True))\n", " summary = ''\n", " summary = model.sample_text(\n", " f'Sequence of events that happened to {name}:\\n{detailed_story}'\n", @@ -794,8 +820,15 @@ }, "outputs": [], "source": [ - "history_sources = [env, direct_effect_externality, convo_externality, election_externality]\n", - "histories_html = [html_lib.PythonObjectToHTMLConverter(history.get_history()).convert() for history in history_sources]\n", + "history_sources = [\n", + " env,\n", + " direct_effect_externality,\n", + " convo_externality,\n", + " election_externality,\n", + "]\n", + "histories_html = [\n", + " html_lib.PythonObjectToHTMLConverter(history.get_history()).convert()\n", + " for history in history_sources]\n", "histories_names = [history.name() for history in history_sources]" ] }, @@ -843,7 +876,6 @@ "cell_type": "code", "execution_count": null, "metadata": { - "cellView": "form", "id": "ESJ1l7_Kt5Uj" }, "outputs": [], @@ -862,12 +894,11 @@ "cell_type": "code", "execution_count": null, "metadata": { - "cellView": "form", "id": "5Q1cYflLt5Uj" }, "outputs": [], "source": [ - "utterence_from_user = 'Did you win the elections?' # @param {type:\"string\"}\n", + "utterence_from_user = 'Did you win the election?' # @param {type:\"string\"}\n", "\n", "interrogation += f'{user_identity}: {utterence_from_user}'\n", "player_says = selected_player.say(interrogation)\n", @@ -892,7 +923,8 @@ "kind": "local" }, "private_outputs": true, - "provenance": [] + "provenance": [], + "toc_visible": true }, "kernelspec": { "display_name": "Python 3",