|
| 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 |
| 19 | + |
| 20 | +import oasis |
| 21 | +from oasis import (ActionType, LLMAction, ManualAction, |
| 22 | + generate_twitter_agent_graph) |
| 23 | + |
| 24 | + |
| 25 | +async def main(): |
| 26 | + openai_model = ModelFactory.create( |
| 27 | + model_platform=ModelPlatformType.DEEPSEEK, |
| 28 | + model_type="deepseek-chat", |
| 29 | + url="https://api.deepseek.com/v1", |
| 30 | + ) |
| 31 | + |
| 32 | + # Define the available actions for the agents |
| 33 | + available_actions = [ |
| 34 | + ActionType.JOIN_GROUP, |
| 35 | + ActionType.LEAVE_GROUP, |
| 36 | + ActionType.LISTEN_FROM_GROUP, |
| 37 | + ActionType.SEND_TO_GROUP, |
| 38 | + ActionType.LIKE_POST, |
| 39 | + ActionType.UNLIKE_POST, |
| 40 | + ActionType.REPOST, |
| 41 | + ActionType.QUOTE_POST, |
| 42 | + ] |
| 43 | + |
| 44 | + agent_graph = await generate_twitter_agent_graph( |
| 45 | + profile_path=( |
| 46 | + "data/twitter_dataset/anonymous_topic_200_1h/False_Business_0.csv" |
| 47 | + ), |
| 48 | + model=openai_model, |
| 49 | + available_actions=available_actions, |
| 50 | + ) |
| 51 | + |
| 52 | + # Define the path to the database |
| 53 | + db_path = "./data/twitter_simulation.db" |
| 54 | + |
| 55 | + # Delete the old database |
| 56 | + if os.path.exists(db_path): |
| 57 | + os.remove(db_path) |
| 58 | + |
| 59 | + # Make the environment |
| 60 | + env = oasis.make( |
| 61 | + agent_graph=agent_graph, |
| 62 | + platform=oasis.DefaultPlatformType.TWITTER, |
| 63 | + database_path=db_path, |
| 64 | + ) |
| 65 | + |
| 66 | + # Run the environment |
| 67 | + await env.reset() |
| 68 | + |
| 69 | + group_result = await env.platform.create_group(1, "AI Group") |
| 70 | + group_id = group_result["group_id"] |
| 71 | + |
| 72 | + actions_1 = {} |
| 73 | + |
| 74 | + actions_1[env.agent_graph.get_agent(0)] = ManualAction( |
| 75 | + action_type=ActionType.JOIN_GROUP, action_args={"group_id": group_id}) |
| 76 | + await env.step(actions_1) |
| 77 | + |
| 78 | + actions_2 = { |
| 79 | + agent: LLMAction() |
| 80 | + # Activate 5 agents with id 1, 3, 5, 7, 9 |
| 81 | + for _, agent in env.agent_graph.get_agents([1, 3, 5, 7, 9]) |
| 82 | + } |
| 83 | + |
| 84 | + await env.step(actions_2) |
| 85 | + |
| 86 | + actions_3 = {} |
| 87 | + |
| 88 | + actions_3[env.agent_graph.get_agent(1)] = ManualAction( |
| 89 | + action_type=ActionType.SEND_TO_GROUP, |
| 90 | + action_args={ |
| 91 | + "group_id": group_id, |
| 92 | + "message": "DeepSeek is amazing!" |
| 93 | + }, |
| 94 | + ) |
| 95 | + await env.step(actions_3) |
| 96 | + |
| 97 | + actions_4 = { |
| 98 | + agent: LLMAction() |
| 99 | + for _, agent in env.agent_graph.get_agents() |
| 100 | + } |
| 101 | + await env.step(actions_4) |
| 102 | + |
| 103 | + # Close the environment |
| 104 | + await env.close() |
| 105 | + |
| 106 | + |
| 107 | +if __name__ == "__main__": |
| 108 | + asyncio.run(main()) |
0 commit comments