Skip to content

Commit

Permalink
updating external colabs to the new component folder structure
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 588345042
Change-Id: I9a0c478c312cf673fd65ca194bb9622829d70b84
  • Loading branch information
vezhnick authored and copybara-github committed Dec 6, 2023
1 parent 7357fb3 commit 82a57f3
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 85 deletions.
23 changes: 13 additions & 10 deletions examples/cyberball/cyberball.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,20 @@
"from IPython import display\n",
"\n",
"from concordia.agents import basic_agent\n",
"from concordia.agents import components\n",
"from concordia import components as generic_components\n",
"from concordia.components import agent as components\n",
"from concordia.associative_memory import associative_memory\n",
"from concordia.associative_memory import blank_memories\n",
"from concordia.associative_memory import embedder_st5\n",
"from concordia.associative_memory import formative_memories\n",
"from concordia.associative_memory import importance_function\n",
"from concordia.clocks import game_clock\n",
"from concordia.environment import components as gm_components\n",
"from concordia.components import game_master as gm_components\n",
"from concordia.environment import game_master\n",
"from concordia.metrics import common_sense_morality\n",
"from concordia.metrics import dass_questionnaire\n",
"from concordia.metrics import opinion_of_others\n",
"from concordia.language_model import sax_model\n",
"from concordia.google.language_model import sax_model\n",
"from concordia.utils import html as html_lib\n",
"from concordia.utils import measurements as measurements_lib\n",
"from concordia.utils import plotting\n",
Expand Down Expand Up @@ -221,9 +222,9 @@
" measurements: measurements_lib.Measurements | None = None):\n",
" mem = formative_memory_factory.make_memories(agent_config)\n",
"\n",
" time = components.report_state.ReportState(\n",
" time = generic_components.report_function.ReportFunction(\n",
" name='Current time',\n",
" get_state=clock.current_time_interval_str,\n",
" function=clock.current_time_interval_str,\n",
" )\n",
"\n",
" somatic_state = components.somatic_state.SomaticState(\n",
Expand Down Expand Up @@ -501,9 +502,9 @@
"# @title Create components and externalities\n",
"player_names = [player.name for player in players]\n",
"\n",
"instructions = components.constant.ConstantConstruct(\n",
"instructions = generic_components.constant.ConstantComponent(\n",
" game_master_instructions, 'Instructions')\n",
"general_knowledge_of_premise = components.constant.ConstantConstruct(\n",
"general_knowledge_of_premise = generic_components.constant.ConstantComponent(\n",
" ' '.join(generic_memories), 'General knowledge of the game')\n",
"\n",
"player_status = gm_components.player_status.PlayerStatus(\n",
Expand All @@ -516,9 +517,11 @@
" model=model,\n",
" memory=game_master_memory,\n",
")\n",
"time_display = gm_components.time_display.TimeDisplay(\n",
" game_clock=clock,\n",
")\n",
"time_display = time = generic_components.report_function.ReportFunction(\n",
" name='Current time',\n",
" function=clock.current_time_interval_str,\n",
" )\n",
"\n",
"\n",
"mem_factory = blank_memories.MemoryFactory(\n",
" model,\n",
Expand Down
55 changes: 16 additions & 39 deletions examples/magic_beans_for_sale.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,26 @@
"import concurrent.futures\n",
"import datetime\n",
"\n",
"import random\n",
"import numpy as np\n",
"\n",
"from google.colab import widgets\n",
"from IPython import display\n",
"\n",
"from concordia.agents import basic_agent\n",
"from concordia.agents import components\n",
"from concordia.components import agent as components\n",
"from concordia import components as generic_components\n",
"from concordia.associative_memory import associative_memory\n",
"from concordia.associative_memory import blank_memories\n",
"from concordia.associative_memory import embedder_st5\n",
"from concordia.associative_memory import formative_memories\n",
"from concordia.associative_memory import importance_function\n",
"from concordia.clocks import game_clock\n",
"from concordia.environment import components as gm_components\n",
"from concordia.components import game_master as gm_components\n",
"from concordia.environment import game_master\n",
"from concordia.metrics import goal_achievement\n",
"from concordia.metrics import common_sense_morality\n",
"from concordia.metrics import opinion_of_others\n",
"from concordia.language_model import sax_model\n",
"from concordia.google.language_model import sax_model\n",
"from concordia.utils import html as html_lib\n",
"from concordia.utils import measurements as measurements_lib\n",
"from concordia.utils import plotting\n"
Expand Down Expand Up @@ -103,7 +103,7 @@
"source": [
"# @title SAX Language Model\n",
"\n",
"SAX_PATH = '/sax/simulacra/llmit-340b-v10' # @param [\"/sax/simulacra/llmit-340b-v10-8k\", \"/sax/simulacra/llmit-340b-v10\"]\n",
"SAX_PATH = '' # @param\n",
"DEFAULT_MAX_TOKENS = 300 # @param {type: 'integer'}\n",
"DEFAULT_TIMEOUT_SECONDS = 60 # @param {type: 'number'}\n",
"\n",
Expand Down Expand Up @@ -240,9 +240,9 @@
"\n",
" mem = formative_memory_factory.make_memories(agent_config)\n",
"\n",
" time = components.report_state.ReportState(\n",
" time = generic_components.report_function.ReportFunction(\n",
" name='Current time',\n",
" get_state=clock.current_time_interval_str,\n",
" function=clock.current_time_interval_str,\n",
" )\n",
"\n",
" self_perception = components.self_perception.SelfPerception(\n",
Expand All @@ -268,8 +268,7 @@
" components=[self_perception, situation_perception],\n",
" )\n",
"\n",
" initial_goal_component = components.constant.ConstantConstruct(\n",
" state=agent_config.goal)\n",
" initial_goal_component = generic_components.constant.ConstantComponent(state=agent_config.goal)\n",
" plan = components.plan.SimPlan(\n",
" model,\n",
" mem,\n",
Expand All @@ -281,7 +280,7 @@
" verbose=False,\n",
" )\n",
"\n",
" persona = components.sequential.Sequential(\n",
" persona = generic_components.sequential.Sequential(\n",
" name='persona',\n",
" components=[\n",
" self_perception,\n",
Expand Down Expand Up @@ -483,18 +482,21 @@
"# @title Create components of the Game Master\n",
"player_names = [player.name for player in players]\n",
"\n",
"instructions_construct = components.constant.ConstantConstruct(\n",
"instructions_construct = generic_components.constant.ConstantComponent(\n",
" state=game_master_instructions,\n",
" name='Instructions')\n",
"scenario_knowledge = components.constant.ConstantConstruct(\n",
"scenario_knowledge = generic_components.constant.ConstantComponent(\n",
" state=' '.join(shared_memories),\n",
" name='Background')\n",
"\n",
"time_display=generic_components.report_function.ReportFunction(\n",
" name='Current time',\n",
" function=clock.current_time_interval_str,\n",
" )\n",
"important_facts = [\n",
" 'Magic beans are marked \"magical\" but have no actual magical powers.',\n",
" 'Magic is not real.',\n",
"]\n",
"important_facts_construct = components.constant.ConstantConstruct(\n",
"important_facts_construct = generic_components.constant.ConstantComponent(\n",
" state=' '.join(important_facts),\n",
" name='Important facts')\n",
"\n",
Expand Down Expand Up @@ -544,29 +546,6 @@
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "5SpNVmlh6_hp"
},
"outputs": [],
"source": [
"# @title Metrics\n",
"player_goals = {\n",
" player_config.name: player_config.goal for player_config in player_configs\n",
"}\n",
"\n",
"goal_metric = goal_achievement.GoalAchievementMetric(\n",
" model, player_goals, clock, 'Goal achievement', verbose=False)\n",
"morality_metric = common_sense_morality.CommonSenseMoralityMetric(\n",
" model, players, clock, 'Morality', verbose=False)\n",
"reputation_metric = reputation.ReputationMetric(\n",
" model, players, clock, 'Reputation', verbose=False)\n",
"\n",
"metrics = [goal_metric, morality_metric, reputation_metric]"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -590,7 +569,6 @@
" direct_effect_externality,\n",
" inventories,\n",
" ],\n",
" measurements=metrics,\n",
" randomise_initiative=True,\n",
" player_observes_event=False,\n",
" verbose=True,\n",
Expand Down Expand Up @@ -716,7 +694,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "O4jp0xGXvOAJ"
},
"outputs": [],
Expand Down
20 changes: 11 additions & 9 deletions examples/phone/calendar.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,18 @@
"\n",
"from IPython import display\n",
"\n",
"from concordia import components as generic_components\n",
"from concordia.components import agent as components\n",
"from concordia.components import game_master as gm_components\n",
"from concordia.agents import basic_agent\n",
"from concordia.agents import components\n",
"from concordia.associative_memory import associative_memory\n",
"from concordia.associative_memory import blank_memories\n",
"from concordia.associative_memory import embedder_st5\n",
"from concordia.associative_memory import formative_memories\n",
"from concordia.associative_memory import importance_function\n",
"from concordia.clocks import game_clock\n",
"from concordia.environment import components as gm_components\n",
"from concordia.environment import game_master\n",
"from concordia.language_model import sax_model\n",
"from concordia.google.language_model import sax_model\n",
"from concordia.utils import html as html_lib\n",
"\n",
"from concordia.examples.phone.components import apps\n",
Expand Down Expand Up @@ -221,15 +222,16 @@
"\n",
" # Build the player.\n",
"\n",
" time = components.report_state.ReportState(\n",
" name='Current time',\n",
" get_state=clock.current_time_interval_str)\n",
" time = generic_components.report_function.ReportFunction(\n",
" name='Current time',\n",
" function=clock.current_time_interval_str,\n",
" )\n",
"\n",
" somatic_state = components.somatic_state.SomaticState(\n",
" model, mem, agent_config.name, clock.now\n",
" )\n",
" identity = components.identity.SimIdentity(model, mem, agent_config.name)\n",
" goal_component = components.constant.ConstantConstruct(state=agent_config.goal)\n",
" goal_component = components.constant.ConstantComponent(state=agent_config.goal)\n",
" plan = components.plan.SimPlan(\n",
" model,\n",
" mem,\n",
Expand Down Expand Up @@ -398,8 +400,8 @@
"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",
"instructions_construct = components.constant.ConstantComponent(game_master_instructions, 'Instructions')\n",
"facts_on_village = components.constant.ConstantComponent(' '.join(shared_memories), 'General knowledge of Riverbend')\n",
"player_status = gm_components.player_status.PlayerStatus(clock.now, model, game_master_memory, player_names)\n",
"\n",
"relevant_events = gm_components.relevant_events.RelevantEvents(clock.now, model, game_master_memory)\n",
Expand Down
17 changes: 9 additions & 8 deletions examples/three_key_questions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,22 @@
"from google.colab import widgets\n",
"from IPython import display\n",
"\n",
"from concordia import components\n",
"from concordia import components as generic_components\n",
"from concordia.agents import basic_agent\n",
"from concordia.components import agent as components\n",
"from concordia.agents import basic_agent\n",
"from concordia.agents import components\n",
"from concordia.associative_memory import associative_memory\n",
"from concordia.associative_memory import blank_memories\n",
"from concordia.associative_memory import embedder_st5\n",
"from concordia.associative_memory import formative_memories\n",
"from concordia.associative_memory import importance_function\n",
"from concordia.clocks import game_clock\n",
"from concordia.environment import components as gm_components\n",
"from concordia.components import game_master as gm_components\n",
"from concordia.environment import game_master\n",
"from concordia.environment.metrics import common_sense_morality\n",
"from concordia.environment.metrics import goal_achievement\n",
"from concordia.environment.metrics import reputation\n",
"from concordia.language_model import sax_model\n",
"from concordia.google.language_model import sax_model\n",
"from concordia.utils import html as html_lib\n",
"from concordia.utils import plotting\n"
]
Expand Down Expand Up @@ -321,7 +322,8 @@
" person_by_situation,\n",
" ],\n",
" )\n",
" current_time_component = components.report_callback.ReportFunction(name='Current time',\n",
" current_time_component = components.report_function.ReportFunction(\n",
" name='current_time',\n",
" function=clock.current_time_interval_str)\n",
"\n",
" current_obs = components.observation.Observation(agent_config.name, mem)\n",
Expand Down Expand Up @@ -419,10 +421,10 @@
"# @title Create components of the Game Master\n",
"player_names = [player.name for player in players]\n",
"\n",
"instructions_construct = components.constant.ConstantComponent(\n",
"instructions_construct = generic_components.constant.ConstantComponent(\n",
" state=game_master_instructions,\n",
" name='Instructions')\n",
"scenario_knowledge = components.constant.ConstantComponent(\n",
"scenario_knowledge = generic_components.constant.ConstantComponent(\n",
" state=' '.join(shared_memories),\n",
" name='Background')\n",
"\n",
Expand Down Expand Up @@ -603,7 +605,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "O4jp0xGXvOAJ"
},
"outputs": [],
Expand Down
14 changes: 7 additions & 7 deletions examples/village/day_in_riverbend.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@
"from google.colab import widgets\n",
"from IPython import display\n",
"\n",
"from concordia import components\n",
"from concordia import components as generic_components\n",
"from concordia.agents import basic_agent\n",
"from concordia.agents import components\n",
"from concordia.components import agent as components\n",
"from concordia.associative_memory import associative_memory\n",
"from concordia.associative_memory import blank_memories\n",
"from concordia.associative_memory import embedder_st5\n",
"from concordia.associative_memory import formative_memories\n",
"from concordia.associative_memory import importance_function\n",
"from concordia.clocks import game_clock\n",
"from concordia.environment import components as gm_components\n",
"from concordia.components import game_master as gm_components\n",
"from concordia.environment import game_master\n",
"from concordia.environment.metrics import goal_achievement\n",
"from concordia.language_model import sax_model\n",
"from concordia.google.language_model import sax_model\n",
"from concordia.utils import html as html_lib\n",
"from concordia.utils import plotting"
]
Expand Down Expand Up @@ -240,7 +240,7 @@
" function=clock.current_time_interval_str)\n",
"\n",
" identity = components.identity.SimIdentity(model, mem, agent_config.name)\n",
" goal_component = components.constant.ConstantComponent(state=agent_config.goal)\n",
" goal_component = generic_components.constant.ConstantComponent(state=agent_config.goal)\n",
" reflection = components.reflection.Reflection(\n",
" model=model,\n",
" memory=mem,\n",
Expand Down Expand Up @@ -437,10 +437,10 @@
"citizen_names = [player.name for player in players]\n",
"player_names = [player.name for player in players]\n",
"\n",
"instructions_construct = components.constant.ConstantComponent(\n",
"instructions_construct = generic_components.constant.ConstantComponent(\n",
" game_master_instructions, 'Instructions'\n",
")\n",
"facts_on_village = components.constant.ConstantComponent(\n",
"facts_on_village = generic_components.constant.ConstantComponent(\n",
" ' '.join(shared_memories), 'General knowledge of Riverbend'\n",
")\n",
"player_status = gm_components.player_status.PlayerStatus(\n",
Expand Down
Loading

0 comments on commit 82a57f3

Please sign in to comment.