Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)
Python
seperate files
Abi Raja04b9b74e0468
diff --git a/backend/agent/providers/anthropic.py b/backend/agent/providers/anthropic.pyindex 0e10769b..05841042 100644--- a/backend/agent/providers/anthropic.py+++ b/backend/agent/providers/anthropic.py@@ -13,14 +13,14 @@ from openai.types.chat import ChatCompletionMessageParamfrom PIL import Imagefrom agent.providers.base import (- MODEL_PRICING,EventSink,ExecutedToolCall,ProviderSession,ProviderTurn,StreamEvent,- TokenUsage,)+from agent.providers.pricing import MODEL_PRICING+from agent.providers.token_usage import TokenUsagefrom agent.tools import CanonicalToolDefinition, ToolCall, parse_json_argumentsfrom llm import Llmdiff --git a/backend/agent/providers/base.py b/backend/agent/providers/base.pyindex 2274522e..604cc50c 100644--- a/backend/agent/providers/base.py+++ b/backend/agent/providers/base.py@@ -1,5 +1,5 @@from dataclasses import dataclass-from typing import Any, Awaitable, Callable, Dict, Literal, Optional, Protocol+from typing import Any, Awaitable, Callable, Literal, Optional, Protocolfrom agent.tools import ToolCall, ToolExecutionResult@@ -20,103 +20,6 @@ class StreamEvent:tool_arguments: Any = None-@dataclass-class TokenUsage:- """Unified token usage across all providers.-- Log line example:- [TOKEN USAGE] provider=gemini model=... | input=1000 output=500- cache_read=200 cache_write=0 total=1700 cost=$0.0020-- Fields:- input: Non-cached input tokens (billed at full input rate).- For providers whose API includes cached tokens in the- prompt count (OpenAI, Gemini), cached tokens are- subtracted so this is always *exclusive* of cache_read.- output: Output tokens including thinking/reasoning (billed at- output rate).- cache_read: Input tokens served from cache (billed at reduced rate).- cache_write: Input tokens written to cache (Anthropic only).- total: All tokens as reported by the provider API. Equals- input + cache_read + output (+ thinking for Gemini).-- Total input sent to the model = input + cache_read.- Cost = (input * input_rate + output * output_rate- + cache_read * cache_read_rate + cache_write * cache_write_rate)- / 1_000_000- """-- input: int = 0- output: int = 0- cache_read: int = 0- cache_write: int = 0- total: int = 0-- def accumulate(self, other: "TokenUsage") -> None:- self.input += other.input- self.output += other.output- self.cache_read += other.cache_read- self.cache_write += other.cache_write- self.total += other.total-- def cost(self, pricing: "ModelPricing") -> float:- """Compute cost in USD using per-million-token rates."""- return (- self.input * pricing.input- + self.output * pricing.output- + self.cache_read * pricing.cache_read- + self.cache_write * pricing.cache_write- ) / 1_000_000---@dataclass-class ModelPricing:- """Per-million-token pricing in USD."""-- input: float = 0.0- output: float = 0.0- cache_read: float = 0.0- cache_write: float = 0.0---# Pricing keyed by the API model name string sent to the provider.-MODEL_PRICING: Dict[str, ModelPricing] = {- # --- OpenAI ---- "gpt-4.1-2025-04-14": ModelPricing(- input=2.00, output=8.00, cache_read=0.50- ),- "gpt-5.2-codex": ModelPricing(- input=1.75, output=14.00, cache_read=0.4375- ),- "gpt-5.3-codex": ModelPricing(- input=1.75, output=14.00, cache_read=0.4375- ),- # --- Anthropic ---- "claude-sonnet-4-6": ModelPricing(- input=3.00, output=15.00, cache_read=0.30, cache_write=3.75- ),- "claude-sonnet-4-5-20250929": ModelPricing(- input=3.00, output=15.00, cache_read=0.30, cache_write=3.75- ),- "claude-opus-4-5-20251101": ModelPricing(- input=5.00, output=25.00, cache_read=0.50, cache_write=6.25- ),- "claude-opus-4-6": ModelPricing(- input=5.00, output=25.00, cache_read=0.50, cache_write=6.25- ),- # --- Gemini ---- "gemini-3-flash-preview": ModelPricing(- input=0.50, output=3.00, cache_read=0.05- ),- "gemini-3-pro-preview": ModelPricing(- input=2.00, output=12.00, cache_read=0.20- ),- "gemini-3.1-pro-preview": ModelPricing(- input=2.00, output=12.00, cache_read=0.20- ),-}--@dataclassclass ProviderTurn:assistant_text: strdiff --git a/backend/agent/providers/gemini.py b/backend/agent/providers/gemini.pyindex 1c0c3b49..c803d201 100644--- a/backend/agent/providers/gemini.py+++ b/backend/agent/providers/gemini.py@@ -10,14 +10,14 @@ from google.genai import typesfrom openai.types.chat import ChatCompletionMessageParamfrom agent.providers.base import (- MODEL_PRICING,EventSink,ExecutedToolCall,ProviderSession,ProviderTurn,StreamEvent,- TokenUsage,)+from agent.providers.pricing import MODEL_PRICING+from agent.providers.token_usage import TokenUsagefrom agent.tools import CanonicalToolDefinition, ToolCallfrom llm import Llmdiff --git a/backend/agent/providers/openai.py b/backend/agent/providers/openai.pyindex 91b56057..e1a3cdae 100644--- a/backend/agent/providers/openai.py+++ b/backend/agent/providers/openai.py@@ -9,14 +9,14 @@ from openai import AsyncOpenAIfrom openai.types.chat import ChatCompletionMessageParamfrom agent.providers.base import (- MODEL_PRICING,EventSink,ExecutedToolCall,ProviderSession,ProviderTurn,StreamEvent,- TokenUsage,)+from agent.providers.pricing import MODEL_PRICING+from agent.providers.token_usage import TokenUsagefrom agent.state import ensure_strfrom agent.tools import CanonicalToolDefinition, ToolCall, parse_json_argumentsfrom llm import Llm, get_openai_api_name, get_openai_reasoning_effortdiff --git a/backend/agent/providers/pricing.py b/backend/agent/providers/pricing.pynew file mode 100644index 00000000..6c469795--- /dev/null+++ b/backend/agent/providers/pricing.py@@ -0,0 +1,40 @@+from typing import Dict++from agent.providers.token_usage import ModelPricing++# Pricing keyed by the API model name string sent to the provider.+MODEL_PRICING: Dict[str, ModelPricing] = {+ # --- OpenAI ---+ "gpt-4.1-2025-04-14": ModelPricing(+ input=2.00, output=8.00, cache_read=0.50+ ),+ "gpt-5.2-codex": ModelPricing(+ input=1.75, output=14.00, cache_read=0.4375+ ),+ "gpt-5.3-codex": ModelPricing(+ input=1.75, output=14.00, cache_read=0.4375+ ),+ # --- Anthropic ---+ "claude-sonnet-4-6": ModelPricing(+ input=3.00, output=15.00, cache_read=0.30, cache_write=3.75+ ),+ "claude-sonnet-4-5-20250929": ModelPricing(+ input=3.00, output=15.00, cache_read=0.30, cache_write=3.75+ ),+ "claude-opus-4-5-20251101": ModelPricing(+ input=5.00, output=25.00, cache_read=0.50, cache_write=6.25+ ),+ "claude-opus-4-6": ModelPricing(+ input=5.00, output=25.00, cache_read=0.50, cache_write=6.25+ ),+ # --- Gemini ---+ "gemini-3-flash-preview": ModelPricing(+ input=0.50, output=3.00, cache_read=0.05+ ),+ "gemini-3-pro-preview": ModelPricing(+ input=2.00, output=12.00, cache_read=0.20+ ),+ "gemini-3.1-pro-preview": ModelPricing(+ input=2.00, output=12.00, cache_read=0.20+ ),+}diff --git a/backend/agent/providers/token_usage.py b/backend/agent/providers/token_usage.pynew file mode 100644index 00000000..28ca55d8--- /dev/null+++ b/backend/agent/providers/token_usage.py@@ -0,0 +1,62 @@+from __future__ import annotations++from dataclasses import dataclass+++@dataclass+class ModelPricing:+ """Per-million-token pricing in USD."""++ input: float = 0.0+ output: float = 0.0+ cache_read: float = 0.0+ cache_write: float = 0.0+++@dataclass+class TokenUsage:+ """Unified token usage across all providers.++ Log line example:+ [TOKEN USAGE] provider=gemini model=... | input=1000 output=500+ cache_read=200 cache_write=0 total=1700 cost=$0.0020++ Fields:+ input: Non-cached input tokens (billed at full input rate).+ For providers whose API includes cached tokens in the+ prompt count (OpenAI, Gemini), cached tokens are+ subtracted so this is always *exclusive* of cache_read.+ output: Output tokens including thinking/reasoning (billed at+ output rate).+ cache_read: Input tokens served from cache (billed at reduced rate).+ cache_write: Input tokens written to cache (Anthropic only).+ total: All tokens as reported by the provider API. Equals+ input + cache_read + output (+ thinking for Gemini).++ Total input sent to the model = input + cache_read.+ Cost = (input * input_rate + output * output_rate+ + cache_read * cache_read_rate + cache_write * cache_write_rate)+ / 1_000_000+ """++ input: int = 0+ output: int = 0+ cache_read: int = 0+ cache_write: int = 0+ total: int = 0++ def accumulate(self, other: TokenUsage) -> None:+ self.input += other.input+ self.output += other.output+ self.cache_read += other.cache_read+ self.cache_write += other.cache_write+ self.total += other.total++ def cost(self, pricing: ModelPricing) -> float:+ """Compute cost in USD using per-million-token rates."""+ return (+ self.input * pricing.input+ + self.output * pricing.output+ + self.cache_read * pricing.cache_read+ + self.cache_write * pricing.cache_write+ ) / 1_000_000diff --git a/backend/tests/test_token_usage.py b/backend/tests/test_token_usage.pyindex b896361f..c192d88c 100644--- a/backend/tests/test_token_usage.py+++ b/backend/tests/test_token_usage.py@@ -2,7 +2,8 @@from types import SimpleNamespace-from agent.providers.base import MODEL_PRICING, ModelPricing, TokenUsage+from agent.providers.pricing import MODEL_PRICING+from agent.providers.token_usage import ModelPricing, TokenUsagefrom agent.providers.anthropic import _extract_anthropic_usagefrom agent.providers.gemini import _extract_usage as _extract_gemini_usagefrom agent.providers.openai import _extract_openai_usage