Add week8 contributions

This commit is contained in:
lisekarimi
2025-06-05 16:42:02 +02:00
parent 5782ca2b43
commit 141216e8f7
13 changed files with 12066 additions and 0 deletions

View File

@@ -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)

View File

@@ -0,0 +1,29 @@
import modal
from agents.base_agent import Agent
class FTPriceAgent(Agent):
"""
An Agent that runs the fine-tuned LLM that's running remotely on Modal
"""
name = "FTPrice Agent"
color = Agent.RED
def __init__(self):
"""
Set up this Agent by creating an instance of the modal class
"""
self.log("FTPrice Agent is initializing - connecting to modal")
Pricer = modal.Cls.from_name("llm-ft-pricer", "Pricer") # 1st API call: to fetch Pricer (remote class)
self.pricer = Pricer()
self.log("FTPrice Agent is ready")
def price(self, description: str) -> float:
"""
Make a remote call to return the estimate of the price of this item
"""
self.log("FTPrice Agent is calling remote fine-tuned model")
result = self.pricer.price.remote(description) # 2nd API call: to run the price method in the remote Pricer class
self.log(f"FTPrice Agent completed - predicting ${result:.2f}")
return result