from ..utils import logger

import ollama

from ..utils import rag as Rag, Context, defines

import json

llm = ollama.Client(host=defines.ollama_api_url)

observer, file_watcher = Rag.start_file_watcher(
    llm=llm, watch_directory=defines.doc_dir, recreate=False  # Don't recreate if exists
)

context = Context(file_watcher=file_watcher)
data = context.model_dump(mode="json")
context = Context.model_validate_json(json.dumps(data))
context.file_watcher = file_watcher

agent = context.get_or_create_agent(
    "chat", system_prompt="You are a helpful assistant."
)
# logger.info(f"data: {data}")
# logger.info(f"agent: {agent}")
agent_type = agent.get_agent_type()
logger.info(f"agent_type: {agent_type}")
logger.info(f"system_prompt: {agent.system_prompt}")

agent.system_prompt = "Eat more tomatoes."

data = context.model_dump(mode="json")
context = Context.model_validate_json(json.dumps(data))
context.file_watcher = file_watcher

agent = context.get_agent("chat")
logger.info(f"system_prompt: {agent.system_prompt}")
