145 lines
4.3 KiB
Python
145 lines
4.3 KiB
Python
"""Re-run press release pipeline for specific tasks that are missing attachments."""
|
|
|
|
import logging
|
|
import sys
|
|
import io
|
|
|
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
|
|
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format="%(asctime)s [%(name)s] %(levelname)s: %(message)s",
|
|
datefmt="%H:%M:%S",
|
|
handlers=[logging.StreamHandler(stream=io.TextIOWrapper(sys.stderr.buffer, encoding="utf-8"))],
|
|
)
|
|
log = logging.getLogger("pr_rerun")
|
|
|
|
from cheddahbot.config import load_config
|
|
from cheddahbot.db import Database
|
|
from cheddahbot.llm import LLMAdapter
|
|
from cheddahbot.agent import Agent
|
|
from cheddahbot.clickup import ClickUpClient
|
|
|
|
|
|
TASKS_TO_RERUN = [
|
|
("86b8ebfk9", "Advanced Industrial highlights medical grade plastic expertise", "Advanced Industrial"),
|
|
]
|
|
|
|
|
|
def bootstrap():
|
|
config = load_config()
|
|
db = Database(config.db_path)
|
|
llm = LLMAdapter(
|
|
default_model=config.chat_model,
|
|
openrouter_key=config.openrouter_api_key,
|
|
ollama_url=config.ollama_url,
|
|
lmstudio_url=config.lmstudio_url,
|
|
)
|
|
|
|
agent_cfg = config.agents[0] if config.agents else None
|
|
agent = Agent(config, db, llm, agent_config=agent_cfg)
|
|
|
|
try:
|
|
from cheddahbot.memory import MemorySystem
|
|
scope = agent_cfg.memory_scope if agent_cfg else ""
|
|
memory = MemorySystem(config, db, scope=scope)
|
|
agent.set_memory(memory)
|
|
except Exception as e:
|
|
log.warning("Memory not available: %s", e)
|
|
|
|
from cheddahbot.tools import ToolRegistry
|
|
tools = ToolRegistry(config, db, agent)
|
|
agent.set_tools(tools)
|
|
|
|
try:
|
|
from cheddahbot.skills import SkillRegistry
|
|
skills = SkillRegistry(config.skills_dir)
|
|
agent.set_skills_registry(skills)
|
|
except Exception as e:
|
|
log.warning("Skills not available: %s", e)
|
|
|
|
return config, db, agent, tools
|
|
|
|
|
|
def run_task(agent, tools, config, client, task_id, task_name, customer):
|
|
"""Execute write_press_releases for a specific task."""
|
|
# Build args matching the field_mapping from config
|
|
args = {
|
|
"topic": task_name,
|
|
"company_name": customer,
|
|
"clickup_task_id": task_id,
|
|
}
|
|
|
|
# Also fetch IMSURL from the task
|
|
import httpx as _httpx
|
|
resp = _httpx.get(
|
|
f"https://api.clickup.com/api/v2/task/{task_id}",
|
|
headers={"Authorization": config.clickup.api_token},
|
|
timeout=30.0,
|
|
)
|
|
task_data = resp.json()
|
|
for cf in task_data.get("custom_fields", []):
|
|
if cf["name"] == "IMSURL":
|
|
val = cf.get("value")
|
|
if val:
|
|
args["url"] = val
|
|
elif cf["name"] == "SocialURL":
|
|
val = cf.get("value")
|
|
if val:
|
|
args["branded_url"] = val
|
|
|
|
log.info("=" * 70)
|
|
log.info("EXECUTING: %s", task_name)
|
|
log.info(" Task ID: %s", task_id)
|
|
log.info(" Customer: %s", customer)
|
|
log.info(" Args: %s", {k: v for k, v in args.items() if k != "clickup_task_id"})
|
|
log.info("=" * 70)
|
|
|
|
try:
|
|
result = tools.execute("write_press_releases", args)
|
|
|
|
if result.startswith("Skipped:") or result.startswith("Error:"):
|
|
log.error("Task skipped/errored: %s", result[:500])
|
|
return False
|
|
|
|
log.info("Task completed!")
|
|
# Print first 500 chars of result
|
|
print(f"\n--- Result for {task_name} ---")
|
|
print(result[:1000])
|
|
print("--- End ---\n")
|
|
return True
|
|
|
|
except Exception as e:
|
|
log.error("Task failed: %s", e, exc_info=True)
|
|
return False
|
|
|
|
|
|
def main():
|
|
log.info("Bootstrapping CheddahBot...")
|
|
config, db, agent, tools = bootstrap()
|
|
|
|
client = ClickUpClient(
|
|
api_token=config.clickup.api_token,
|
|
workspace_id=config.clickup.workspace_id,
|
|
task_type_field_name=config.clickup.task_type_field_name,
|
|
)
|
|
|
|
log.info("Will re-run %d tasks", len(TASKS_TO_RERUN))
|
|
|
|
results = []
|
|
for i, (task_id, name, customer) in enumerate(TASKS_TO_RERUN):
|
|
log.info("\n>>> Task %d/%d <<<", i + 1, len(TASKS_TO_RERUN))
|
|
success = run_task(agent, tools, config, client, task_id, name, customer)
|
|
results.append((name, success))
|
|
|
|
print(f"\n{'=' * 70}")
|
|
print("RESULTS SUMMARY")
|
|
print(f"{'=' * 70}")
|
|
for name, success in results:
|
|
status = "OK" if success else "FAILED"
|
|
print(f" [{status}] {name}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|