|
| 1 | +# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. =========== |
| 2 | +# Licensed under the Apache License, Version 2.0 (the “License”); |
| 3 | +# you may not use this file except in compliance with the License. |
| 4 | +# You may obtain a copy of the License at |
| 5 | +# |
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an “AS IS” BASIS, |
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +# See the License for the specific language governing permissions and |
| 12 | +# limitations under the License. |
| 13 | +# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. =========== |
| 14 | +import asyncio |
| 15 | +import os |
| 16 | + |
| 17 | +from camel.models import ModelFactory |
| 18 | +from camel.types import ModelPlatformType, ModelType |
| 19 | + |
| 20 | +import oasis |
| 21 | +from oasis import ActionType, EnvAction, SingleAction |
| 22 | + |
| 23 | + |
| 24 | +async def main(): |
| 25 | + openai_model = ModelFactory.create( |
| 26 | + model_platform=ModelPlatformType.OPENAI, |
| 27 | + model_type=ModelType.GPT_4O_MINI, |
| 28 | + ) |
| 29 | + |
| 30 | + # Define the available actions for the agents |
| 31 | + available_actions = [ |
| 32 | + ActionType.CREATE_POST, |
| 33 | + ActionType.LIKE_POST, |
| 34 | + ActionType.REPOST, |
| 35 | + ActionType.FOLLOW, |
| 36 | + ActionType.DO_NOTHING, |
| 37 | + ActionType.QUOTE_POST, |
| 38 | + ] |
| 39 | + |
| 40 | + # Define the path to the database |
| 41 | + db_path = "./data/twitter_simulation.db" |
| 42 | + |
| 43 | + # Delete the old database |
| 44 | + if os.path.exists(db_path): |
| 45 | + os.remove(db_path) |
| 46 | + |
| 47 | + # Make the environment |
| 48 | + env = oasis.make( |
| 49 | + platform=oasis.DefaultPlatformType.TWITTER, |
| 50 | + database_path=db_path, |
| 51 | + agent_profile_path=("data/twitter_dataset/anonymous_topic_200_1h/" |
| 52 | + "False_Business_0.csv"), |
| 53 | + agent_models=openai_model, |
| 54 | + available_actions=available_actions, |
| 55 | + ) |
| 56 | + |
| 57 | + # Run the environment |
| 58 | + await env.reset() |
| 59 | + |
| 60 | + action_1 = SingleAction(agent_id=0, |
| 61 | + action=ActionType.CREATE_POST, |
| 62 | + args={"content": "Earth is flat."}) |
| 63 | + env_actions_1 = EnvAction( |
| 64 | + # Activate 5 agents with id 1, 3, 5, 7, 9 |
| 65 | + activate_agents=[1, 3, 5, 7, 9], |
| 66 | + intervention=[action_1]) |
| 67 | + |
| 68 | + action_2 = SingleAction(agent_id=1, |
| 69 | + action=ActionType.CREATE_POST, |
| 70 | + args={"content": "Earth is not flat."}) |
| 71 | + env_actions_2 = EnvAction(activate_agents=[2, 4, 6, 8, 10], |
| 72 | + intervention=[action_2]) |
| 73 | + |
| 74 | + empty_action = EnvAction() # Means activate all agents and no intervention |
| 75 | + |
| 76 | + all_env_actions = [ |
| 77 | + env_actions_1, |
| 78 | + env_actions_2, |
| 79 | + empty_action, |
| 80 | + ] |
| 81 | + |
| 82 | + # Simulate 3 timesteps |
| 83 | + for i in range(3): |
| 84 | + env_actions = all_env_actions[i] |
| 85 | + # Perform the actions |
| 86 | + await env.step(env_actions) |
| 87 | + |
| 88 | + # Close the environment |
| 89 | + await env.close() |
| 90 | + |
| 91 | + |
| 92 | +if __name__ == "__main__": |
| 93 | + asyncio.run(main()) |
0 commit comments