fixed tree fmt and removed chat with images

This commit is contained in:
2026-03-13 08:59:26 -04:00
parent b5ee7c2dc2
commit 4e3273d5ec
3 changed files with 14 additions and 21 deletions

View File

@@ -95,9 +95,9 @@ def handle_inventory_update(
logger.info(f"Processing inventory update from {message.source}") logger.info(f"Processing inventory update from {message.source}")
if message.attachments: if message.attachments:
image_data = signal.get_attachment(message.attachments[0]) image_data = signal.get_attachment(message.attachments[0])
raw_response = llm.chat_with_image( raw_response = llm.chat(
IMAGE_PROMPT, IMAGE_PROMPT,
image_data, image_data=image_data,
system=SYSTEM_PROMPT, system=SYSTEM_PROMPT,
) )
source_type = "receipt_photo" source_type = "receipt_photo"

View File

@@ -48,8 +48,8 @@ class DeviceRegistry:
def is_verified(self, phone_number: str) -> bool: def is_verified(self, phone_number: str) -> bool:
"""Check if a phone number is verified.""" """Check if a phone number is verified."""
# if entry := self._cached(phone_number): if entry := self._cached(phone_number):
# return entry.trust_level == TrustLevel.VERIFIED return entry.trust_level == TrustLevel.VERIFIED
device = self.get_device(phone_number) device = self.get_device(phone_number)
return device is not None and device.trust_level == TrustLevel.VERIFIED return device is not None and device.trust_level == TrustLevel.VERIFIED
@@ -57,9 +57,9 @@ class DeviceRegistry:
"""Record seeing a device. Creates entry if new, updates last_seen.""" """Record seeing a device. Creates entry if new, updates last_seen."""
now = utcnow() now = utcnow()
# entry = self._cached(phone_number) entry = self._cached(phone_number)
# if entry and entry.safety_number == safety_number: if entry and entry.safety_number == safety_number:
# return return
with Session(self.engine) as session: with Session(self.engine) as session:
device = session.execute( device = session.execute(
@@ -94,8 +94,8 @@ class DeviceRegistry:
def has_safety_number(self, phone_number: str) -> bool: def has_safety_number(self, phone_number: str) -> bool:
"""Check if a device has a safety number on file.""" """Check if a device has a safety number on file."""
# if entry := self._cached(phone_number): if entry := self._cached(phone_number):
# return entry.has_safety_number return entry.has_safety_number
device = self.get_device(phone_number) device = self.get_device(phone_number)
return device is not None and device.safety_number is not None return device is not None and device.safety_number is not None

View File

@@ -26,24 +26,17 @@ class LLMClient:
self.temperature = temperature self.temperature = temperature
self._client = httpx.Client(base_url=f"http://{host}:{port}", timeout=120) self._client = httpx.Client(base_url=f"http://{host}:{port}", timeout=120)
def chat(self, prompt: str, *, system: str = "") -> str: def chat(self, prompt: str, image_data: bytes | None = None, system: str | None = None) -> str:
"""Send a text prompt and return the response.""" """Send a text prompt and return the response."""
messages: list[dict[str, Any]] = [] messages: list[dict[str, Any]] = []
if system: if system:
messages.append({"role": "system", "content": system}) messages.append({"role": "system", "content": system})
messages.append({"role": "user", "content": prompt})
return self._generate(messages)
def chat_with_image(self, prompt: str, image_data: bytes, *, system: str = "") -> str: user_msg = {"role": "user", "content": prompt}
"""Send a prompt with an image and return the response. if image_data:
user_msg["images"] = [base64.b64encode(image_data).decode()]
Requires a vision-capable model (e.g. qwen3-vl). messages.append(user_msg)
"""
encoded = base64.b64encode(image_data).decode()
messages: list[dict[str, Any]] = []
if system:
messages.append({"role": "system", "content": system})
messages.append({"role": "user", "content": prompt, "images": [encoded]})
return self._generate(messages) return self._generate(messages)
def _generate(self, messages: list[dict[str, Any]]) -> str: def _generate(self, messages: list[dict[str, Any]]) -> str: