# genesis/regulation.py import os import requests from typing import Dict OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") def analyze_regulatory_pathways(therapy_description: str) -> Dict: """ Analyze regulatory risks and pathways for a therapy or technology. Uses OpenAI GPT-4 to reason about approval timelines and steps. """ try: if not OPENAI_API_KEY: raise ValueError("Missing OPENAI_API_KEY") headers = { "Authorization": f"Bearer {OPENAI_API_KEY}", "Content-Type": "application/json" } payload = { "model": "gpt-4o-mini", "messages": [ { "role": "system", "content": ( "You are a senior FDA and EMA regulatory affairs expert " "specializing in synthetic biology, gene therapies, and living therapeutics. " "Provide an evidence-based, structured assessment of approval pathways." ) }, { "role": "user", "content": ( f"Analyze the regulatory approval process for:\n{therapy_description}\n\n" "Include:\n" "1. Likely classification (e.g., ATMP, Biologic, Device)\n" "2. Key regulatory agencies and applicable guidelines\n" "3. Estimated approval timeline\n" "4. Common risks & how to mitigate them\n" "5. Post-market surveillance requirements" ) } ], "temperature": 0.2 } r = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload, timeout=60) r.raise_for_status() data = r.json() text = data["choices"][0]["message"]["content"] return { "analysis": text.strip(), "source": "OpenAI GPT-4o Regulatory Module" } except Exception as e: print(f"[Regulation] Failed: {e}") return {"analysis": "Regulatory analysis unavailable at this time.", "source": "Error"}