{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load env variables and create client\n",
    "import base64\n",
    "from dotenv import load_dotenv\n",
    "from anthropic import Anthropic\n",
    "\n",
    "load_dotenv()\n",
    "\n",
    "client = Anthropic()\n",
    "model = \"claude-3-7-sonnet-latest\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Helper functions\n",
    "from anthropic.types import Message\n",
    "\n",
    "\n",
    "def add_user_message(messages, message):\n",
    "    user_message = {\n",
    "        \"role\": \"user\",\n",
    "        \"content\": message.content if isinstance(message, Message) else message,\n",
    "    }\n",
    "    messages.append(user_message)\n",
    "\n",
    "\n",
    "def add_assistant_message(messages, message):\n",
    "    assistant_message = {\n",
    "        \"role\": \"assistant\",\n",
    "        \"content\": message.content if isinstance(message, Message) else message,\n",
    "    }\n",
    "    messages.append(assistant_message)\n",
    "\n",
    "\n",
    "def chat(\n",
    "    messages,\n",
    "    system=None,\n",
    "    temperature=1.0,\n",
    "    stop_sequences=[],\n",
    "    tools=None,\n",
    "    thinking=False,\n",
    "    thinking_budget=1024,\n",
    "):\n",
    "    params = {\n",
    "        \"model\": model,\n",
    "        \"max_tokens\": 4000,\n",
    "        \"messages\": messages,\n",
    "        \"temperature\": temperature,\n",
    "        \"stop_sequences\": stop_sequences,\n",
    "    }\n",
    "\n",
    "    if thinking:\n",
    "        params[\"thinking\"] = {\n",
    "            \"type\": \"enabled\",\n",
    "            \"budget_tokens\": thinking_budget,\n",
    "        }\n",
    "\n",
    "    if tools:\n",
    "        params[\"tools\"] = tools\n",
    "\n",
    "    if system:\n",
    "        params[\"system\"] = system\n",
    "\n",
    "    message = client.messages.create(**params)\n",
    "    return message\n",
    "\n",
    "\n",
    "def text_from_message(message):\n",
    "    return \"\\n\".join(\n",
    "        [block.text for block in message.content if block.type == \"text\"]\n",
    "    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Fire risk assessment prompt\n",
    "prompt = \"\"\"\n",
    "Analyze the attached satellite image of a property with these specific steps:\n",
    "\n",
    "1. Residence identification: Locate the primary residence on the property by looking for:\n",
    "   - The largest roofed structure \n",
    "   - Typical residential features (driveway connection, regular geometry)\n",
    "   - Distinction from other structures (garages, sheds, pools)\n",
    "   Describe the residence's location relative to property boundaries and other features.\n",
    "\n",
    "2. Tree overhang analysis: Examine all trees near the primary residence:\n",
    "   - Identify any trees whose canopy extends directly over any portion of the roof\n",
    "   - Estimate the percentage of roof covered by overhanging branches (0-25%, 25-50%, 50-75%, 75-100%)\n",
    "   - Note particularly dense areas of overhang\n",
    "\n",
    "3. Fire risk assessment: For any overhanging trees, evaluate:\n",
    "   - Potential wildfire vulnerability (ember catch points, continuous fuel paths to structure)\n",
    "   - Proximity to chimneys, vents, or other roof openings if visible\n",
    "   - Areas where branches create a \"bridge\" between wildland vegetation and the structure\n",
    "   \n",
    "4. Defensible space identification: Assess the property's overall vegetative structure:\n",
    "   - Identify if trees connect to form a continuous canopy over or near the home\n",
    "   - Note any obvious fuel ladders (vegetation that can carry fire from ground to tree to roof)\n",
    "\n",
    "5. Fire risk rating: Based on your analysis, assign a Fire Risk Rating from 1-4:\n",
    "   - Rating 1 (Low Risk): No tree branches overhanging the roof, good defensible space around the structure\n",
    "   - Rating 2 (Moderate Risk): Minimal overhang (<25% of roof), some separation between tree canopies\n",
    "   - Rating 3 (High Risk): Significant overhang (25-50% of roof), connected tree canopies, multiple points of vulnerability\n",
    "   - Rating 4 (Severe Risk): Extensive overhang (>50% of roof), dense vegetation against structure, numerous ember catch points, limited defensible space\n",
    "\n",
    "For each item above (1-5), write one sentence summarizing your findings, with your final response being the numeric Fire Risk Rating (1-4) with a brief justification.\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# TODO: Read image data, feed into Claude"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
