import autogen
import os

# Set your OpenAI API key
# os.environ["OPENAI_API_KEY"] = "YOUR_OPENAI_API_KEY"

# Configuration for the models
config_list = [
    {
        "model": "gpt-4",
        "api_key": os.environ.get("OPENAI_API_KEY"),
    }
]

# Define the data file
DATA_FILE = "data.txt"

# Create an AssistantAgent
assistant = autogen.AssistantAgent(
    name="assistant",
    llm_config={"config_list": config_list},
    system_message="You are a helpful AI assistant. Answer questions based on the provided information. Respond with 'TERMINATE' when the task is done.",
)

# Create a UserProxyAgent
user_proxy = autogen.UserProxyAgent(
    name="user_proxy",
    human_input_mode="NEVER",
    max_consecutive_auto_reply=10,
    is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"),
    code_execution_config={"use_docker": False},
)

# Read the external data
script_dir = os.path.dirname(__file__)
data_path = os.path.join(script_dir, DATA_FILE)
with open(data_path, "r") as f:
    knowledge_base = f.read()

# Start the conversation with the knowledge base as context
user_proxy.initiate_chat(
    assistant,
    message=f"Here is some information: {knowledge_base} Based on this information, what is AutoGen?",
)
