File size: 2,258 Bytes
359d26a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 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"}