More troubleshooting and setup tips, and some improvements to flagship Week 8 project
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
"\n",
|
||||
"We'll move at a faster pace than usual, particularly as you're becoming proficient LLM engineers.\n",
|
||||
"\n",
|
||||
"One quick admin thing: I've added a number of packages to the environment.yml file during September. To make sure you have the latest repo with the latest code, it's worth doing this from the `llm_engineering` project folder:\n",
|
||||
"One quick admin thing: I've added a number of packages to the environment.yml file during Sep and Oct. To make sure you have the latest repo with the latest code, it's worth doing this from the `llm_engineering` project folder:\n",
|
||||
"\n",
|
||||
"```\n",
|
||||
"git pull\n",
|
||||
@@ -206,6 +206,26 @@
|
||||
"print(reply)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "9c1b1451-6249-4462-bf2d-5937c059926c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Optional: Keeping Modal warm\n",
|
||||
"\n",
|
||||
"## A way to improve the speed of the Modal pricer service\n",
|
||||
"\n",
|
||||
"A student mentioned to me that he was concerned by how slow Modal seems to be. The reason is that Modal puts our service to sleep if we don't use it, and then it takes 2.5 minutes to spin back up.\n",
|
||||
"\n",
|
||||
"I've added a utility called `keep_warm.py` that will keep our Modal warm by pinging it every 30 seconds.\n",
|
||||
"\n",
|
||||
"To use the utliity, bring up a new Terminal (Mac) or Anaconda prompt (Windows), ensure the environment is activated with `conda activate llms\\\n",
|
||||
"\n",
|
||||
"Then run: `python keep_warm.py` from within the week8 drectory.\n",
|
||||
"\n",
|
||||
"Remember to press ctrl+C or exit the window when you no longer need Modal running.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "3754cfdd-ae28-47c8-91f2-6e060e2c91b3",
|
||||
|
||||
@@ -41,14 +41,18 @@ class DealAgentFramework:
|
||||
|
||||
def __init__(self):
|
||||
init_logging()
|
||||
self.log("Initializing Agent Framework")
|
||||
load_dotenv()
|
||||
client = chromadb.PersistentClient(path=self.DB)
|
||||
self.memory = self.read_memory()
|
||||
self.collection = client.get_or_create_collection('products')
|
||||
self.planner = PlanningAgent(self.collection)
|
||||
self.log("Agent Framework is ready")
|
||||
self.planner = None
|
||||
|
||||
def init_agents_as_needed(self):
|
||||
if not self.planner:
|
||||
self.log("Initializing Agent Framework")
|
||||
self.planner = PlanningAgent(self.collection)
|
||||
self.log("Agent Framework is ready")
|
||||
|
||||
def read_memory(self) -> List[Opportunity]:
|
||||
if os.path.exists(self.MEMORY_FILENAME):
|
||||
with open(self.MEMORY_FILENAME, "r") as file:
|
||||
@@ -66,14 +70,15 @@ class DealAgentFramework:
|
||||
text = BG_BLUE + WHITE + "[Agent Framework] " + message + RESET
|
||||
logging.info(text)
|
||||
|
||||
def run(self) -> Optional[Opportunity]:
|
||||
def run(self) -> List[Opportunity]:
|
||||
self.init_agents_as_needed()
|
||||
logging.info("Kicking off Planning Agent")
|
||||
result = self.planner.plan(memory=self.memory)
|
||||
logging.info(f"Planning Agent has completed and returned: {result}")
|
||||
if result:
|
||||
self.memory.append(result)
|
||||
self.write_memory()
|
||||
return result
|
||||
return self.memory
|
||||
|
||||
@classmethod
|
||||
def get_plot_data(cls, max_datapoints=10000):
|
||||
|
||||
10
week8/keep_warm.py
Normal file
10
week8/keep_warm.py
Normal file
@@ -0,0 +1,10 @@
|
||||
import time
|
||||
import modal
|
||||
from datetime import datetime
|
||||
|
||||
Pricer = modal.Cls.lookup("pricer-service", "Pricer")
|
||||
pricer = Pricer()
|
||||
while True:
|
||||
reply = pricer.wake_up.remote()
|
||||
print(f"{datetime.now()}: {reply}")
|
||||
time.sleep(30)
|
||||
@@ -16,149 +16,5 @@
|
||||
},
|
||||
"estimate": 930.8824204895075,
|
||||
"discount": 225.88242048950747
|
||||
},
|
||||
{
|
||||
"deal": {
|
||||
"product_description": "The Certified Refurbished Acer Nitro V laptop boasts a powerful 13th Generation Intel Core i5 processor, perfect for gaming and multitasking. With its 15.6-inch 1080p IPS display and NVIDIA GeForce RTX 4050 GPU, expect stunning visuals and smooth performance for all your gaming needs. It comes with 8GB RAM and a 512GB SSD, ensuring fast load times and ample storage. This model is backed by a 2-year warranty from Allstate, ensuring reliable performance for years to come.",
|
||||
"price": 560.0,
|
||||
"url": "https://www.dealnews.com/products/Acer/Nitro-V-13-th-Gen-i5-15-6-Laptop-w-NVIDIA-Ge-Force-RTX-4050/480447.html?iref=rss-c39"
|
||||
},
|
||||
"estimate": 925.1468647365509,
|
||||
"discount": 365.1468647365509
|
||||
},
|
||||
{
|
||||
"deal": {
|
||||
"product_description": "This EcoFlow DELTA 2 (950) Portable Power Station is designed to meet all your mobile energy needs. With a capacity of 1024Wh, it features six AC outlets and multiple USB ports, allowing you to charge various devices simultaneously. The included 800W alternator charger ensures quick recharging, making it an ideal power solution for camping trips or emergency situations. Its Wi-Fi and Bluetooth capabilities provide easy control and monitoring.",
|
||||
"price": 699.0,
|
||||
"url": "https://www.dealnews.com/Eco-Flow-DELTA-2-950-Portable-Power-Station-800-W-Alternator-Charger-for-699-free-shipping/21671420.html?iref=rss-c142"
|
||||
},
|
||||
"estimate": 869.9627492224658,
|
||||
"discount": 170.96274922246585
|
||||
},
|
||||
{
|
||||
"deal": {
|
||||
"product_description": "This 12V 280Ah LiFePO4 battery offers advanced lithium iron phosphate technology, providing lightweight yet robust power storage for a variety of applications including solar, RV, and marine use. Its long cycle life ensures you can rely on it for consistent performance over time. With built-in BMS (Battery Management System) for safe operation and efficiency, this battery is designed for those who prioritize both reliability and energy efficiency.",
|
||||
"price": 400.0,
|
||||
"url": "https://www.dealnews.com/12-V-280-Ah-Li-Fe-PO4-Battery-for-400-free-shipping/21676885.html?iref=rss-c142"
|
||||
},
|
||||
"estimate": 744.6978640830646,
|
||||
"discount": 344.6978640830646
|
||||
},
|
||||
{
|
||||
"deal": {
|
||||
"product_description": "This certified refurbished Apple iPhone 14 features 128GB of storage, providing ample space for apps, photos, and videos. Known for its performance, the iPhone 14 includes advanced camera capabilities and a long-lasting battery, setting standards in smartphone technology. The device comes with a one-year warranty from Allstate, ensuring reliability and support for customers. This refurbished option is an excellent choice for users looking for quality at a lower price point.",
|
||||
"price": 425.0,
|
||||
"url": "https://www.dealnews.com/products/Apple/Refurb-Unlocked-Apple-iPhone-14-128-GB-Phone-Excellent-Cond/472441.html?iref=rss-c142"
|
||||
},
|
||||
"estimate": 667.340418267145,
|
||||
"discount": 242.34041826714497
|
||||
},
|
||||
{
|
||||
"deal": {
|
||||
"product_description": "The iRobot Roomba j7+ is a highly efficient WiFi self-emptying robot vacuum designed to make cleaning effortless. With advanced smart mapping technology, it can identify and avoid obstacles, ensuring a thorough cleaning of your home. This model offers a self-emptying base, eliminating the need for manual bag changes. A runtime of 90 minutes allows it to cover large areas, making it ideal for busy households.",
|
||||
"price": 250.0,
|
||||
"url": "https://www.dealnews.com/products/iRobot/iRobot-Roomba-j7-Wi-Fi-Self-Emptying-Robot-Vacuum/293669.html?iref=rss-f1912"
|
||||
},
|
||||
"estimate": 621.4089582478217,
|
||||
"discount": 371.4089582478217
|
||||
},
|
||||
{
|
||||
"deal": {
|
||||
"product_description": "The certified refurbished iRobot Roomba 692 is a smart cleaning device that simplifies household upkeep. This vacuum operates with three-stage cleaning technology and has a compatibility feature with smart assistants such as Alexa and Google Home. It is designed for efficient cleaning across hard floors and carpets, providing a 90-minute runtime per charge. This model comes with a 2-year warranty from Allstate, ensuring peace of mind along with top-notch functionality for your cleaning needs.",
|
||||
"price": 120.0,
|
||||
"url": "https://www.dealnews.com/products/iRobot/iRobot-Roomba-692-Robot-Vacuum/143125.html?iref=rss-f1912"
|
||||
},
|
||||
"estimate": 304.1034980572389,
|
||||
"discount": 184.10349805723888
|
||||
},
|
||||
{
|
||||
"deal": {
|
||||
"product_description": "The Certified Refurb Acer Swift Edge Ryzen 7 Laptop features an advanced AMD Ryzen 7 7735U 8-core processor, offering exceptional performance for both work and play. It is equipped with a 16GB RAM and a spacious 1TB SSD, ensuring smooth multitasking and ample storage for your files. The 16-inch display boasts a stunning 3840x2400 resolution, making it ideal for streaming and content creation. This laptop is certified refurbished, meaning it comes backed by a 2-year warranty for peace of mind.",
|
||||
"price": 760.0,
|
||||
"url": "https://www.dealnews.com/Certified-Refurb-Acer-Swift-Edge-Ryzen-7-16-Laptop-for-760-free-shipping/21682096.html?iref=rss-c39"
|
||||
},
|
||||
"estimate": 985.5902213719573,
|
||||
"discount": 225.59022137195734
|
||||
},
|
||||
{
|
||||
"deal": {
|
||||
"product_description": "The Klipsch T5 II True Wireless ANC Earphones offer a high-fidelity audio experience combined with active noise-canceling technology. These earbuds come with six sizes of patented, color-coded oval ear tips to ensure a comfortable fit for all users. The device is equipped with a two-mic hybrid design, enhancing call quality while reducing background noise. With intuitive head gesture controls, you can easily manage your audio playback without needing to reach for your device.",
|
||||
"price": 68.0,
|
||||
"url": "https://www.dealnews.com/products/Klipsch/Klipsch-T5-II-True-Wireless-ANC-Earphones/482823.html?iref=rss-c142"
|
||||
},
|
||||
"estimate": 309.56921733594834,
|
||||
"discount": 241.56921733594834
|
||||
},
|
||||
{
|
||||
"deal": {
|
||||
"product_description": "The Certified Refurbished Acer Aspire 3 laptop boasts a powerful 6th-generation AMD Ryzen 5 processor and a spacious 15.6-inch touchscreen display with full HD resolution. It is equipped with 16GB of RAM and a 1TB SSD, providing ample storage and fast performance. This model comes with Windows 11 Home and is backed by a two-year warranty.",
|
||||
"price": 288.0,
|
||||
"url": "https://www.dealnews.com/products/Acer/Acer-Aspire-3-6-th-Gen-Ryzen-5-15-6-Touchscreen-Laptop/476367.html?iref=rss-c39"
|
||||
},
|
||||
"estimate": 558.5214284656016,
|
||||
"discount": 270.5214284656016
|
||||
},
|
||||
{
|
||||
"deal": {
|
||||
"product_description": "The Eufy eufyCam S330 (eufyCam 3) 4-Camera kit comes equipped with advanced security features, making it a top choice for home monitoring. Each camera offers high-resolution 4K video and includes an integrated solar panel for continuous powering, thus eliminating the need for frequent recharges. The system utilizes artificial intelligence for facial recognition, effectively distinguishing between family and strangers. Furthermore, it includes a 1TB hard drive for expandable local storage, ensuring that you have ample room to save recorded footage without additional fees.",
|
||||
"price": 650.0,
|
||||
"url": "https://www.dealnews.com/products/Eufy/eufy-Cam-S330-eufy-Cam-3-4-Camera-Kit-1-TB-HDD/464094.html?iref=rss-c196"
|
||||
},
|
||||
"estimate": 901.053559336033,
|
||||
"discount": 251.053559336033
|
||||
},
|
||||
{
|
||||
"deal": {
|
||||
"product_description": "The Shark IQ Robot Vacuum is designed to simplify your cleaning routine with its 60-day capacity base, which allows it to store more dirt before needing to be emptied. It comes equipped with advanced navigation technology to efficiently clean your floors while avoiding obstacles. This self-emptying feature not only saves you time but also ensures your home remains clean with minimal effort on your part. It's a perfect solution for busy households looking for convenience.",
|
||||
"price": 267.0,
|
||||
"url": "https://www.dealnews.com/Shark-IQ-Robot-Vacuum-w-60-Day-Capacity-Base-for-267-free-shipping/21668563.html?iref=rss-f1912"
|
||||
},
|
||||
"estimate": 495.68476864134675,
|
||||
"discount": 228.68476864134675
|
||||
},
|
||||
{
|
||||
"deal": {
|
||||
"product_description": "The Dell Inspiron 15 Laptop is equipped with a 12th Generation Intel Core i5 processor and a 15.6-inch touchscreen display, providing a dynamic computing experience for work and entertainment. With 8GB of RAM and a 512GB SSD, it offers sufficient memory for multitasking and fast boot-up times. This laptop runs Windows 11 Home in S Mode, enhancing its performance for everyday tasks. Its sleek design and robust features make it a practical choice for students and professionals alike.",
|
||||
"price": 350.0,
|
||||
"url": "https://www.dealnews.com/products/Dell/Dell-Inspiron-15-12-th-Gen-i5-15-6-Touchscreen-Laptop-w-512-GB-SSD/479057.html?iref=rss-c39"
|
||||
},
|
||||
"estimate": 577.1076076116793,
|
||||
"discount": 227.10760761167933
|
||||
},
|
||||
{
|
||||
"deal": {
|
||||
"product_description": "The EcoFlow DELTA 2 (950) Portable Power Station is designed for convenience and reliability, boasting a 1024Wh capacity that can power multiple devices simultaneously. It features six AC outlets, two USB-A, and two USB-C ports, making it versatile for outdoor adventures, emergencies, or everyday use. With both Wi-Fi and Bluetooth connectivity, you can monitor the status of your power station right from your smartphone. This bundle also comes with an 800W alternator charger, ensuring that you have everything you need to stay powered up wherever you go.",
|
||||
"price": 699.0,
|
||||
"url": "https://www.dealnews.com/Eco-Flow-DELTA-2-950-Portable-Power-Station-800-W-Alternator-Charger-for-699-free-shipping/21673983.html?iref=rss-c142"
|
||||
},
|
||||
"estimate": 963.8626028683989,
|
||||
"discount": 264.8626028683989
|
||||
},
|
||||
{
|
||||
"deal": {
|
||||
"product_description": "The Certified Refurb iRobot Roomba i4 EVO WiFi Robot Vacuum combines smart technology with powerful cleaning capabilities. This robot vacuum is designed to navigate effortlessly through your home, providing thorough cleaning on multiple surfaces. With WiFi connectivity, users can control the vacuum remotely via a smartphone app. The three-stage cleaning system ensures a deep clean, making it a perfect addition for busy households.",
|
||||
"price": 130.0,
|
||||
"url": "https://www.dealnews.com/products/iRobot/iRobot-Roomba-i4-EVO-Wi-Fi-Robot-Vacuum/431157.html?iref=rss-f1912"
|
||||
},
|
||||
"estimate": 341.23175777017946,
|
||||
"discount": 211.23175777017946
|
||||
},
|
||||
{
|
||||
"deal": {
|
||||
"product_description": "The ZimaBoard 832 Single Board Server is a versatile and compact solution for home or office use, equipped with robust processing power suitable for a variety of applications, including media streaming and file servers. It is designed for ease of use, with capabilities for expansion and customization. Its lightweight and energy-efficient design makes it an ideal selection for developers and tech enthusiasts seeking a reliable platform for programming and digital projects.",
|
||||
"price": 140.0,
|
||||
"url": "https://www.dealnews.com/Zima-Board-832-Single-Board-Server-for-140-free-shipping/21676871.html?iref=rss-c39"
|
||||
},
|
||||
"estimate": 292.84135797094723,
|
||||
"discount": 152.84135797094723
|
||||
},
|
||||
{
|
||||
"deal": {
|
||||
"product_description": "The EcoFlow DELTA 2 (950) Portable Power Station is a robust solution for all your electrical needs while on the go. With a 1024Wh capacity, this power station is versatile enough to charge multiple devices simultaneously, thanks to its six AC outlets. Additionally, it features two USB-A and two USB-C ports, enabling you to charge laptops, phones, and other electronics quickly. Bundled with an 800W Alternator Charger, it's designed to ensure you have power, wherever your adventures may lead you.",
|
||||
"price": 699.0,
|
||||
"url": "https://www.dealnews.com/Eco-Flow-DELTA-2-950-Portable-Power-Station-800-W-Alternator-Charger-for-699-free-shipping/21676798.html?iref=rss-c142"
|
||||
},
|
||||
"estimate": 870.8927901823207,
|
||||
"discount": 171.8927901823207
|
||||
}
|
||||
]
|
||||
@@ -42,6 +42,11 @@ class App:
|
||||
def __init__(self):
|
||||
self.agent_framework = None
|
||||
|
||||
def get_agent_framework(self):
|
||||
if not self.agent_framework:
|
||||
self.agent_framework = DealAgentFramework()
|
||||
return self.agent_framework
|
||||
|
||||
def run(self):
|
||||
with gr.Blocks(title="The Price is Right", fill_width=True) as ui:
|
||||
|
||||
@@ -51,16 +56,17 @@ class App:
|
||||
return [[opp.deal.product_description, f"${opp.deal.price:.2f}", f"${opp.estimate:.2f}", f"${opp.discount:.2f}", opp.deal.url] for opp in opps]
|
||||
|
||||
def update_output(log_data, log_queue, result_queue):
|
||||
initial_result = table_for(self.get_agent_framework().memory)
|
||||
final_result = None
|
||||
while True:
|
||||
try:
|
||||
message = log_queue.get_nowait()
|
||||
log_data.append(reformat(message))
|
||||
yield log_data, html_for(log_data), final_result
|
||||
yield log_data, html_for(log_data), final_result or initial_result
|
||||
except queue.Empty:
|
||||
try:
|
||||
final_result = result_queue.get_nowait()
|
||||
yield log_data, html_for(log_data), final_result
|
||||
yield log_data, html_for(log_data), final_result or initial_result
|
||||
except queue.Empty:
|
||||
if final_result is not None:
|
||||
break
|
||||
@@ -100,28 +106,18 @@ class App:
|
||||
|
||||
return fig
|
||||
|
||||
def start():
|
||||
self.agent_framework = DealAgentFramework()
|
||||
self.agent_framework.run()
|
||||
opportunities = self.agent_framework.memory
|
||||
table = table_for(opportunities)
|
||||
return table
|
||||
|
||||
def do_run():
|
||||
if not self.agent_framework:
|
||||
self.agent_framework = DealAgentFramework()
|
||||
self.agent_framework.run()
|
||||
new_opportunities = self.agent_framework.memory
|
||||
new_opportunities = self.get_agent_framework().run()
|
||||
table = table_for(new_opportunities)
|
||||
return table
|
||||
|
||||
def do_with_logging(function, initial_log_data):
|
||||
def run_with_logging(initial_log_data):
|
||||
log_queue = queue.Queue()
|
||||
result_queue = queue.Queue()
|
||||
setup_logging(log_queue)
|
||||
|
||||
def worker():
|
||||
result = function()
|
||||
result = do_run()
|
||||
result_queue.put(result)
|
||||
|
||||
thread = threading.Thread(target=worker)
|
||||
@@ -130,19 +126,11 @@ class App:
|
||||
for log_data, output, final_result in update_output(initial_log_data, log_queue, result_queue):
|
||||
yield log_data, output, final_result
|
||||
|
||||
def start_with_logging(initial_log_data):
|
||||
for log_data, output, final_result in do_with_logging(start, initial_log_data):
|
||||
yield log_data, output, final_result
|
||||
|
||||
def run_with_logging(initial_log_data):
|
||||
for log_data, output, final_result in do_with_logging(do_run, initial_log_data):
|
||||
yield log_data, output, final_result
|
||||
|
||||
def do_select(selected_index: gr.SelectData):
|
||||
opportunities = self.agent_framework.memory
|
||||
opportunities = self.get_agent_framework().memory
|
||||
row = selected_index.index[0]
|
||||
opportunity = opportunities[row]
|
||||
self.agent_framework.planner.messenger.alert(opportunity)
|
||||
self.get_agent_framework().planner.messenger.alert(opportunity)
|
||||
|
||||
with gr.Row():
|
||||
gr.Markdown('<div style="text-align: center;font-size:24px"><strong>The Price is Right</strong> - Autonomous Agent Framework that hunts for deals</div>')
|
||||
@@ -155,7 +143,7 @@ class App:
|
||||
column_widths=[6, 1, 1, 1, 3],
|
||||
row_count=10,
|
||||
col_count=5,
|
||||
height=400,
|
||||
max_height=400,
|
||||
)
|
||||
with gr.Row():
|
||||
with gr.Column(scale=1):
|
||||
@@ -163,14 +151,11 @@ class App:
|
||||
with gr.Column(scale=1):
|
||||
plot = gr.Plot(value=get_plot(), show_label=False)
|
||||
|
||||
ui.load(start_with_logging, inputs=[log_data], outputs=[log_data, logs, opportunities_dataframe])
|
||||
ui.load(run_with_logging, inputs=[log_data], outputs=[log_data, logs, opportunities_dataframe])
|
||||
|
||||
timer = gr.Timer(value=300, active=True)
|
||||
timer.tick(run_with_logging, inputs=[log_data], outputs=[log_data, logs, opportunities_dataframe])
|
||||
|
||||
# timer2 = gr.Timer(value=5, active=True)
|
||||
# timer2.tick(get_plot, inputs=[], outputs=[plot, timer2])
|
||||
|
||||
opportunities_dataframe.select(do_select)
|
||||
|
||||
ui.launch(share=False, inbrowser=True)
|
||||
|
||||
@@ -82,3 +82,7 @@ class Pricer:
|
||||
match = re.search(r"[-+]?\d*\.\d+|\d+", contents)
|
||||
return float(match.group()) if match else 0
|
||||
|
||||
@modal.method()
|
||||
def wake_up(self) -> str:
|
||||
return "ok"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user