From dc160eaaa6c532368540b812b37b111ee2707665 Mon Sep 17 00:00:00 2001 From: Tochi-Nwachukwu Date: Thu, 30 Oct 2025 06:23:27 +0100 Subject: [PATCH] Submission for Week 8 --- .../tochi/agents/agent.py | 33 + .../tochi/agents/deals.py | 233 +++ .../tochi/agents/ensemble_agent.py | 48 + .../tochi/agents/frontier_agent.py | 113 ++ .../tochi/agents/messaging_agent.py | 79 ++ .../tochi/agents/planning_agent.py | 57 + .../tochi/agents/random_forest_agent.py | 37 + .../tochi/agents/scanner_agent.py | 94 ++ .../tochi/agents/specialist_agent.py | 29 + .../tochi/autonomous_deal_agent.ipynb | 1262 +++++++++++++++++ .../tochi/deal_agent_framework.py | 98 ++ week8/community_contributions/tochi/items.py | 101 ++ .../tochi/log_utils.py | 35 + .../tochi/price_is_right.py | 62 + .../tochi/price_is_right_final.py | 166 +++ .../tochi/pricer_ephemeral.py | 66 + .../tochi/pricer_service.py | 69 + .../community_contributions/tochi/testing.py | 75 + 18 files changed, 2657 insertions(+) create mode 100644 week8/community_contributions/tochi/agents/agent.py create mode 100644 week8/community_contributions/tochi/agents/deals.py create mode 100644 week8/community_contributions/tochi/agents/ensemble_agent.py create mode 100644 week8/community_contributions/tochi/agents/frontier_agent.py create mode 100644 week8/community_contributions/tochi/agents/messaging_agent.py create mode 100644 week8/community_contributions/tochi/agents/planning_agent.py create mode 100644 week8/community_contributions/tochi/agents/random_forest_agent.py create mode 100644 week8/community_contributions/tochi/agents/scanner_agent.py create mode 100644 week8/community_contributions/tochi/agents/specialist_agent.py create mode 100644 week8/community_contributions/tochi/autonomous_deal_agent.ipynb create mode 100644 week8/community_contributions/tochi/deal_agent_framework.py create mode 100644 week8/community_contributions/tochi/items.py create mode 100644 week8/community_contributions/tochi/log_utils.py create mode 100644 week8/community_contributions/tochi/price_is_right.py create mode 100644 week8/community_contributions/tochi/price_is_right_final.py create mode 100644 week8/community_contributions/tochi/pricer_ephemeral.py create mode 100644 week8/community_contributions/tochi/pricer_service.py create mode 100644 week8/community_contributions/tochi/testing.py diff --git a/week8/community_contributions/tochi/agents/agent.py b/week8/community_contributions/tochi/agents/agent.py new file mode 100644 index 0000000..fe09e18 --- /dev/null +++ b/week8/community_contributions/tochi/agents/agent.py @@ -0,0 +1,33 @@ +import logging + +class Agent: + """ + An abstract superclass for Agents + Used to log messages in a way that can identify each Agent + """ + + # Foreground colors + RED = '\033[31m' + GREEN = '\033[32m' + YELLOW = '\033[33m' + BLUE = '\033[34m' + MAGENTA = '\033[35m' + CYAN = '\033[36m' + WHITE = '\033[37m' + + # Background color + BG_BLACK = '\033[40m' + + # Reset code to return to default color + RESET = '\033[0m' + + name: str = "" + color: str = '\033[37m' + + def log(self, message): + """ + Log this as an info message, identifying the agent + """ + color_code = self.BG_BLACK + self.color + message = f"[{self.name}] {message}" + logging.info(color_code + message + self.RESET) \ No newline at end of file diff --git a/week8/community_contributions/tochi/agents/deals.py b/week8/community_contributions/tochi/agents/deals.py new file mode 100644 index 0000000..fc24e76 --- /dev/null +++ b/week8/community_contributions/tochi/agents/deals.py @@ -0,0 +1,233 @@ +import os +from dotenv import load_dotenv +from pydantic import BaseModel +from typing import List, Dict, Self +import feedparser +from tqdm import tqdm +import time +from openai import OpenAI +from typing import Optional +import json + + +load_dotenv(override=True) +os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY", "your-key-if-not-using-env") + +openai = OpenAI() + +feeds = [ + "https://www.dealnews.com/c142/Electronics/?rss=1", + "https://www.dealnews.com/c39/Computers/?rss=1", + "https://www.dealnews.com/c238/Automotive/?rss=1", + "https://www.dealnews.com/f1912/Smart-Home/?rss=1", + "https://www.dealnews.com/c196/Home-Garden/?rss=1", + "https://www.reddit.com/r/buildapcsales.rss", + "https://www.reddit.com/r/deals.rss", +] + +SYSTEM_PROMPT = """ +You are an RSS feed parser specializing in extracting deal information. Your task is to analyze content and extract structured data. + +# INPUT TYPES +You will receive one of two input types: + +**TYPE 1: RSS Feed Entry Data** +- May contain fields like: title, summary, description, link +- Summary/description often contains HTML with deal details +- Multiple URL fields may exist (link, links array, etc.) + +**TYPE 2: HTML Page Content** +- Raw HTML from a deal webpage +- Contains product information, pricing, and purchase links + +# TASK +Extract and structure the following information: +1. **title**: The deal's headline or main title + - For RSS entries: Use the entry's title field directly + - For HTML: Extract the main product/deal title + +2. **summary**: A concise summary of the deal (2-3 sentences max), focusing on: + - What is being offered (product name, specs) + - Key terms (price, discount percentage, original price) + - Important conditions (promo codes, shipping, availability, refurb/new condition) + - Strip ALL HTML tags and formatting + +3. **url**: The primary link where users can access the deal + - Prioritize direct product/deal purchase links + - Avoid tracking links, RSS links with "?rss=1" or "?iref=rss" + - For RSS entries, use the "link" field or first link in "links" array + +# EXTRACTION RULES +- **From RSS entries**: Parse the 'summary' or 'description' HTML to extract deal details +- **Clean all HTML**: Remove ,
,

,