1 line
5.0 KiB
JSON
1 line
5.0 KiB
JSON
{"repo": "aatmajbarbhaiya/tariffpilot", "files": {"config.py": {"515be3ac56d02a6a34562557596eb71d8ed704d3": {"t": 1785674618.1564114, "n": 4703, "h": "78a5726c984bc16b", "c": "\"\"\"\nCentral configuration — everything env-driven so the same code runs on a laptop,\nthe AMD box, or against Fireworks with no edits.\n\nNothing here imports heavy deps; safe to import from anywhere.\n\nNOTE: Fireworks is OPTIONAL. With no FIREWORKS_API_KEY set (the current state),\nthe Fireworks backend simply skips itself and the pipeline degrades gracefully\nto keyword + vector signals — no crash, no hard dependency.\n\"\"\"\nimport os\nfrom pathlib import Path\n\n# --- paths (anchored to this file, CWD-independent) -------------------------\nROOT = Path(__file__).resolve().parent\nDB_PATH = str(ROOT / \"Database\" / \"tariff_pilot.db\")\nCHROMA_PATH = str(ROOT / \"Database\" / \"chroma_db\")\nCHROMA_COLLECTION = \"hs_taxonomy\"\n\n\ndef _load_dotenv(path):\n \"\"\"Minimal, dependency-free .env loader: KEY=VALUE per line, '#' comments.\n Uses setdefault so a real shell `export` always overrides the file.\"\"\"\n try:\n with open(path) as f:\n for line in f:\n line = line.strip()\n if not line or line.startswith(\"#\") or \"=\" not in line:\n continue\n key, _, val = line.partition(\"=\")\n os.environ.setdefault(\n key.strip(), val.strip().strip('\"').strip(\"'\"))\n except FileNotFoundError:\n pass\n\n\n_load_dotenv(ROOT / \".env\") # load before the classes below read env\n\n\ndef _env(name, default=\"\"):\n return os.environ.get(name, default).strip()\n\n\n# --- LLM backends -----------------------------------------------------------\n# Local vLLM server (OpenAI-compatible) is tried first; Fireworks is the\n# fallback. Either can be the sole backend depending on which envs are set.\nclass LLM:\n # Local vLLM server. api_key is a dummy — vLLM ignores auth.\n BASE_URL = _env(\"LLM_BASE_URL\", \"http://localhost:8080/v1\")\n MODEL = _env(\"LLM_MODEL\", \"local\")\n API_KEY = _env(\"LLM_API_KEY\", \"sk-noauth\")\n # seconds, local is close\n TIMEOUT = float(_env(\"LLM_TIMEOUT\", \"6\"))\n # SDK auto-retries transient 429/5xx/timeout with backoff. 0 = fail fast.\n MAX_RETRIES = int(_env(\"LLM_MAX_RETRIES\", \"2\"))\n ENABLED = _env(\"LLM_LOCAL_ENABLED\", \"1\") != \"0\"\n\n\nclass FIREWORKS:\n BASE_URL = _env(\"FIREWORKS_BASE_URL\",\n \"https://api.fireworks.ai/inference/v1\")\n MODEL = _env(\"FIREWORKS_MODEL\", \"accounts/fireworks/models/gpt-oss-20b\")\n # empty => backend skipped\n API_KEY = _env(\"FIREWORKS_API_KEY\", \"\")\n TIMEOUT = float(_env(\"FIREWORKS_TIMEOUT\", \"20\"))\n # Serverless Fireworks occasionally 429s/times out — retry transient errors.\n MAX_RETRIES = int(_env(\"FIREWORKS_MAX_RETRIES\", \"1\"))\n\n\n# --- shared LLM sampling knobs (both backends) ------------------------------\n# gpt-oss is a REASONING model: at default effort it spends the whole token\n# budget \"thinking\" and never emits the final JSON (verified: 2048 tokens ->\n# empty). \"low\" collapses reasoning to ~80 tokens and returns clean JSON.\n# Set to \"\" for a non-reasoning model (e.g. plain Qwen) that rejects the param.\nLLM_REASONING_EFFORT = _env(\"LLM_REASONING_EFFORT\", \"low\")\nLLM_MAX_OUTPUT_TOKENS = int(_env(\"LLM_MAX_OUTPUT_TOKENS\", \"1024\"))\n\n\n# --- retrieval thresholds (calibrate with tests/evaluate.py) ------------\n# Min cosine similarity for a vector hit to count as a real candidate.\nVECTOR_MIN_SIM = float(_env(\"VECTOR_MIN_SIM\", \"0.30\"))\n# Fast path (no LLM) requires keyword+vector to agree AND the vector to be at\n# least this confident.\nFASTPATH_MIN_SIM = float(_env(\"FASTPATH_MIN_SIM\", \"0.50\"))\nKEYWORD_K = int(_env(\"KEYWORD_K\", \"5\"))\nVECTOR_K = int(_env(\"VECTOR_K\", \"5\"))\n# abstain -> top-N suggestions\nTOP_N = int(_env(\"TOP_N\", \"3\"))\n\n\n# --- static scope map (Signal 2 / consistency guard) ------------------------\n# Deliberately tiny + hand-maintained: the whole supported universe. Signal 2\n# routes user text onto these; anything else is out of scope.\nSCOPE_CHAPTERS = {\n \"30\": \"pharmaceuticals & medical preparations (medicaments, vaccines, dressings)\",\n}\nSCOPE_HEADINGS = {\n \"9018\": \"medical/surgical/dental instruments & appliances\",\n \"9019\": \"mechano-therapy, massage, respiration apparatus\",\n \"9020\": \"breathing appliances & gas masks\",\n \"9021\": \"orthopaedic, prosthetic, hearing, pacemaker appliances\",\n \"9022\": \"x-ray & ionising-radiation apparatus\",\n \"9305\": \"parts & accessories of firearms\",\n \"9306\": \"ammunition & parts\",\n \"9101\": \"wrist/pocket watches, precious-metal case\",\n \"9102\": \"wrist/pocket watches, other case\",\n \"2208\": \"spirits & liqueurs (whisky, vodka, gin, rum, etc.)\",\n}\n\n# Valid heading/chapter sets used to sanity-check LLM output + build filters.\nALL_HEADINGS = set(SCOPE_HEADINGS)\nALL_CHAPTERS = set(SCOPE_CHAPTERS)\n"}}}} |