Haven't uploaded it anywhere, but here is a copy of the original implementation i made (i've improved a bit since):
```
import os
import ell
import chrono24
from PIL import Image
from ell import Message
from typing import List
from dataclasses import dataclass
from pydantic import BaseModel, Field
ell.init(store='./logdir', autocommit=True, verbose=True)
@dataclass
class PriceRange:
from_usd: int
to_usd: int
class QuickView(BaseModel):
brand: str = Field(description="The manufacturer or brand of the watch.")
watchModel: str = Field(description="The name of the watch model. No apostrophes, just letters.")
class ContentBlock(BaseModel):
parsed: QuickView
class ResponseContent(BaseModel):
content: List[ContentBlock]
class GenerateReport(BaseModel):
brand: str = Field(description="The manufacturer or brand of the watch.")
watchModel: str = Field(description="The name of the watch model.")
year_of_production: str = Field(description="Estimated production year (example: 'Est. 1990-1994')")
condition: str = Field(description="General description of the watch's condition (e.g., fair, good, excellent, mint)")
condition_score: int = Field(description="A score reflecting the condition of the watch, a `float` on a scale from 1 to 10. (ie. 6.7)")
value: PriceRange = Field(description="A from-to price range. The price range should be specified with a minimum and maximum value in USD")
rarity: str = Field(description="A description of how rare the watch is with arguments.")
rarity_score: int = Field(description="A score representation of the rarity of the watch. A `float` on a scale from 1 to 10 (ie 8.0).")
materials: str = Field(description="Materials used in the watch, including case, crystal, and strap.")
movement: str = Field(description="The type of movement the watch uses (e.g., manual wind, automatic, quartz). Simply write N/A if unable to answer.")
demand: str = Field(description="The current demand for this type of watch in the market.")
recommendations: str = Field(description="Actionable recommendations, such as servicing to increase the watch's value.")
@ell.tool()
def fetch_prices(brand:str, model:str):
"""Tool used to retrieve watch listings from the Chrono24 marketplace"""
result = ""
query = brand " " model
res = chrono24.query(query)
for listing in
res.search_detail(limit=30):
result = f"Brand: {listing['manufacturer']}\nTitle: {listing['title']}\nDescription: {listing['description']}\nPrice: {listing['price']}\nProduction year: {listing['year_of_production']}"
result = "\n" "_" * 12 "\n\n"
return result
@ell.complex(model="gpt-4o-2024-08-06", response_format=QuickView, temperature=0)
def inspect(image: Image.Image) -> QuickView:
return [
ell.system("You are a professional watch appraiser agent. Given the image of a watch, you will need to determine its brand and model name."),
ell.user(["Determine the brand and model for this watch: ", image])
]
@ell.complex(model="gpt-4o-2024-08-06", response_format=GenerateReport, temperature=.1)
def make_report(image: Image.Image, price_research: str) -> GenerateReport:
return [
ell.system("You are a certified professional watch appraiser. Upon being provided with an image of a watch, your task is to generate a comprehensive and structured appraisal report. Be thorough and accurate, but only include details you can confidently verify from the image. If certain information cannot be determined from the image, state that clearly. Avoid speculation."),
ell.user(["Generate a watch appraisal report for this watch: ", image, price_research])
]
def meow(image):
res = inspect(image, api_params=(dict(n=1)))
for content_block in res.content:
brand = content_block.parsed.brand
watch_model = content_block.parsed.watchModel
price_research = fetch_prices(brand, watch_model)
make_report(image, price_research)
imagepath = './imgs/IMG_1182.jpg'
image =
Image.open(imagepath)
meow(image)
```