Reddit Simulation

This cookbook provides a comprehensive guide to running a Reddit simulation using OASIS.

import asyncio
import os

from camel.models import ModelFactory
from camel.types import ModelPlatformType, ModelType

import oasis
from oasis import ActionType, EnvAction, SingleAction


async def main():
    # Define the model for the agents
    openai_model = ModelFactory.create(
        model_platform=ModelPlatformType.OPENAI,
        model_type=ModelType.GPT_4O_MINI,
    )

    # Define the available actions for the agents
    available_actions = [
        ActionType.LIKE_POST,
        ActionType.DISLIKE_POST,
        ActionType.CREATE_POST,
        ActionType.CREATE_COMMENT,
        ActionType.LIKE_COMMENT,
        ActionType.DISLIKE_COMMENT,
        ActionType.SEARCH_POSTS,
        ActionType.SEARCH_USER,
        ActionType.TREND,
        ActionType.REFRESH,
        ActionType.DO_NOTHING,
        ActionType.FOLLOW,
        ActionType.MUTE,
    ]

    # Define the path to the database
    db_path = "./data/reddit_simulation.db"

    # Delete the old database
    if os.path.exists(db_path):
        os.remove(db_path)

    # Make the environment
    env = oasis.make(
        platform=oasis.DefaultPlatformType.REDDIT,
        database_path=db_path,
        agent_profile_path="./data/reddit/user_data_36.json",
        agent_models=openai_model,
        available_actions=available_actions,
    )

    # Run the environment
    await env.reset()

    action_1 = SingleAction(agent_id=0,
                            action=ActionType.CREATE_POST,
                            args={"content": "Hello, world!"})
    action_2 = SingleAction(agent_id=0,
                            action=ActionType.CREATE_COMMENT,
                            args={
                                "post_id": "1",
                                "content": "Welcome to the OASIS World!"
                            })

    env_actions = EnvAction(activate_agents=list(range(10)),
                            intervention=[action_1, action_2])

    # Perform the actions
    await env.step(env_actions)

    # Close the environment
    await env.close()

    # Print the results
    # print_db_contents(db_path)


if __name__ == "__main__":
    asyncio.run(main())