Spaces:
Sleeping
Sleeping
| """Configuration for the Health Marketing Compliance RAG system. | |
| Note: model presets and env vars retain the legacy `ECE_MODEL` / `ECE_MLX_MODEL` | |
| names from the ECE prototype to avoid disturbing the Makefile and shell habits. | |
| That's a deliberate choice β see CLAUDE.md "Conventions" section. | |
| """ | |
| import os | |
| import sys | |
| from dotenv import load_dotenv | |
| # Paths | |
| PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| CORPUS_DIR = os.path.join(PROJECT_ROOT, "corpus") | |
| INDEX_DIR = os.path.join(PROJECT_ROOT, "indexes") | |
| PAGEINDEX_DIR = os.path.join(PROJECT_ROOT, "PageIndex") | |
| # Load .env for API keys | |
| load_dotenv(os.path.join(PROJECT_ROOT, ".env"), override=True) | |
| # Add PageIndex to path | |
| sys.path.insert(0, PAGEINDEX_DIR) | |
| # LLM β supports local MLX models and remote API models | |
| # Set ECE_MODEL env var to switch: "sonnet", "gemma", "qwen" (default), or a full model path | |
| MLX_BASE_URL = "http://localhost:8080/v1" | |
| _MODEL_PRESETS = { | |
| "qwen": "openai/mlx-community/Qwen2.5-14B-Instruct-4bit", | |
| "gemma": "openai/mlx-community/gemma-4-26b-a4b-it-4bit", | |
| "sonnet": "anthropic/claude-sonnet-4-6", | |
| "opus": "anthropic/claude-opus-4-6", | |
| } | |
| # On HF Spaces (SPACE_ID is set automatically) or any hosted env where MLX | |
| # isn't running, default to sonnet so the app boots cleanly. Locally, qwen | |
| # remains the default to preserve existing dev habits. | |
| _default_model = "sonnet" if os.environ.get("SPACE_ID") else "qwen" | |
| _model_choice = os.environ.get("ECE_MODEL") or os.environ.get("ECE_MLX_MODEL") or _default_model | |
| MODEL = _MODEL_PRESETS.get(_model_choice, _model_choice) | |
| # Only configure MLX server env vars for local models | |
| if MODEL.startswith("openai/"): | |
| os.environ["OPENAI_API_KEY"] = "mlx" | |
| os.environ["OPENAI_API_BASE"] = MLX_BASE_URL | |
| # Short display name for the UI | |
| _DISPLAY_NAMES = { | |
| "qwen": "Qwen 2.5 14B (local)", | |
| "gemma": "Gemma 4 26B MoE (local)", | |
| "sonnet": "Claude Sonnet 4.6 (API)", | |
| "opus": "Claude Opus 4.6 (API)", | |
| } | |
| MODEL_DISPLAY_NAME = _DISPLAY_NAMES.get(_model_choice, MODEL.split("/")[-1]) | |
| # Document registry β maps domain keys to their files and descriptions. | |
| # | |
| # v3 β 6 domains for healthcare marketing, scoped to complementary/alternative | |
| # practitioners (chiros, osteos, physios, Chinese medicine, naturopaths, | |
| # acupuncturists) and supplement sellers. | |
| # | |
| # - description: used by the indexer when generating the root summary for each | |
| # PageIndex tree. Should describe what the corpus contains. | |
| # - router_description: used by the router to decide which domain(s) to query | |
| # for a given question. Should describe what KIND of question this domain | |
| # answers β intent-focused, not just keyword-focused. | |
| DOCUMENT_REGISTRY = { | |
| "medicines_and_supplements": { | |
| "corpus": os.path.join(CORPUS_DIR, "medicines-and-supplements.md"), | |
| "index": os.path.join(INDEX_DIR, "medicines-and-supplements.json"), | |
| "description": "NZ Medicines Act 1981 (Part 4 advertising restrictions including s58 testimonial bans on medicines, medical devices and methods of treatment, plus Part 5 enforcement and offences), Medicines Regulations 1984, Dietary Supplements Regulations 1985 (regulations 3 and 5 β definition of dietary supplement and the rule that marketing a supplement for a therapeutic purpose reclassifies it as a medicine), and Medsafe guidance on advertising of medicines. Covers when a product becomes a medicine, what claims medicines can and cannot make, testimonial restrictions, and the supplement-vs-medicine threshold that is the supplement industry's primary legal trapdoor.", | |
| "router_description": "Questions about medicines, medical devices, methods of treatment, and dietary supplements β therapeutic claims, prohibited representations, testimonial restrictions on medicines (s58), and supplement classification. Use when the question is about what claims can be made about a specific product, whether something counts as a medicine, the line between supplements and medicines, or testimonials referencing medicines. The 'is this product allowed to claim X?' cluster.", | |
| "source_url": "https://www.legislation.govt.nz/act/public/1981/0118/latest/whole.html", | |
| }, | |
| "advertising_standards": { | |
| "corpus": os.path.join(CORPUS_DIR, "advertising-standards.md"), | |
| "index": os.path.join(INDEX_DIR, "advertising-standards.json"), | |
| "description": "ASA (Advertising Standards Authority) self-regulatory codes β both the current Therapeutic and Health Advertising Code (in force until 1 April 2026 for new advertising / 1 July 2026 for all advertising) and the December 2025 version (in force from those dates onwards, with materially different rules on testimonials, user-generated content, and vulnerable audiences). Effective-date metadata is preserved on each section so retrieval can answer date-aware questions correctly across the transition. The General ASA Advertising Standards Code is included alongside per the Therapeutic Code's own 'consult alongside' instruction. ASA is industry-funded but enforced via broadcaster gatekeeping (TVNZ, ThreeNow, NZME) and ASA's own complaints adjudication.", | |
| "router_description": "Questions about what advertisements can and cannot say under ASA codes β testimonial rules, vulnerable audiences, user-generated content, social media advertising, broadcast standards. The Therapeutic and Health Advertising Code is the specific instrument; the General Code applies alongside. The 'is this ad allowed?' / 'will this ad survive an ASA complaint?' cluster. Note the transition window: a December 2025 code applies from 1 April 2026.", | |
| "source_url": "https://asa.co.nz/codes/", | |
| }, | |
| "consumer_protection": { | |
| "corpus": os.path.join(CORPUS_DIR, "consumer-protection.md"), | |
| "index": os.path.join(INDEX_DIR, "consumer-protection.json"), | |
| "description": "NZ Fair Trading Act 1986 (Part 1 β misleading and deceptive conduct, false representations, plus section 12A unsubstantiated representations β the requirement to have a reasonable basis for any claim made in trade, irrespective of whether the claim turns out to be true). Section 12A is the most-tripped-over provision in health and wellness advertising. Plus Commerce Commission guidance on health and wellness claims, including how the substantiation rule applies to health products and services and what evidence counts as a reasonable basis. Penalties for breach are up to $200,000 (individual) / $600,000 (body corporate).", | |
| "router_description": "Questions about whether a claim has enough evidence behind it (substantiation), whether something is misleading even if technically true, or general consumer-protection rules for advertising. Section 12A (unsubstantiated representations) is the workhorse provision. Use when the question is about evidence requirements, the difference between marketing puffery and a substantive claim, or general 'is this misleading?' issues that don't fit a specific therapeutic-products framework.", | |
| "source_url": "https://www.legislation.govt.nz/act/public/1986/0121/latest/whole.html", | |
| }, | |
| "marketing_comms": { | |
| "corpus": os.path.join(CORPUS_DIR, "marketing-comms.md"), | |
| "index": os.path.join(INDEX_DIR, "marketing-comms.json"), | |
| "description": "How marketers can lawfully use customer and patient lists β Privacy Act 2020 Information Privacy Principles (especially IPP 10 limits on use and IPP 11 limits on disclosure), Health Information Privacy Code 2020 (incorporating Amendment No 1, 2022 β applies the IPPs to health information with extra protections for sensitive health data), and Unsolicited Electronic Messages Act 2007 (NZ's anti-spam law: requires consent for commercial electronic messages, mandates a functional unsubscribe facility, and requires accurate sender identification). Together these rules govern email marketing, SMS reminders, retargeted advertising using patient data, and the line between permitted health communication and unlawful direct marketing.", | |
| "router_description": "Questions about how to lawfully use patient or customer data for marketing β email and SMS marketing (consent, unsubscribe), patient list use for promotional purposes, sharing testimonials with consent, retargeting using patient data, when health information privacy adds extra restrictions. The 'can I email this list?' / 'can I send patient reminders?' / 'can I share that testimonial?' cluster.", | |
| "source_url": "https://www.legislation.govt.nz/act/public/2020/0031/latest/whole.html", | |
| }, | |
| "practitioner_regulation": { | |
| "corpus": os.path.join(CORPUS_DIR, "practitioner-regulation.md"), | |
| "index": os.path.join(INDEX_DIR, "practitioner-regulation.json"), | |
| "description": "Foundational law that defines who can call themselves a health practitioner and what they can claim about their qualifications β Health Practitioners Competence Assurance Act 2003 (protected titles, scopes of practice, restricted activities, registration requirements). Plus the HDC Code of Health and Disability Services Consumers' Rights (especially Right 6 right to information and Right 7 informed consent β both routinely cited in advertising complaints when ads create unrealistic expectations or omit material information). Plus ACC provider obligations (Standard Terms and Conditions of the ACC provider contract, plus the Code of ACC Claimants' Rights). Marketing relevance: title use, qualification claims, what must be disclosed before treatment, ACC-registration claims.", | |
| "router_description": "Questions about who can call themselves what (protected titles, scope of practice claims), what practitioners must disclose to patients (consumer rights to information, informed consent), and ACC provider obligations including how ACC registration can be referenced in advertising. The 'can I call myself X?' / 'can I claim to specialise in Y?' / 'what must I tell patients before they book?' / 'can I say I'm an ACC provider?' cluster.", | |
| "source_url": "https://www.legislation.govt.nz/act/public/2003/0048/latest/whole.html", | |
| }, | |
| "professional_codes": { | |
| "corpus": os.path.join(CORPUS_DIR, "professional-codes.md"), | |
| "index": os.path.join(INDEX_DIR, "professional-codes.json"), | |
| "description": "Profession-specific advertising standards set by each council/board. Each document binds only its own registered practitioners β see the binds: scope metadata in each section. Includes Chiropractic Board Advertising Policy 2025 (binds chiropractors), Osteopathic Council Code of Conduct (binds osteopaths, includes advertising provisions in clause 7.12), Physiotherapy Board Advertising Standard (binds physiotherapists, extracted from the broader Standards framework), Chinese Medicine Council Advertising Standard Guidance (binds Chinese medicine practitioners including acupuncturists). Medical Council Statement on Advertising is included as a benchmark only β it is the strictest set in the country, particularly on testimonials, and applies ONLY to registered medical practitioners (MDs). Citing Medical Council guidance for non-MD practitioners gives over-conservative answers.", | |
| "router_description": "Profession-specific advertising rules. Each council/board sets standards binding only on its own registered practitioners. Use when the question mentions a specific profession (chiropractor, osteopath, physiotherapist, Chinese medicine practitioner, acupuncturist). Important: Medical Council guidance binds doctors only and is the strictest set β do NOT cite it for non-MD practitioners; their own councils have their own (often less strict) rules. Always check the binds: scope tag.", | |
| "source_url": "https://www.health.govt.nz/our-work/regulation-health-and-disability-system/health-practitioners-competence-assurance-act", | |
| }, | |
| } | |